Files

427 lines
11 KiB
Bash
Raw Permalink Normal View History

2014-10-29 03:35:29 -07:00
#!/usr/bin/env bats
load test_helper
2025-09-08 16:47:50 +02:00
_setup() {
export PYENV_ROOT="${BATS_TEST_TMPDIR}/pyenv"
2014-10-29 03:35:29 -07:00
stub pyenv-hooks 'install : true'
2023-01-22 05:49:40 +03:00
stub pyenv-rehash true
2014-10-29 03:35:29 -07:00
}
2023-01-22 05:49:40 +03:00
stub_python_build_lib() {
2014-10-29 03:35:29 -07:00
stub python-build "--lib : $BATS_TEST_DIRNAME/../bin/python-build --lib" "$@"
}
2023-01-22 05:49:40 +03:00
stub_python_build_no_latest() {
stub python-build "${@:-echo python-build \"\$@\"}"
}
2026-10-30 15:50:30 +05:00
2023-01-22 05:49:40 +03:00
stub_python_build() {
stub_python_build_no_latest "$@"
stub pyenv-latest '-f -k * : shift 2; echo "$@"'
2023-01-22 05:49:40 +03:00
}
@test "install a single version" {
stub_python_build_lib
stub_python_build
2014-10-29 03:35:29 -07:00
run pyenv-install 3.4.2
assert_success "python-build 3.4.2 ${PYENV_ROOT}/versions/3.4.2"
unstub python-build
}
@test "install a single version under an alias" {
stub_python_build_lib
stub_python_build
run pyenv-install 3.4.2:3.4.2-custom
assert_success "python-build 3.4.2 ${PYENV_ROOT}/versions/3.4.2-custom"
unstub python-build
}
@test "install multiple versions, each under its own alias" {
stub_python_build_lib
stub_python_build
stub_python_build
run pyenv-install 3.4.1:custom1 3.4.2:custom2
assert_success
assert_output <<OUT
python-build 3.4.1 ${PYENV_ROOT}/versions/custom1
python-build 3.4.2 ${PYENV_ROOT}/versions/custom2
OUT
unstub python-build
unstub pyenv-latest
}
2014-10-29 03:35:29 -07:00
2023-01-22 05:49:40 +03:00
@test "install multiple versions" {
stub_python_build_lib
stub_python_build
stub_python_build
2022-12-22 18:35:25 +01:00
run pyenv-install 3.4.1 3.4.2
assert_success
assert_output <<OUT
2025-09-08 16:47:50 +02:00
python-build 3.4.1 ${BATS_TEST_TMPDIR}/pyenv/versions/3.4.1
python-build 3.4.2 ${BATS_TEST_TMPDIR}/pyenv/versions/3.4.2
2022-12-22 18:35:25 +01:00
OUT
unstub python-build
unstub pyenv-latest
}
2023-01-22 05:49:40 +03:00
@test "install multiple versions, some fail" {
stub_python_build_lib
stub_python_build 'echo "fail: python-build" "$@"; false'
2023-01-22 05:49:40 +03:00
run pyenv-install 3.4.1 3.4.2
assert_failure
assert_output <<OUT
2025-09-08 16:47:50 +02:00
fail: python-build 3.4.1 ${BATS_TEST_TMPDIR}/pyenv/versions/3.4.1
2023-01-22 05:49:40 +03:00
OUT
unstub python-build
}
2022-12-22 18:35:25 +01:00
2023-01-22 05:49:40 +03:00
@test "install resolves a prefix" {
stub_python_build_lib
for i in {1..3}; do stub_python_build_no_latest; done
stub pyenv-latest \
'-r -k 3.4 : echo 3.4.2' \
'-r -k 3.5.1 : false' \
'-r -k 3.5 : echo 3.5.2'
2023-01-22 05:49:40 +03:00
run pyenv-install 3.4 3.5.1 3.5
2022-12-22 18:35:25 +01:00
assert_success <<OUT
python-build 3.4.2 ${PYENV_ROOT}/versions/3.4.2
2023-01-22 05:49:40 +03:00
python-build 3.5.1 ${PYENV_ROOT}/versions/3.5.1
2022-12-22 18:35:25 +01:00
python-build 3.5.2 ${PYENV_ROOT}/versions/3.5.2
OUT
unstub python-build
}
2023-01-22 05:49:40 +03:00
@test "install resolves :latest" {
stub_python_build_lib
for i in {1..2}; do stub_python_build '--definitions : echo -e 3.4.2\\n3.5.1\\n3.5.2'; done
for i in {1..2}; do stub_python_build; done
2026-10-30 15:50:30 +05:00
2023-01-22 05:49:40 +03:00
pyenv-hooks install; unstub pyenv-hooks
PYENV_INSTALL_ROOT="$BATS_TEST_DIRNAME/../../.."
export PYENV_HOOK_PATH="$PYENV_INSTALL_ROOT/pyenv.d"
[[ -d "$PYENV_INSTALL_ROOT/libexec" ]] || skip "python-build is installed separately from pyenv"
export PATH="$PATH:$PYENV_INSTALL_ROOT/libexec"
run pyenv-install 3.4:latest 3:latest
assert_success <<!
python-build 3.4.2 ${PYENV_ROOT}/versions/3.4.2
python-build 3.5.2 ${PYENV_ROOT}/versions/3.5.2
!
unstub python-build
}
@test "install :latest ignores prereleases, rolling releases, alternative srcs, and 't' versions" {
stub_python_build_lib
for i in {1..2}; do stub_python_build_no_latest '--definitions : echo -e 3.4.2\\n3.5.1\\n3.5.2\\n3.5.3-dev\\n3.5.3-src\\n3.5.3a1\\n3.5.3b1\\n3.5.3rc1\\n3.5.3t\\n3.6.0a2\\n3.6.0a2t'; done
for i in {1..2}; do stub_python_build; done
pyenv-hooks install; unstub pyenv-hooks
PYENV_INSTALL_ROOT="$BATS_TEST_DIRNAME/../../.."
export PYENV_HOOK_PATH="$PYENV_INSTALL_ROOT/pyenv.d"
[[ -d "$PYENV_INSTALL_ROOT/libexec" ]] || skip "python-build is installed separately from pyenv"
export PATH="$PATH:$PYENV_INSTALL_ROOT/libexec"
run pyenv-install 3.5:latest 3:latest
assert_success
assert_output <<!
python-build 3.5.2 ${PYENV_ROOT}/versions/3.5.2
python-build 3.5.2 ${PYENV_ROOT}/versions/3.5.2
!
unstub python-build
unstub pyenv-latest
}
2023-01-22 05:49:40 +03:00
@test "install installs local versions by default" {
stub_python_build_lib
stub_python_build
stub_python_build
stub pyenv-local 'echo 3.4.2; echo 3.4.1'
2022-12-22 18:35:25 +01:00
run pyenv-install
assert_success <<OUT
2023-01-22 05:49:40 +03:00
python-build 3.4.2
python-build 3.4.1
2022-12-22 18:35:25 +01:00
OUT
unstub python-build
unstub pyenv-local
}
2014-10-29 03:35:29 -07:00
@test "list available versions" {
2023-01-22 05:49:40 +03:00
stub_python_build_lib
stub_python_build "--definitions : echo 2.6.9 2.7.9-rc1 2.7.9-rc2 3.4.2 | tr ' ' $'\\n'"
2014-10-29 03:35:29 -07:00
run pyenv-install --list
assert_success
assert_output <<OUT
Available versions:
2.6.9
2.7.9-rc1
2.7.9-rc2
3.4.2
OUT
unstub python-build
}
@test "list available versions with --bare" {
stub_python_build_lib
stub_python_build "--definitions : echo 2.6.9 2.7.9-rc1 2.7.9-rc2 3.4.2 | tr ' ' $'\\n'"
run pyenv-install --list --bare
assert_success
assert_output <<OUT
2.6.9
2.7.9-rc1
2.7.9-rc2
3.4.2
OUT
unstub python-build
}
@test "bare listing fails when definition listing fails" {
stub_python_build_lib '--definitions : echo "listing failed" >&2; exit 1'
run pyenv-install --list --bare
assert_failure "listing failed"
unstub python-build
}
2023-01-22 05:49:40 +03:00
@test "upgrade instructions given for a nonexistent version" {
2014-10-29 03:35:29 -07:00
stub brew false
2023-01-22 05:49:40 +03:00
stub_python_build_lib
stub_python_build 'echo ERROR >&2 && exit 2'
stub_python_build "--definitions : echo 2.6.9 2.7.9-rc1 2.7.9-rc2 3.4.2 | tr ' ' $'\\n'"
2014-10-29 03:35:29 -07:00
mkdir "$BATS_TEST_TMPDIR/.git"
#Faking the Pyenv installation prefix may break things.
# May have to move some dependent stuff into the fake root for the code to find it
# or introduce an overriding test variable in the code specifically for the hint.
_PYENV_INSTALL_PREFIX="$BATS_TEST_TMPDIR" run pyenv-install 2.7.9
2014-10-29 03:35:29 -07:00
assert_failure
assert_output <<OUT
ERROR
The following versions contain \`2.7.9' in the name:
2.7.9-rc1
2.7.9-rc2
See all available versions with \`pyenv install --list'.
2014-11-03 00:33:44 -08:00
If the version you need is missing, try upgrading pyenv:
2014-10-29 03:35:29 -07:00
cd ${BATS_TEST_TMPDIR} && git pull && cd -
2014-10-29 03:35:29 -07:00
OUT
unstub python-build
}
2023-01-22 05:49:40 +03:00
@test "homebrew upgrade instructions given when pyenv is homebrew-installed" {
stub brew "--prefix : echo '${_PYENV_INSTALL_PREFIX}'"
2023-01-22 05:49:40 +03:00
stub_python_build_lib
2014-10-29 03:35:29 -07:00
stub_python_build 'echo ERROR >&2 && exit 2' \
"--definitions : true"
_PYENV_INSTALL_PREFIX="$BATS_TEST_TMPDIR" run pyenv-install 1.9.3
2014-10-29 03:35:29 -07:00
assert_failure
assert_output <<OUT
ERROR
See all available versions with \`pyenv install --list'.
2014-11-03 00:33:44 -08:00
If the version you need is missing, try upgrading pyenv:
2014-10-29 03:35:29 -07:00
brew update && brew upgrade pyenv
OUT
unstub brew
unstub python-build
}
@test "no build definitions from plugins" {
assert [ ! -e "${PYENV_ROOT}/plugins" ]
2023-01-22 05:49:40 +03:00
stub_python_build_lib
2014-10-29 03:35:29 -07:00
stub_python_build 'echo $PYTHON_BUILD_DEFINITIONS'
run pyenv-install 3.4.2
assert_success ""
2026-10-30 15:50:30 +05:00
2023-01-22 05:49:40 +03:00
unstub python-build
2014-10-29 03:35:29 -07:00
}
@test "some build definitions from plugins" {
mkdir -p "${PYENV_ROOT}/plugins/foo/share/python-build"
mkdir -p "${PYENV_ROOT}/plugins/bar/share/python-build"
2023-01-22 05:49:40 +03:00
stub_python_build_lib
2014-10-29 03:35:29 -07:00
stub_python_build "echo \$PYTHON_BUILD_DEFINITIONS | tr ':' $'\\n'"
run pyenv-install 3.4.2
assert_success
assert_output <<OUT
${PYENV_ROOT}/plugins/bar/share/python-build
${PYENV_ROOT}/plugins/foo/share/python-build
OUT
2023-01-22 05:49:40 +03:00
unstub python-build
2014-10-29 03:35:29 -07:00
}
@test "list build definitions from plugins" {
mkdir -p "${PYENV_ROOT}/plugins/foo/share/python-build"
mkdir -p "${PYENV_ROOT}/plugins/bar/share/python-build"
2023-01-22 05:49:40 +03:00
stub_python_build_lib
2014-10-29 03:35:29 -07:00
stub_python_build "--definitions : echo \$PYTHON_BUILD_DEFINITIONS | tr ':' $'\\n'"
run pyenv-install --list
assert_success
assert_output <<OUT
Available versions:
${PYENV_ROOT}/plugins/bar/share/python-build
${PYENV_ROOT}/plugins/foo/share/python-build
OUT
2023-01-22 05:49:40 +03:00
unstub python-build
2014-10-29 03:35:29 -07:00
}
@test "completion results include build definitions from plugins" {
mkdir -p "${PYENV_ROOT}/plugins/foo/share/python-build"
mkdir -p "${PYENV_ROOT}/plugins/bar/share/python-build"
2023-01-22 05:49:40 +03:00
stub_python_build "--definitions : echo \$PYTHON_BUILD_DEFINITIONS | tr ':' $'\\n'"
2014-10-29 03:35:29 -07:00
run pyenv-install --complete
assert_success
assert_output <<OUT
--bare
--list
--force
--skip-existing
--keep
--patch
--verbose
--version
--debug
2014-10-29 03:35:29 -07:00
${PYENV_ROOT}/plugins/bar/share/python-build
${PYENV_ROOT}/plugins/foo/share/python-build
OUT
2023-01-22 05:49:40 +03:00
unstub python-build
2014-10-29 03:35:29 -07:00
}
2015-01-15 23:13:36 +09:00
2022-12-22 18:35:25 +01:00
@test "not enough arguments for pyenv-install if no local version" {
2023-01-22 05:49:40 +03:00
stub_python_build_lib
2015-08-25 15:37:31 +09:00
stub pyenv-help 'install : true'
2015-01-15 23:13:36 +09:00
run pyenv-install
assert_failure
2015-08-25 15:37:31 +09:00
unstub pyenv-help
2022-12-22 18:35:25 +01:00
assert_output ""
2015-01-15 23:13:36 +09:00
}
@test "show help for pyenv-install" {
2015-08-25 15:37:31 +09:00
stub pyenv-help 'install : true'
2015-01-15 23:13:36 +09:00
run pyenv-install -h
assert_success
2015-08-25 15:37:31 +09:00
unstub pyenv-help
}
@test "pyenv-install has usage help preface" {
run head "$(command -v pyenv-install)"
2015-01-15 23:13:36 +09:00
assert_output_contains 'Usage: pyenv install'
}
@test "not enough arguments pyenv-uninstall" {
2015-08-25 15:37:31 +09:00
stub pyenv-help 'uninstall : true'
2015-01-15 23:13:36 +09:00
run pyenv-uninstall
assert_failure
2015-08-25 15:37:31 +09:00
unstub pyenv-help
2015-01-15 23:13:36 +09:00
}
2023-01-22 05:49:40 +03:00
@test "multiple arguments for pyenv-uninstall" {
mkdir -p "${PYENV_ROOT}/versions/3.4.1"
mkdir -p "${PYENV_ROOT}/versions/3.4.2"
run pyenv-uninstall -f 3.4.1 3.4.2
assert_success
refute [ -d "${PYENV_ROOT}/versions/3.4.1" ]
refute [ -d "${PYENV_ROOT}/versions/3.4.2" ]
}
2015-08-25 15:37:31 +09:00
@test "invalid arguments for pyenv-uninstall" {
2025-09-15 13:38:35 +02:00
bats_require_minimum_version 1.5.0
mkdir -p "${PYENV_ROOT}/versions/3.10.3"
mkdir -p "${PYENV_ROOT}/versions/3.10.4"
2025-09-15 13:38:35 +02:00
run -127 pyenv-uninstall -f 3.10.3 --invalid-option 3.10.4
2015-01-15 23:13:36 +09:00
assert_failure
assert [ -d "${PYENV_ROOT}/versions/3.10.3" ]
assert [ -d "${PYENV_ROOT}/versions/3.10.4" ]
rmdir "${PYENV_ROOT}/versions/3.10.3"
rmdir "${PYENV_ROOT}/versions/3.10.4"
2015-01-15 23:13:36 +09:00
}
@test "show help for pyenv-uninstall" {
2015-08-25 15:37:31 +09:00
stub pyenv-help 'uninstall : true'
2015-01-15 23:13:36 +09:00
run pyenv-uninstall -h
assert_success
2015-08-25 15:37:31 +09:00
unstub pyenv-help
}
@test "pyenv-uninstall has usage help preface" {
run head "$(command -v pyenv-uninstall)"
2015-01-15 23:13:36 +09:00
assert_output_contains 'Usage: pyenv uninstall'
}
@test "pyenv-uninstall lists installed versions matching a missing version's prefix" {
mkdir -p "${PYENV_ROOT}/versions/3.7.1"
mkdir -p "${PYENV_ROOT}/versions/3.7.14"
mkdir -p "${PYENV_ROOT}/versions/3.7-dev"
mkdir -p "${PYENV_ROOT}/versions/3.70.0"
mkdir -p "${PYENV_ROOT}/versions/3.8.1"
ln -s "${PYENV_ROOT}/versions/3.7.14" "${PYENV_ROOT}/versions/3.7.alias"
run pyenv-uninstall 3.7
assert_failure
assert_output <<OUT
pyenv: version \`3.7' not installed
pyenv: installed versions starting with \`3.7':
3.7.1
3.7.14
3.7-dev
OUT
assert [ -d "${PYENV_ROOT}/versions/3.7.1" ]
assert [ -d "${PYENV_ROOT}/versions/3.7.14" ]
assert [ -d "${PYENV_ROOT}/versions/3.7-dev" ]
}
@test "pyenv-uninstall reports a missing version without suggestions when nothing matches" {
mkdir -p "${PYENV_ROOT}/versions/3.8.1"
run pyenv-uninstall 3.7
assert_failure "pyenv: version \`3.7' not installed"
}