diff --git a/bin/pyenv-virtualenv-prefix b/bin/pyenv-virtualenv-prefix index dad9688..858ff72 100755 --- a/bin/pyenv-virtualenv-prefix +++ b/bin/pyenv-virtualenv-prefix @@ -44,7 +44,7 @@ for version_string in "${versions[@]}"; do if [[ "${version_string}" != "${version_string%/envs/*}" ]]; then conda_env="${version_string##*/envs/}" if [ -f "${PREFIX}/envs/${conda_env}/bin/conda" ]; then - VIRTUALENV_PREFIX_PATHS=("${VIRTUALENV_PREFIX_PATHS[@]}" "${PREFIX}/envs/${conda_env}") + VIRTUALENV_PREFIX_PATHS=("${VIRTUALENV_PREFIX_PATHS[@]}" "${PREFIX}") else echo "pyenv-virtualenv: version \`${version_string}' is not an environment of anaconda/miniconda" 1>&2 exit 1 diff --git a/test/conda-activate.bats b/test/conda-activate.bats new file mode 100644 index 0000000..8d43f31 --- /dev/null +++ b/test/conda-activate.bats @@ -0,0 +1,149 @@ +#!/usr/bin/env bats + +load test_helper + +setup() { + export HOME="${TMP}" + export PYENV_ROOT="${TMP}/pyenv" +} + +@test "activate conda root from current version" { + export PYENV_VIRTUALENV_INIT=1 + + create_conda "anaconda-2.3.0" + 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-prefix "anaconda-2.3.0 : echo \"${PYENV_ROOT}/versions/anaconda-2.3.0\"" + + 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 <&2; + false; +fi; +EOS +} + +@test "deactivate conda root (fish)" { + export PYENV_ACTIVATE="${PYENV_ROOT}/versions/anaconda-2.3.0" + export PYENV_ACTIVATE_SHELL= + + create_conda "anaconda-2.3.0" + + PYENV_SHELL="fish" run pyenv-sh-deactivate + + assert_failure + assert_output <&2; + false; +fi; +EOS +} diff --git a/test/conda-virtualenv-prefix.bats b/test/conda-virtualenv-prefix.bats new file mode 100644 index 0000000..d7a928b --- /dev/null +++ b/test/conda-virtualenv-prefix.bats @@ -0,0 +1,41 @@ +#!/usr/bin/env bats + +load test_helper + +setup() { + export PYENV_ROOT="${TMP}/pyenv" +} + +@test "display conda root" { + create_conda "anaconda-2.3.0" + + stub pyenv-version-name "echo anaconda-2.3.0" + stub pyenv-prefix "anaconda-2.3.0 : echo \"${PYENV_ROOT}/versions/anaconda-2.3.0\"" + + PYENV_VERSION="anaconda-2.3.0" run pyenv-virtualenv-prefix + + unstub pyenv-version-name + unstub pyenv-prefix + + assert_success + assert_output <