2014-01-02 11:48:22 -05:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
load test_helper
|
|
|
|
|
|
|
|
create_executable() {
|
|
|
|
name="${1?}"
|
|
|
|
shift 1
|
|
|
|
bin="${PYENV_ROOT}/versions/${PYENV_VERSION}/bin"
|
|
|
|
mkdir -p "$bin"
|
|
|
|
{ if [ $# -eq 0 ]; then cat -
|
|
|
|
else echo "$@"
|
|
|
|
fi
|
|
|
|
} | sed -Ee '1s/^ +//' > "${bin}/$name"
|
|
|
|
chmod +x "${bin}/$name"
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "fails with invalid version" {
|
2014-01-02 14:38:29 -05:00
|
|
|
export PYENV_VERSION="3.4"
|
2015-11-20 23:13:52 -05:00
|
|
|
run pyenv-exec python -V
|
|
|
|
assert_failure "pyenv: version \`3.4' is not installed (set by PYENV_VERSION environment variable)"
|
2013-03-31 21:01:37 -04:00
|
|
|
}
|
|
|
|
|
2015-11-13 22:53:27 -05:00
|
|
|
@test "fails with invalid version set from file" {
|
2015-11-20 23:13:52 -05:00
|
|
|
mkdir -p "$PYENV_TEST_DIR"
|
|
|
|
cd "$PYENV_TEST_DIR"
|
|
|
|
echo 2.7 > .python-version
|
|
|
|
run pyenv-exec rspec
|
|
|
|
assert_failure "pyenv: version \`2.7' is not installed (set by $PWD/.python-version)"
|
2014-01-02 11:48:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "completes with names of executables" {
|
2014-01-02 14:38:29 -05:00
|
|
|
export PYENV_VERSION="3.4"
|
|
|
|
create_executable "fab" "#!/bin/sh"
|
2014-01-02 11:48:22 -05:00
|
|
|
create_executable "python" "#!/bin/sh"
|
|
|
|
|
|
|
|
pyenv-rehash
|
|
|
|
run pyenv-completions exec
|
|
|
|
assert_success
|
|
|
|
assert_output <<OUT
|
2015-11-17 15:01:33 -05:00
|
|
|
--help
|
2014-01-02 14:38:29 -05:00
|
|
|
fab
|
2014-01-02 11:48:22 -05:00
|
|
|
python
|
|
|
|
OUT
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "carries original IFS within hooks" {
|
2015-12-29 11:01:10 -05:00
|
|
|
create_hook exec hello.bash <<SH
|
2014-01-02 11:48:22 -05:00
|
|
|
hellos=(\$(printf "hello\\tugly world\\nagain"))
|
|
|
|
echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
|
|
|
|
SH
|
|
|
|
|
|
|
|
export PYENV_VERSION=system
|
2016-03-01 20:39:52 -05:00
|
|
|
IFS=$' \t\n' run pyenv-exec env
|
2014-01-02 11:48:22 -05:00
|
|
|
assert_success
|
|
|
|
assert_line "HELLO=:hello:ugly:world:again"
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "forwards all arguments" {
|
2014-01-02 14:38:29 -05:00
|
|
|
export PYENV_VERSION="3.4"
|
2014-01-02 11:48:22 -05:00
|
|
|
create_executable "python" <<SH
|
|
|
|
#!$BASH
|
|
|
|
echo \$0
|
|
|
|
for arg; do
|
|
|
|
# hack to avoid bash builtin echo which can't output '-e'
|
|
|
|
printf " %s\\n" "\$arg"
|
|
|
|
done
|
|
|
|
SH
|
|
|
|
|
|
|
|
run pyenv-exec python -w "/path to/python script.rb" -- extra args
|
|
|
|
assert_success
|
|
|
|
assert_output <<OUT
|
2014-01-02 14:38:29 -05:00
|
|
|
${PYENV_ROOT}/versions/3.4/bin/python
|
2014-01-02 11:48:22 -05:00
|
|
|
-w
|
|
|
|
/path to/python script.rb
|
|
|
|
--
|
|
|
|
extra
|
|
|
|
args
|
|
|
|
OUT
|
|
|
|
}
|
2019-09-28 18:03:44 -04:00
|
|
|
|
|
|
|
@test "sys.executable with system version (#98)" {
|
2021-06-09 20:57:58 -04:00
|
|
|
system_python=$(which python3)
|
2019-09-28 18:03:44 -04:00
|
|
|
|
|
|
|
PYENV_VERSION="custom"
|
2021-06-09 20:57:58 -04:00
|
|
|
create_executable "python3" ""
|
2019-09-28 18:03:44 -04:00
|
|
|
unset PYENV_VERSION
|
|
|
|
|
|
|
|
pyenv-rehash
|
2021-06-09 20:57:58 -04:00
|
|
|
run pyenv-exec python3 -c 'import sys; print(sys.executable)'
|
2019-09-28 18:03:44 -04:00
|
|
|
assert_success "${system_python}"
|
|
|
|
}
|
|
|
|
|
2021-05-04 13:24:28 -04:00
|
|
|
@test 'PATH is not modified with system Python' {
|
2019-09-28 18:03:44 -04:00
|
|
|
# Create a wrapper executable that verifies PATH.
|
|
|
|
PYENV_VERSION="custom"
|
2021-06-09 20:57:58 -04:00
|
|
|
create_executable "python3" '[[ "$PATH" == "${PYENV_TEST_DIR}/root/versions/custom/bin:"* ]] || { echo "unexpected:$PATH"; exit 2;}'
|
2019-09-28 18:03:44 -04:00
|
|
|
unset PYENV_VERSION
|
|
|
|
pyenv-rehash
|
|
|
|
|
|
|
|
# Path is not modified with system Python.
|
2021-06-09 20:57:58 -04:00
|
|
|
run pyenv-exec python3 -c 'import os; print(os.getenv("PATH"))'
|
2019-09-28 18:03:44 -04:00
|
|
|
assert_success "$PATH"
|
|
|
|
|
|
|
|
# Path is modified with custom Python.
|
2021-06-09 20:57:58 -04:00
|
|
|
PYENV_VERSION=custom run pyenv-exec python3
|
2019-09-28 18:03:44 -04:00
|
|
|
assert_success
|
|
|
|
|
|
|
|
# Path is modified with custom:system Python.
|
2021-06-09 20:57:58 -04:00
|
|
|
PYENV_VERSION=custom:system run pyenv-exec python3
|
2019-09-28 18:03:44 -04:00
|
|
|
assert_success
|
|
|
|
|
|
|
|
# Path is not modified with system:custom Python.
|
2021-06-09 20:57:58 -04:00
|
|
|
PYENV_VERSION=system:custom run pyenv-exec python3 -c 'import os; print(os.getenv("PATH"))'
|
2019-09-28 18:03:44 -04:00
|
|
|
assert_success "$PATH"
|
|
|
|
}
|