2014-01-02 11:48:22 -05:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
load test_helper
|
|
|
|
|
|
|
|
create_version() {
|
|
|
|
mkdir -p "${PYENV_ROOT}/versions/$1"
|
|
|
|
}
|
|
|
|
|
|
|
|
setup() {
|
|
|
|
mkdir -p "$PYENV_TEST_DIR"
|
|
|
|
cd "$PYENV_TEST_DIR"
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "no version selected" {
|
|
|
|
assert [ ! -d "${PYENV_ROOT}/versions" ]
|
|
|
|
run pyenv-version-name
|
|
|
|
assert_success "system"
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "system version is not checked for existance" {
|
|
|
|
PYENV_VERSION=system run pyenv-version-name
|
|
|
|
assert_success "system"
|
|
|
|
}
|
|
|
|
|
2016-03-01 20:39:52 -05:00
|
|
|
@test "PYENV_VERSION can be overridden by hook" {
|
|
|
|
create_version "2.7.11"
|
|
|
|
create_version "3.5.1"
|
|
|
|
create_hook version-name test.bash <<<"PYENV_VERSION=3.5.1"
|
2015-05-27 23:10:39 -04:00
|
|
|
|
2016-03-01 20:39:52 -05:00
|
|
|
PYENV_VERSION=2.7.11 run pyenv-version-name
|
|
|
|
assert_success "3.5.1"
|
2015-05-27 23:10:39 -04:00
|
|
|
}
|
|
|
|
|
2015-12-29 11:15:27 -05:00
|
|
|
@test "carries original IFS within hooks" {
|
|
|
|
create_hook version-name hello.bash <<SH
|
|
|
|
hellos=(\$(printf "hello\\tugly world\\nagain"))
|
|
|
|
echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
|
|
|
|
SH
|
|
|
|
|
2016-03-01 20:39:52 -05:00
|
|
|
export PYENV_VERSION=system
|
|
|
|
IFS=$' \t\n' run pyenv-version-name env
|
2015-12-29 11:15:27 -05:00
|
|
|
assert_success
|
|
|
|
assert_line "HELLO=:hello:ugly:world:again"
|
|
|
|
}
|
|
|
|
|
2014-01-02 11:48:22 -05:00
|
|
|
@test "PYENV_VERSION has precedence over local" {
|
2016-03-01 20:39:52 -05:00
|
|
|
create_version "2.7.11"
|
|
|
|
create_version "3.5.1"
|
2014-01-02 11:48:22 -05:00
|
|
|
|
2014-01-02 14:38:29 -05:00
|
|
|
cat > ".python-version" <<<"2.7.6"
|
2014-01-02 11:48:22 -05:00
|
|
|
run pyenv-version-name
|
2014-01-02 14:38:29 -05:00
|
|
|
assert_success "2.7.6"
|
2014-01-02 11:48:22 -05:00
|
|
|
|
2014-01-02 14:38:29 -05:00
|
|
|
PYENV_VERSION=3.3.3 run pyenv-version-name
|
|
|
|
assert_success "3.3.3"
|
2014-01-02 11:48:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "local file has precedence over global" {
|
2014-01-02 14:38:29 -05:00
|
|
|
create_version "2.7.6"
|
|
|
|
create_version "3.3.3"
|
2014-01-02 11:48:22 -05:00
|
|
|
|
2014-01-02 14:38:29 -05:00
|
|
|
cat > "${PYENV_ROOT}/version" <<<"2.7.6"
|
2014-01-02 11:48:22 -05:00
|
|
|
run pyenv-version-name
|
2014-01-02 14:38:29 -05:00
|
|
|
assert_success "2.7.6"
|
2014-01-02 11:48:22 -05:00
|
|
|
|
2014-01-02 14:38:29 -05:00
|
|
|
cat > ".python-version" <<<"3.3.3"
|
2014-01-02 11:48:22 -05:00
|
|
|
run pyenv-version-name
|
2014-01-02 14:38:29 -05:00
|
|
|
assert_success "3.3.3"
|
2014-01-02 11:48:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "missing version" {
|
|
|
|
PYENV_VERSION=1.2 run pyenv-version-name
|
2015-11-20 23:13:52 -05:00
|
|
|
assert_failure "pyenv: version \`1.2' is not installed (set by PYENV_VERSION environment variable)"
|
2014-01-02 11:48:22 -05:00
|
|
|
}
|
|
|
|
|
2014-12-11 12:47:09 -05:00
|
|
|
@test "one missing version (second missing)" {
|
|
|
|
create_version "3.4.2"
|
|
|
|
PYENV_VERSION="3.4.2:1.2" run pyenv-version-name
|
|
|
|
assert_failure
|
|
|
|
assert_output <<OUT
|
2015-11-20 23:13:52 -05:00
|
|
|
pyenv: version \`1.2' is not installed (set by PYENV_VERSION environment variable)
|
2014-12-11 12:47:09 -05:00
|
|
|
3.4.2
|
|
|
|
OUT
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "one missing version (first missing)" {
|
|
|
|
create_version "3.4.2"
|
|
|
|
PYENV_VERSION="1.2:3.4.2" run pyenv-version-name
|
|
|
|
assert_failure
|
|
|
|
assert_output <<OUT
|
2015-11-20 23:13:52 -05:00
|
|
|
pyenv: version \`1.2' is not installed (set by PYENV_VERSION environment variable)
|
2014-12-11 12:47:09 -05:00
|
|
|
3.4.2
|
|
|
|
OUT
|
|
|
|
}
|
|
|
|
|
2014-12-11 14:37:03 -05:00
|
|
|
pyenv-version-name-without-stderr() {
|
|
|
|
pyenv-version-name 2>/dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "one missing version (without stderr)" {
|
|
|
|
create_version "3.4.2"
|
|
|
|
PYENV_VERSION="1.2:3.4.2" run pyenv-version-name-without-stderr
|
|
|
|
assert_failure
|
|
|
|
assert_output <<OUT
|
|
|
|
3.4.2
|
|
|
|
OUT
|
|
|
|
}
|
|
|
|
|
2014-01-02 11:48:22 -05:00
|
|
|
@test "version with prefix in name" {
|
2014-01-02 14:38:29 -05:00
|
|
|
create_version "2.7.6"
|
|
|
|
cat > ".python-version" <<<"python-2.7.6"
|
2014-01-02 11:48:22 -05:00
|
|
|
run pyenv-version-name
|
|
|
|
assert_success
|
2015-03-06 11:01:32 -05:00
|
|
|
assert_output "2.7.6"
|
2014-01-02 11:48:22 -05:00
|
|
|
}
|