From b32d357353f075f419d358addb6652d0d437141b Mon Sep 17 00:00:00 2001 From: "Yamashita, Yuu" Date: Sun, 19 Jul 2015 15:00:59 +0900 Subject: [PATCH] Add tests for conda --- bin/pyenv-virtualenv-prefix | 2 +- test/conda-activate.bats | 149 ++++++++++++++++++++++++++++++ test/conda-deactivate.bats | 64 +++++++++++++ test/conda-virtualenv-prefix.bats | 41 ++++++++ test/test_helper.bash | 16 ++++ 5 files changed, 271 insertions(+), 1 deletion(-) create mode 100644 test/conda-activate.bats create mode 100644 test/conda-deactivate.bats create mode 100644 test/conda-virtualenv-prefix.bats 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 <