mirror of
https://github.com/pyenv/pyenv-virtualenv.git
synced 2025-11-08 11:33:55 -05:00
Add tests for activate and deactivate
This commit is contained in:
@@ -20,6 +20,11 @@ if [ "$1" = "--complete" ]; then
|
|||||||
exec pyenv-virtualenvs --bare
|
exec pyenv-virtualenvs --bare
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ "$1" = "--unset" ]; then
|
||||||
|
echo "pyenv deactivate"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
versions=("$@")
|
versions=("$@")
|
||||||
shell="$(basename "${PYENV_SHELL:-$SHELL}")"
|
shell="$(basename "${PYENV_SHELL:-$SHELL}")"
|
||||||
|
|
||||||
@@ -29,11 +34,6 @@ if [ -z "$versions" ]; then
|
|||||||
IFS="$OLDIFS"
|
IFS="$OLDIFS"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$1" = "--unset" ]; then
|
|
||||||
echo "pyenv deactivate"
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "${#versions[@]}" -gt 1 ]; then
|
if [ "${#versions[@]}" -gt 1 ]; then
|
||||||
echo "pyenv-virtualenv: cannot activate multiple versions at once: ${versions[@]}" 1>&2
|
echo "pyenv-virtualenv: cannot activate multiple versions at once: ${versions[@]}" 1>&2
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
87
test/activate.bats
Normal file
87
test/activate.bats
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
#!/usr/bin/env bats
|
||||||
|
|
||||||
|
load test_helper
|
||||||
|
|
||||||
|
setup() {
|
||||||
|
export PYENV_ROOT="${TMP}/pyenv"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "activate virtualenv from current version" {
|
||||||
|
stub pyenv-version-name "echo venv"
|
||||||
|
stub pyenv-virtualenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
|
||||||
|
stub pyenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
|
||||||
|
|
||||||
|
PYENV_SHELL="bash" PYENV_VERSION="venv" run pyenv-sh-activate
|
||||||
|
|
||||||
|
unstub pyenv-version-name
|
||||||
|
unstub pyenv-virtualenv-prefix
|
||||||
|
unstub pyenv-prefix
|
||||||
|
|
||||||
|
assert_success
|
||||||
|
assert_output <<EOS
|
||||||
|
pyenv shell "venv"
|
||||||
|
source "${PYENV_ROOT}/versions/venv/bin/activate"
|
||||||
|
EOS
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "activate virtualenv from current version (fish)" {
|
||||||
|
stub pyenv-version-name "echo venv"
|
||||||
|
stub pyenv-virtualenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
|
||||||
|
stub pyenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
|
||||||
|
|
||||||
|
PYENV_SHELL="fish" PYENV_VERSION="venv" run pyenv-sh-activate
|
||||||
|
|
||||||
|
unstub pyenv-version-name
|
||||||
|
unstub pyenv-virtualenv-prefix
|
||||||
|
unstub pyenv-prefix
|
||||||
|
|
||||||
|
assert_success
|
||||||
|
assert_output <<EOS
|
||||||
|
pyenv shell "venv"
|
||||||
|
. "${PYENV_ROOT}/versions/venv/bin/activate.fish"
|
||||||
|
EOS
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "activate virtualenv from command-line argument" {
|
||||||
|
stub pyenv-virtualenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
|
||||||
|
stub pyenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
|
||||||
|
|
||||||
|
run pyenv-sh-activate "venv27"
|
||||||
|
|
||||||
|
unstub pyenv-virtualenv-prefix
|
||||||
|
unstub pyenv-prefix
|
||||||
|
|
||||||
|
assert_success
|
||||||
|
assert_output <<EOS
|
||||||
|
pyenv shell "venv27"
|
||||||
|
source "${PYENV_ROOT}/versions/venv27/bin/activate"
|
||||||
|
EOS
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "unset invokes deactivate" {
|
||||||
|
run pyenv-sh-activate --unset
|
||||||
|
|
||||||
|
assert_success
|
||||||
|
assert_output <<EOS
|
||||||
|
pyenv deactivate
|
||||||
|
EOS
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "should fail if the version is not a virtualenv" {
|
||||||
|
stub pyenv-virtualenv-prefix "3.3.3 : false"
|
||||||
|
|
||||||
|
run pyenv-sh-activate "3.3.3"
|
||||||
|
|
||||||
|
unstub pyenv-virtualenv-prefix
|
||||||
|
|
||||||
|
assert_failure
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "should fail if there are multiple versions" {
|
||||||
|
run pyenv-sh-activate "venv" "venv27"
|
||||||
|
|
||||||
|
assert_failure
|
||||||
|
assert_output <<EOS
|
||||||
|
pyenv-virtualenv: cannot activate multiple versions at once: venv venv27
|
||||||
|
EOS
|
||||||
|
}
|
||||||
27
test/deactivate.bats
Normal file
27
test/deactivate.bats
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#!/usr/bin/env bats
|
||||||
|
|
||||||
|
load test_helper
|
||||||
|
|
||||||
|
setup() {
|
||||||
|
export PYENV_ROOT="${TMP}/pyenv"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "deactivate virtualenv" {
|
||||||
|
PYENV_SHELL="bash" run pyenv-sh-deactivate
|
||||||
|
|
||||||
|
assert_success
|
||||||
|
assert_output <<EOS
|
||||||
|
declare -f deactivate 1>/dev/null 2>&1 && deactivate
|
||||||
|
pyenv shell --unset
|
||||||
|
EOS
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "deactivate virtualenv (fish)" {
|
||||||
|
PYENV_SHELL="fish" run pyenv-sh-deactivate
|
||||||
|
|
||||||
|
assert_success
|
||||||
|
assert_output <<EOS
|
||||||
|
functions -q deactivate; and deactivate
|
||||||
|
pyenv shell --unset
|
||||||
|
EOS
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user