1
0
mirror of https://github.com/pyenv/pyenv.git synced 2025-11-18 00:03:45 -05:00

fix test isolation

Make sur that PYENV_TEST_DIR is created if mktemp failed
mock python3 usage by updating create_executable function
fix test by adding the right PATH
update path in plugin test
replace for loop with while read
don't use symlink for stub
This commit is contained in:
rockandska
2025-09-08 15:36:12 +02:00
parent 857806e6ca
commit 0d987b0e4b
7 changed files with 43 additions and 17 deletions

View File

@@ -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"
}