tests: refactor: migrate to newly-added create_stub()

This commit is contained in:
Ivan Pozdeev 2025-12-20 09:31:05 +03:00 committed by Ivan Pozdeev
parent 7418835908
commit 6113214f65
No known key found for this signature in database
GPG Key ID: FB6A628DCF06DCD7
2 changed files with 12 additions and 34 deletions

View File

@ -2,10 +2,6 @@
load test_helper load test_helper
_setup() {
export PATH="${PYENV_TEST_DIR}/bin:$PATH"
}
@test "creates shims and versions directories" { @test "creates shims and versions directories" {
assert [ ! -d "${PYENV_ROOT}/shims" ] assert [ ! -d "${PYENV_ROOT}/shims" ]
assert [ ! -d "${PYENV_ROOT}/versions" ] assert [ ! -d "${PYENV_ROOT}/versions" ]
@ -171,16 +167,14 @@ echo "\$PATH"
} }
@test "outputs sh-compatible case syntax" { @test "outputs sh-compatible case syntax" {
create_path_executable pyenv-commands <<! create_stub pyenv-commands <<!
#!$BASH
echo -e 'activate\ndeactivate\nrehash\nshell' echo -e 'activate\ndeactivate\nrehash\nshell'
! !
run pyenv-init - bash run pyenv-init - bash
assert_success assert_success
assert_line ' activate|deactivate|rehash|shell)' assert_line ' activate|deactivate|rehash|shell)'
create_path_executable pyenv-commands <<! create_stub pyenv-commands <<!
#!$BASH
echo echo
! !
run pyenv-init - bash run pyenv-init - bash

View File

@ -2,13 +2,8 @@
load test_helper load test_helper
_setup() {
export PATH="${PYENV_TEST_DIR}/bin:$PATH"
}
@test "read from installed" { @test "read from installed" {
create_path_executable pyenv-versions <<! create_stub pyenv-versions <<!
#!$BASH
echo 4.5.6 echo 4.5.6
! !
run pyenv-latest 4 run pyenv-latest 4
@ -19,8 +14,7 @@ echo 4.5.6
} }
@test "read from known" { @test "read from known" {
create_path_executable python-build <<! create_stub python-build <<!
#!$BASH
echo 4.5.6 echo 4.5.6
! !
run pyenv-latest -k 4 run pyenv-latest -k 4
@ -31,8 +25,7 @@ echo 4.5.6
} }
@test "installed version not found" { @test "installed version not found" {
create_path_executable pyenv-versions <<! create_stub pyenv-versions <<!
#!$BASH
echo 3.5.6 echo 3.5.6
echo 3.10.8 echo 3.10.8
! !
@ -44,8 +37,7 @@ pyenv: no installed versions match the prefix \`3.8'
} }
@test "known version not found" { @test "known version not found" {
create_path_executable python-build <<! create_stub python-build <<!
#!$BASH
echo 3.5.6 echo 3.5.6
echo 3.10.8 echo 3.10.8
! !
@ -57,8 +49,7 @@ pyenv: no known versions match the prefix \`3.8'
} }
@test "complete name resolves to itself" { @test "complete name resolves to itself" {
create_path_executable pyenv-versions <<! create_stub pyenv-versions <<!
#!$BASH
echo foo echo foo
echo foo.bar echo foo.bar
! !
@ -72,8 +63,7 @@ foo
} }
@test "sort CPython" { @test "sort CPython" {
create_path_executable pyenv-versions <<! create_stub pyenv-versions <<!
#!$BASH
echo 2.7.18 echo 2.7.18
echo 3.5.6 echo 3.5.6
echo 3.10.8 echo 3.10.8
@ -87,8 +77,7 @@ echo 3.10.6
} }
@test "ignores rolling releases, branch tips, alternative srcs, prereleases, virtualenvs; 't' versions if prefix without 't'" { @test "ignores rolling releases, branch tips, alternative srcs, prereleases, virtualenvs; 't' versions if prefix without 't'" {
create_path_executable pyenv-versions <<! create_stub pyenv-versions <<!
#!$BASH
echo 3.8.5-dev echo 3.8.5-dev
echo 3.8.5-src echo 3.8.5-src
echo 3.8.5-latest echo 3.8.5-latest
@ -109,8 +98,7 @@ echo 3.8.1/envs/foo
} }
@test "resolves to a 't' version if prefix has 't'" { @test "resolves to a 't' version if prefix has 't'" {
create_path_executable pyenv-versions <<! create_stub pyenv-versions <<!
#!$BASH
echo 3.13.2t echo 3.13.2t
echo 3.13.5 echo 3.13.5
echo 3.13.5t echo 3.13.5t
@ -124,9 +112,7 @@ echo 3.14.6
} }
@test "falls back to argument with -b" { @test "falls back to argument with -b" {
create_path_executable pyenv-versions <<! create_stub pyenv-versions
#!$BASH
!
run pyenv-latest -b nonexistent run pyenv-latest -b nonexistent
assert_failure assert_failure
assert_output <<! assert_output <<!
@ -135,9 +121,7 @@ nonexistent
} }
@test "falls back to argument and succeeds with -f" { @test "falls back to argument and succeeds with -f" {
create_path_executable pyenv-versions <<! create_stub pyenv-versions
#!$BASH
!
run pyenv-latest -f nonexistent run pyenv-latest -f nonexistent
assert_success assert_success
assert_output <<! assert_output <<!