From d0685addc1d96ba91bcf9f7f2f11cf51cb2ec464 Mon Sep 17 00:00:00 2001 From: Yamashita Yuu Date: Tue, 21 Jan 2014 00:37:33 +0900 Subject: [PATCH] Add tests for activate and deactivate --- bin/pyenv-sh-activate | 10 ++--- test/activate.bats | 87 +++++++++++++++++++++++++++++++++++++++++++ test/deactivate.bats | 27 ++++++++++++++ 3 files changed, 119 insertions(+), 5 deletions(-) create mode 100644 test/activate.bats create mode 100644 test/deactivate.bats diff --git a/bin/pyenv-sh-activate b/bin/pyenv-sh-activate index 33f2352..1fca8e6 100755 --- a/bin/pyenv-sh-activate +++ b/bin/pyenv-sh-activate @@ -20,6 +20,11 @@ if [ "$1" = "--complete" ]; then exec pyenv-virtualenvs --bare fi +if [ "$1" = "--unset" ]; then + echo "pyenv deactivate" + exit +fi + versions=("$@") shell="$(basename "${PYENV_SHELL:-$SHELL}")" @@ -29,11 +34,6 @@ if [ -z "$versions" ]; then IFS="$OLDIFS" fi -if [ "$1" = "--unset" ]; then - echo "pyenv deactivate" - exit -fi - if [ "${#versions[@]}" -gt 1 ]; then echo "pyenv-virtualenv: cannot activate multiple versions at once: ${versions[@]}" 1>&2 exit 1 diff --git a/test/activate.bats b/test/activate.bats new file mode 100644 index 0000000..ecbdeb6 --- /dev/null +++ b/test/activate.bats @@ -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 </dev/null 2>&1 && deactivate +pyenv shell --unset +EOS +} + +@test "deactivate virtualenv (fish)" { + PYENV_SHELL="fish" run pyenv-sh-deactivate + + assert_success + assert_output <