mirror of
https://github.com/pyenv/pyenv.git
synced 2025-11-13 05:43:53 -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:
@@ -378,6 +378,9 @@ OUT
|
||||
stub port "-q installed libyaml : echo ' libyaml @0.2.5_0 (active)'"
|
||||
for i in {1..3}; do stub port false; done
|
||||
stub_make_install
|
||||
export PYTHON_BUILD_SKIP_HOMEBREW=1
|
||||
PORT_PREFIX="$(which port)"
|
||||
PORT_PREFIX="${PORT_PREFIX%/bin/port}"
|
||||
|
||||
install_fixture definitions/needs-yaml
|
||||
assert_success
|
||||
@@ -403,6 +406,9 @@ OUT
|
||||
stub port "-q installed readline : echo ' readline @8.2.013_0 (active)'"
|
||||
for i in {1..2}; do stub port false; done
|
||||
stub_make_install
|
||||
export PYTHON_BUILD_SKIP_HOMEBREW=1
|
||||
PORT_PREFIX="$(which port)"
|
||||
PORT_PREFIX="${PORT_PREFIX%/bin/port}"
|
||||
|
||||
run_inline_definition <<DEF
|
||||
install_package "Python-3.6.2" "http://python.org/ftp/python/3.6.2/Python-3.6.2.tar.gz"
|
||||
@@ -431,6 +437,9 @@ OUT
|
||||
stub port "-q installed ncurses : echo '$ncurses_libdir'"
|
||||
stub port false
|
||||
stub_make_install
|
||||
export PYTHON_BUILD_SKIP_HOMEBREW=1
|
||||
PORT_PREFIX="$(which port)"
|
||||
PORT_PREFIX="${PORT_PREFIX%/bin/port}"
|
||||
|
||||
run_inline_definition <<DEF
|
||||
install_package "Python-3.6.2" "http://python.org/ftp/python/3.6.2/Python-3.6.2.tar.gz"
|
||||
@@ -845,6 +854,7 @@ OUT
|
||||
|
||||
stub uname '-s : echo Darwin'
|
||||
stub sw_vers '-productVersion : echo 10.10'
|
||||
for i in {1..6}; do stub brew false; done
|
||||
|
||||
stub sysctl false
|
||||
stub_make_install
|
||||
@@ -857,6 +867,7 @@ DEF
|
||||
|
||||
unstub uname
|
||||
unstub sw_vers
|
||||
unstub brew
|
||||
unstub make
|
||||
|
||||
assert_build_log <<OUT
|
||||
@@ -872,6 +883,7 @@ OUT
|
||||
|
||||
stub uname '-s : echo Darwin'
|
||||
stub sw_vers '-productVersion : echo 10.10'
|
||||
for i in {1..6}; do stub brew false; done
|
||||
|
||||
stub sysctl '-n hw.ncpu : echo 4'
|
||||
stub_make_install
|
||||
@@ -884,6 +896,7 @@ DEF
|
||||
|
||||
unstub uname
|
||||
unstub sw_vers
|
||||
unstub brew
|
||||
unstub sysctl
|
||||
unstub make
|
||||
|
||||
|
||||
@@ -87,9 +87,9 @@ jython-2.5.4-rc1
|
||||
jython-2.7-beta1
|
||||
jython-2.7-beta2
|
||||
jython-2.7-beta3"
|
||||
for ver in "$expected"; do
|
||||
while IFS=$'\n' read -r ver; do
|
||||
touch "${PYTHON_BUILD_ROOT}/share/python-build/$ver"
|
||||
done
|
||||
done <<<"$expected"
|
||||
run python-build --definitions
|
||||
assert_success "$expected"
|
||||
}
|
||||
|
||||
@@ -6,9 +6,7 @@ if [ "$FIXTURE_ROOT" != "$BATS_TEST_DIRNAME/fixtures" ]; then
|
||||
export FIXTURE_ROOT="$BATS_TEST_DIRNAME/fixtures"
|
||||
export INSTALL_ROOT="$TMP/install"
|
||||
PATH="/usr/bin:/bin:/usr/sbin:/sbin"
|
||||
if [ "FreeBSD" = "$(uname -s)" ]; then
|
||||
PATH="/usr/local/bin:$PATH"
|
||||
fi
|
||||
PATH="$BATS_TEST_DIRNAME/../bin:$PATH"
|
||||
PATH="$TMP/bin:$PATH"
|
||||
export PATH
|
||||
@@ -29,7 +27,7 @@ stub() {
|
||||
export "${prefix}_STUB_END"=
|
||||
|
||||
mkdir -p "${TMP}/bin"
|
||||
ln -sf "${BATS_TEST_DIRNAME}/stubs/stub" "${TMP}/bin/${program}"
|
||||
cp "${BATS_TEST_DIRNAME}/stubs/stub" "${TMP}/bin/${program}"
|
||||
|
||||
touch "${TMP}/${program}-stub-plan"
|
||||
for arg in "$@"; do printf "%s\n" "$arg" >> "${TMP}/${program}-stub-plan"; done
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ load test_helper
|
||||
mkdir -p "${PYENV_TEST_DIR}/bin"
|
||||
touch "${PYENV_TEST_DIR}/bin/python"
|
||||
chmod +x "${PYENV_TEST_DIR}/bin/python"
|
||||
PYENV_VERSION="system" run pyenv-prefix
|
||||
PATH="${PYENV_TEST_DIR}/libexec:$PATH" PYENV_VERSION="system" run pyenv-prefix
|
||||
assert_success "$PYENV_TEST_DIR"
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ load test_helper
|
||||
echo /bin/python
|
||||
OUT
|
||||
chmod +x "${BATS_TEST_DIRNAME}/libexec/pyenv-which"
|
||||
PYENV_VERSION="system" run pyenv-prefix
|
||||
PATH="${PYENV_TEST_DIR}/libexec:$PATH" PYENV_VERSION="system" run pyenv-prefix
|
||||
assert_success "/"
|
||||
rm -f "${BATS_TEST_DIRNAME}/libexec/pyenv-which"
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ unset PYENV_DIR
|
||||
if [ -z "$PYENV_TEST_DIR" ]; then
|
||||
PYENV_TEST_DIR="${BATS_TMPDIR}/pyenv"
|
||||
export PYENV_TEST_DIR="$(mktemp -d "${PYENV_TEST_DIR}.XXX" 2>/dev/null || echo "$PYENV_TEST_DIR")"
|
||||
mkdir -p "${PYENV_TEST_DIR}"
|
||||
|
||||
if enable -f "${BATS_TEST_DIRNAME}"/../libexec/pyenv-realpath.dylib realpath 2>/dev/null; then
|
||||
export PYENV_TEST_DIR="$(realpath "$PYENV_TEST_DIR")"
|
||||
|
||||
@@ -238,6 +238,7 @@ OUT
|
||||
}
|
||||
|
||||
@test "non-bare output shows symlink contents" {
|
||||
stub_system_python
|
||||
create_version "1.9.0"
|
||||
create_alias "link" "1.9.0"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user