Bladeren bron

Merge pull request #124 from yyuu/deactivation-before-activation-should-not-return-non-zero

Deactivation before activation should not return as non-zero
pull/125/head
Yamashita, Yuu 8 jaren geleden
bovenliggende
commit
353062df09
3 gewijzigde bestanden met toevoegingen van 65 en 39 verwijderingen
  1. +1
    -1
      bin/pyenv-sh-activate
  2. +31
    -15
      test/activate.bats
  3. +33
    -23
      test/conda-activate.bats

+ 1
- 1
bin/pyenv-sh-activate Bestand weergeven

@ -128,7 +128,7 @@ if [ -z "$PYENV_VIRTUALENV_INIT" ]; then
fi
fi
pyenv-sh-deactivate --quiet ${VERBOSE+--verbose} || true
pyenv-sh-deactivate --force --quiet ${VERBOSE+--verbose} || true
echo "pyenv-virtualenv: activate ${venv}" 1>&2

+ 31
- 15
test/activate.bats Bestand weergeven

@ -23,16 +23,18 @@ setup() {
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\""
stub pyenv-sh-deactivate "--force --quiet : echo deactivated"
PYENV_SHELL="bash" PYENV_VERSION="venv" run pyenv-sh-activate
unstub pyenv-version-name
unstub pyenv-virtualenv-prefix
unstub pyenv-prefix
stub pyenv-sh-deactivate
assert_success
assert_output <<EOS
false
deactivated
pyenv-virtualenv: activate venv
export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv";
pyenv-virtualenv: prompt changing will be removed from future release. configure \`export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
@ -47,16 +49,18 @@ EOS
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\""
stub pyenv-sh-deactivate "--force --quiet --verbose : echo deactivated"
PYENV_SHELL="bash" PYENV_VERSION="venv" run pyenv-sh-activate --verbose
unstub pyenv-version-name
unstub pyenv-virtualenv-prefix
unstub pyenv-prefix
unstub pyenv-sh-deactivate
assert_success
assert_output <<EOS
false
deactivated
pyenv-virtualenv: activate venv
export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv";
pyenv-virtualenv: prompt changing will be removed from future release. configure \`export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
@ -71,12 +75,14 @@ EOS
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\""
stub pyenv-sh-deactivate "--force --quiet : echo deactivated"
PYENV_SHELL="bash" PYENV_VERSION="venv" run pyenv-sh-activate
unstub pyenv-version-name
unstub pyenv-virtualenv-prefix
unstub pyenv-prefix
unstub pyenv-sh-deactivate
assert_success
assert_output <<EOS
@ -85,7 +91,7 @@ EOS
eval "\$(pyenv virtualenv-init -)"
false
deactivated
pyenv-virtualenv: activate venv
export PYENV_VERSION="venv";
export PYENV_ACTIVATE_SHELL=1;
@ -102,16 +108,18 @@ EOS
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\""
stub pyenv-sh-deactivate "--force --quiet : echo deactivated"
PYENV_SHELL="fish" PYENV_VERSION="venv" run pyenv-sh-activate
unstub pyenv-version-name
unstub pyenv-virtualenv-prefix
unstub pyenv-prefix
unstub pyenv-sh-deactivate
assert_success
assert_output <<EOS
false
deactivated
pyenv-virtualenv: activate venv
setenv VIRTUAL_ENV "${PYENV_ROOT}/versions/venv";
pyenv-virtualenv: prompt changing not work for fish.
@ -124,12 +132,14 @@ EOS
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\""
stub pyenv-sh-deactivate "--force --quiet : echo deactivated"
PYENV_SHELL="fish" PYENV_VERSION="venv" run pyenv-sh-activate
unstub pyenv-version-name
unstub pyenv-virtualenv-prefix
unstub pyenv-prefix
unstub pyenv-sh-deactivate
assert_success
assert_output <<EOS
@ -138,7 +148,7 @@ EOS
status --is-interactive; and . (pyenv virtualenv-init -|psub)
false
deactivated
pyenv-virtualenv: activate venv
setenv PYENV_VERSION "venv";
setenv PYENV_ACTIVATE_SHELL 1;
@ -152,15 +162,17 @@ EOS
stub pyenv-virtualenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
stub pyenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
stub pyenv-sh-deactivate "--force --quiet : echo deactivated"
PYENV_SHELL="bash" PYENV_VERSION="venv" run pyenv-sh-activate "venv27"
unstub pyenv-virtualenv-prefix
unstub pyenv-prefix
unstub pyenv-sh-deactivate
assert_success
assert_output <<EOS
false
deactivated
pyenv-virtualenv: activate venv27
export PYENV_VERSION="venv27";
export PYENV_ACTIVATE_SHELL=1;
@ -176,11 +188,13 @@ EOS
stub pyenv-virtualenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
stub pyenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
stub pyenv-sh-deactivate "--force --quiet : echo deactivated"
PYENV_SHELL="bash" PYENV_VERSION="venv" run pyenv-sh-activate "venv27"
unstub pyenv-virtualenv-prefix
unstub pyenv-prefix
unstub pyenv-sh-deactivate
assert_success
assert_output <<EOS
@ -189,7 +203,7 @@ EOS
eval "\$(pyenv virtualenv-init -)"
false
deactivated
pyenv-virtualenv: activate venv27
export PYENV_VERSION="venv27";
export PYENV_ACTIVATE_SHELL=1;
@ -205,15 +219,17 @@ EOS
stub pyenv-virtualenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
stub pyenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
stub pyenv-sh-deactivate "--force --quiet : echo deactivated"
PYENV_SHELL="fish" PYENV_VERSION="venv" run pyenv-sh-activate "venv27"
unstub pyenv-virtualenv-prefix
unstub pyenv-prefix
unstub pyenv-sh-deactivate
assert_success
assert_output <<EOS
false
deactivated
pyenv-virtualenv: activate venv27
setenv PYENV_VERSION "venv27";
setenv PYENV_ACTIVATE_SHELL 1;
@ -227,11 +243,13 @@ EOS
stub pyenv-virtualenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
stub pyenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
stub pyenv-sh-deactivate "--force --quiet : echo deactivated"
PYENV_SHELL="fish" PYENV_VERSION="venv" run pyenv-sh-activate "venv27"
unstub pyenv-virtualenv-prefix
unstub pyenv-prefix
unstub pyenv-sh-deactivate
assert_success
assert_output <<EOS
@ -240,7 +258,7 @@ EOS
status --is-interactive; and . (pyenv virtualenv-init -|psub)
false
deactivated
pyenv-virtualenv: activate venv27
setenv PYENV_VERSION "venv27";
setenv PYENV_ACTIVATE_SHELL 1;
@ -253,7 +271,7 @@ EOS
export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv"
export PYENV_ACTIVATE_SHELL=
stub pyenv-sh-deactivate "echo deactivated"
stub pyenv-sh-deactivate " : echo deactivated"
run pyenv-sh-activate --unset
@ -270,8 +288,6 @@ EOS
run pyenv-sh-activate "3.3.3"
unstub pyenv-virtualenv-prefix
assert_failure
assert_output <<EOS
pyenv-virtualenv: version \`3.3.3' is not a virtualenv
@ -328,8 +344,6 @@ EOS
run pyenv-sh-activate "2.7.10" "venv27"
unstub pyenv-virtualenv-prefix
assert_failure
assert_output <<EOS
pyenv-virtualenv: version \`2.7.10' is not a virtualenv
@ -340,18 +354,20 @@ EOS
@test "activate if the first virtualenv is a virtualenv" {
export PYENV_VIRTUALENV_INIT=1
stub pyenv-sh-deactivate "--force --quiet : echo deactivated"
stub pyenv-virtualenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
stub pyenv-virtualenv-prefix "2.7.10 : false"
stub pyenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
run pyenv-sh-activate "venv27" "2.7.10"
unstub pyenv-sh-deactivate
unstub pyenv-virtualenv-prefix
unstub pyenv-prefix
assert_success
assert_output <<EOS
false
deactivated
pyenv-virtualenv: activate venv27
export PYENV_VERSION="venv27:2.7.10";
export PYENV_ACTIVATE_SHELL=1;

+ 33
- 23
test/conda-activate.bats Bestand weergeven

@ -24,16 +24,13 @@ setup() {
stub pyenv-version-name "echo anaconda-2.3.0"
stub pyenv-virtualenv-prefix "anaconda-2.3.0 : echo \"${PYENV_ROOT}/versions/anaconda-2.3.0\""
stub pyenv-prefix "anaconda-2.3.0 : echo \"${PYENV_ROOT}/versions/anaconda-2.3.0\""
stub pyenv-sh-deactivate "--force --quiet : echo deactivated"
PYENV_SHELL="bash" PYENV_VERSION="anaconda-2.3.0" run pyenv-sh-activate
unstub pyenv-version-name
unstub pyenv-virtualenv-prefix
unstub pyenv-prefix
assert_success
assert_output <<EOS
false
deactivated
pyenv-virtualenv: activate anaconda-2.3.0
export VIRTUAL_ENV="${PYENV_ROOT}/versions/anaconda-2.3.0";
export CONDA_DEFAULT_ENV="root";
@ -41,6 +38,11 @@ pyenv-virtualenv: prompt changing will be removed from future release. configure
export _OLD_VIRTUAL_PS1="\${PS1}";
export PS1="(anaconda-2.3.0) \${PS1}";
EOS
unstub pyenv-version-name
unstub pyenv-virtualenv-prefix
unstub pyenv-prefix
unstub pyenv-sh-deactivate
}
@test "activate conda root from current version (fish)" {
@ -50,21 +52,23 @@ EOS
stub pyenv-version-name "echo anaconda-2.3.0"
stub pyenv-virtualenv-prefix "anaconda-2.3.0 : echo \"${PYENV_ROOT}/versions/anaconda-2.3.0\""
stub pyenv-prefix "anaconda-2.3.0 : echo \"${PYENV_ROOT}/versions/anaconda-2.3.0\""
stub pyenv-sh-deactivate "--force --quiet : echo deactivated"
PYENV_SHELL="fish" PYENV_VERSION="anaconda-2.3.0" run pyenv-sh-activate
unstub pyenv-version-name
unstub pyenv-virtualenv-prefix
unstub pyenv-prefix
assert_success
assert_output <<EOS
false
deactivated
pyenv-virtualenv: activate anaconda-2.3.0
setenv VIRTUAL_ENV "${TMP}/pyenv/versions/anaconda-2.3.0";
setenv CONDA_DEFAULT_ENV "root";
pyenv-virtualenv: prompt changing not work for fish.
EOS
unstub pyenv-version-name
unstub pyenv-virtualenv-prefix
unstub pyenv-prefix
unstub pyenv-sh-deactivate
}
@test "activate conda root from command-line argument" {
@ -74,15 +78,13 @@ EOS
create_conda "miniconda-3.9.1"
stub pyenv-virtualenv-prefix "miniconda-3.9.1 : echo \"${PYENV_ROOT}/versions/miniconda-3.9.1\""
stub pyenv-prefix "miniconda-3.9.1 : echo \"${PYENV_ROOT}/versions/miniconda-3.9.1\""
stub pyenv-sh-deactivate "--force --quiet : echo deactivated"
PYENV_SHELL="bash" PYENV_VERSION="anaconda-2.3.0" run pyenv-sh-activate "miniconda-3.9.1"
unstub pyenv-virtualenv-prefix
unstub pyenv-prefix
assert_success
assert_output <<EOS
false
deactivated
pyenv-virtualenv: activate miniconda-3.9.1
export PYENV_VERSION="miniconda-3.9.1";
export PYENV_ACTIVATE_SHELL=1;
@ -92,6 +94,10 @@ pyenv-virtualenv: prompt changing will be removed from future release. configure
export _OLD_VIRTUAL_PS1="\${PS1}";
export PS1="(miniconda-3.9.1) \${PS1}";
EOS
unstub pyenv-virtualenv-prefix
unstub pyenv-prefix
unstub pyenv-sh-deactivate
}
@test "activate conda env from current version" {
@ -101,16 +107,13 @@ EOS
stub pyenv-version-name "echo anaconda-2.3.0/envs/foo"
stub pyenv-virtualenv-prefix "anaconda-2.3.0/envs/foo : echo \"${PYENV_ROOT}/versions/anaconda-2.3.0/envs/foo\""
stub pyenv-prefix "anaconda-2.3.0/envs/foo : echo \"${PYENV_ROOT}/versions/anaconda-2.3.0/envs/foo\""
stub pyenv-sh-deactivate "--force --quiet : echo deactivated"
PYENV_SHELL="bash" PYENV_VERSION="anaconda-2.3.0/envs/foo" run pyenv-sh-activate
unstub pyenv-version-name
unstub pyenv-virtualenv-prefix
unstub pyenv-prefix
assert_success
assert_output <<EOS
false
deactivated
pyenv-virtualenv: activate anaconda-2.3.0/envs/foo
export VIRTUAL_ENV="${PYENV_ROOT}/versions/anaconda-2.3.0/envs/foo";
export CONDA_DEFAULT_ENV="foo";
@ -118,6 +121,11 @@ pyenv-virtualenv: prompt changing will be removed from future release. configure
export _OLD_VIRTUAL_PS1="\${PS1}";
export PS1="(anaconda-2.3.0/envs/foo) \${PS1}";
EOS
unstub pyenv-version-name
unstub pyenv-virtualenv-prefix
unstub pyenv-prefix
unstub pyenv-sh-deactivate
}
@test "activate conda env from command-line argument" {
@ -127,15 +135,13 @@ EOS
create_conda "miniconda-3.9.1" "bar"
stub pyenv-virtualenv-prefix "miniconda-3.9.1/envs/bar : echo \"${PYENV_ROOT}/versions/miniconda-3.9.1\""
stub pyenv-prefix "miniconda-3.9.1/envs/bar : echo \"${PYENV_ROOT}/versions/miniconda-3.9.1/envs/bar\""
stub pyenv-sh-deactivate "--force --quiet : echo deactivated"
PYENV_SHELL="bash" PYENV_VERSION="anaconda-2.3.0/envs/foo" run pyenv-sh-activate "miniconda-3.9.1/envs/bar"
unstub pyenv-virtualenv-prefix
unstub pyenv-prefix
assert_success
assert_output <<EOS
false
deactivated
pyenv-virtualenv: activate miniconda-3.9.1/envs/bar
export PYENV_VERSION="miniconda-3.9.1/envs/bar";
export PYENV_ACTIVATE_SHELL=1;
@ -145,4 +151,8 @@ pyenv-virtualenv: prompt changing will be removed from future release. configure
export _OLD_VIRTUAL_PS1="\${PS1}";
export PS1="(miniconda-3.9.1/envs/bar) \${PS1}";
EOS
unstub pyenv-virtualenv-prefix
unstub pyenv-prefix
unstub pyenv-sh-deactivate
}

Laden…
Annuleren
Opslaan