You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
2.9 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. #!/usr/bin/env bats
  2. load test_helper
  3. setup() {
  4. export PYENV_ROOT="${TMP}/pyenv"
  5. export HOOK_PATH="${TMP}/i has hooks"
  6. mkdir -p "$HOOK_PATH"
  7. unset PYENV_VIRTUALENV_PROMPT
  8. }
  9. @test "pyenv-virtualenv hooks" {
  10. cat > "${HOOK_PATH}/virtualenv.bash" <<OUT
  11. before_virtualenv 'echo before: \$VIRTUALENV_PATH'
  12. after_virtualenv 'echo after: \$STATUS'
  13. OUT
  14. setup_version "3.5.1"
  15. create_executable "3.5.1" "virtualenv"
  16. stub pyenv-prefix "echo '${PYENV_ROOT}/versions/3.5.1'"
  17. stub pyenv-prefix "echo '${PYENV_ROOT}/versions/3.5.1'"
  18. stub pyenv-exec "python -m venv --help : true"
  19. stub pyenv-hooks "virtualenv : echo '$HOOK_PATH'/virtualenv.bash"
  20. stub pyenv-exec "echo PYENV_VERSION=3.5.1 \"\$@\""
  21. stub pyenv-exec "echo PYENV_VERSION=3.5.1 \"\$@\""
  22. stub pyenv-rehash "echo rehashed"
  23. run pyenv-virtualenv "3.5.1" venv
  24. assert_success
  25. assert_output <<-OUT
  26. before: ${PYENV_ROOT}/versions/3.5.1/envs/venv
  27. PYENV_VERSION=3.5.1 virtualenv ${PYENV_ROOT}/versions/3.5.1/envs/venv
  28. PYENV_VERSION=3.5.1 python -s -m ensurepip
  29. after: 0
  30. rehashed
  31. OUT
  32. unstub pyenv-prefix
  33. unstub pyenv-hooks
  34. unstub pyenv-exec
  35. unstub pyenv-rehash
  36. teardown_version "3.5.1"
  37. }
  38. @test "pyenv-sh-activate hooks" {
  39. cat > "${HOOK_PATH}/activate.bash" <<OUT
  40. before_activate 'echo "before"'
  41. after_activate 'echo "after"'
  42. OUT
  43. export PYENV_VIRTUALENV_INIT=1
  44. stub pyenv-version-name "echo venv"
  45. stub pyenv-virtualenv-prefix ""
  46. stub pyenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
  47. stub pyenv-hooks "activate : echo '$HOOK_PATH'/activate.bash"
  48. stub pyenv-sh-deactivate ""
  49. PYENV_SHELL="bash" PYENV_VERSION="venv" run pyenv-sh-activate
  50. assert_success
  51. assert_output <<EOS
  52. before
  53. export PYENV_VIRTUAL_ENV="${PYENV_ROOT}/versions/venv";
  54. export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv";
  55. export _OLD_VIRTUAL_PS1="\${PS1:-}";
  56. export PS1="(venv) \${PS1:-}";
  57. after
  58. EOS
  59. unstub pyenv-version-name
  60. unstub pyenv-virtualenv-prefix
  61. unstub pyenv-prefix
  62. unstub pyenv-hooks
  63. unstub pyenv-sh-deactivate
  64. }
  65. @test "deactivate virtualenv" {
  66. cat > "${HOOK_PATH}/deactivate.bash" <<OUT
  67. before_deactivate 'echo "before"'
  68. after_deactivate 'echo "after"'
  69. OUT
  70. export PYENV_VIRTUALENV_INIT=1
  71. export PYENV_VIRTUAL_ENV="${PYENV_ROOT}/versions/venv"
  72. export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv"
  73. export PYENV_ACTIVATE_SHELL=
  74. stub pyenv-hooks "deactivate : echo '$HOOK_PATH'/deactivate.bash"
  75. PYENV_SHELL="bash" run pyenv-sh-deactivate
  76. assert_success
  77. assert_output <<EOS
  78. before
  79. unset PYENV_VIRTUAL_ENV;
  80. unset VIRTUAL_ENV;
  81. if [ -n "\${_OLD_VIRTUAL_PATH:-}" ]; then
  82. export PATH="\${_OLD_VIRTUAL_PATH}";
  83. unset _OLD_VIRTUAL_PATH;
  84. fi;
  85. if [ -n "\${_OLD_VIRTUAL_PYTHONHOME:-}" ]; then
  86. export PYTHONHOME="\${_OLD_VIRTUAL_PYTHONHOME}";
  87. unset _OLD_VIRTUAL_PYTHONHOME;
  88. fi;
  89. if [ -n "\${_OLD_VIRTUAL_PS1:-}" ]; then
  90. export PS1="\${_OLD_VIRTUAL_PS1}";
  91. unset _OLD_VIRTUAL_PS1;
  92. fi;
  93. if declare -f deactivate 1>/dev/null 2>&1; then
  94. unset -f deactivate;
  95. fi;
  96. after
  97. EOS
  98. unstub pyenv-hooks
  99. }