@ -8,7 +8,7 @@ create_executable() {
bin="${PYENV_ROOT}/versions/${PYENV_VERSION}/bin"
mkdir -p "$bin"
{ if [ $# -eq 0 ]; then cat -
else echo "$@"
else printf '%s\n' "$@"
fi
} | sed -Ee '1s/^ +//' > "${bin}/$name"
chmod +x "${bin}/$name"
@ -85,18 +85,25 @@ OUT
}
@test "sys.executable with system version (#98)" {
system_python="$(python3 -c 'import sys; print(sys.executable)')"
export PATH="${PYENV_ROOT}/versions/bin:${PATH}"
create_executable "python3" <<SH
#!$BASH
echo system
SH
system_python="$(python3)"
assert_equal "${system_python}" "system"
PYENV_VERSION="custom"
create_executable "python3" ""
unset PYENV_VERSION
export PYENV_VERSION="custom"
create_executable "python3" "#!/bin/sh" "echo custom"
pyenv-rehash
run pyenv-exec python3 -c 'import sys; print(sys.executable)'
assert_success "${system_python}"
custom_python="$(pyenv-exec python3)"
assert_equal "${custom_python}" "custom"
}
@test 'PATH is not modified with system Python' {
export PATH="${PYENV_TEST_DIR}:${PATH}"
# Create a wrapper executable that verifies PATH.
PYENV_VERSION="custom"
create_executable "python3" '[[ "$PATH" == "${PYENV_TEST_DIR}/root/versions/custom/bin:"* ]] || { echo "unexpected:$PATH"; exit 2;}'
@ -104,7 +111,13 @@ OUT
pyenv-rehash
# Path is not modified with system Python.
run pyenv-exec python3 -c 'import os; print(os.getenv("PATH"))'
cat > "${PYENV_TEST_DIR}/python3" <<SH
#!$BASH
echo \$PATH
SH
chmod +x "${PYENV_TEST_DIR}/python3"
pyenv-rehash
run pyenv-exec python3
assert_success "$PATH"
# Path is modified with custom Python.
@ -116,6 +129,6 @@ OUT
assert_success
# Path is not modified with system:custom Python.
PYENV_VERSION=system:custom run pyenv-exec python3 -c 'import os; print(os.getenv("PATH"))'
PYENV_VERSION=system:custom run pyenv-exec python3
assert_success "$PATH"
}