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.

246 rivejä
6.4 KiB

  1. #!/usr/bin/env bats
  2. load test_helper
  3. setup() {
  4. export PYENV_ROOT="${TMP}/pyenv"
  5. }
  6. create_version() {
  7. mkdir -p "${PYENV_ROOT}/versions/$1/bin"
  8. touch "${PYENV_ROOT}/versions/$1/bin/python"
  9. chmod +x "${PYENV_ROOT}/versions/$1/bin/python"
  10. }
  11. remove_version() {
  12. rm -fr "${PYENV_ROOT}/versions/$1"
  13. }
  14. create_virtualenv() {
  15. create_version "$1"
  16. create_version "${2:-$1}"
  17. mkdir -p "${PYENV_ROOT}/versions/$1/lib/python${2:-$1}"
  18. echo "${PYENV_ROOT}/versions/${2:-$1}" > "${PYENV_ROOT}/versions/$1/lib/python${2:-$1}/orig-prefix.txt"
  19. touch "${PYENV_ROOT}/versions/$1/bin/activate"
  20. }
  21. create_virtualenv_jython() {
  22. create_version "$1"
  23. create_version "${2:-$1}"
  24. mkdir -p "${PYENV_ROOT}/versions/$1/Lib/"
  25. echo "${PYENV_ROOT}/versions/${2:-$1}" > "${PYENV_ROOT}/versions/$1/Lib/orig-prefix.txt"
  26. touch "${PYENV_ROOT}/versions/$1/bin/activate"
  27. }
  28. create_virtualenv_pypy() {
  29. create_version "$1"
  30. create_version "${2:-$1}"
  31. mkdir -p "${PYENV_ROOT}/versions/$1/lib-python/${2:-$1}"
  32. echo "${PYENV_ROOT}/versions/${2:-$1}" > "${PYENV_ROOT}/versions/$1/lib-python/${2:-$1}/orig-prefix.txt"
  33. touch "${PYENV_ROOT}/versions/$1/bin/activate"
  34. }
  35. remove_virtualenv() {
  36. remove_version "$1"
  37. remove_version "${2:-$1}"
  38. }
  39. create_pyvenv() {
  40. create_version "$1"
  41. create_version "${2:-$1}"
  42. echo "home = ${PYENV_ROOT}/versions/${2:-$1}/bin" > "${PYENV_ROOT}/versions/$1/pyvenv.cfg"
  43. touch "${PYENV_ROOT}/versions/$1/bin/activate"
  44. }
  45. remove_pyvenv() {
  46. remove_version "${2:-$1}"
  47. }
  48. create_conda() {
  49. create_version "$1"
  50. create_version "${2:-$1}"
  51. touch "${PYENV_ROOT}/versions/$1/bin/conda"
  52. touch "${PYENV_ROOT}/versions/$1/bin/activate"
  53. mkdir -p "${PYENV_ROOT}/versions/${2:-$1}/bin"
  54. touch "${PYENV_ROOT}/versions/${2:-$1}/bin/conda"
  55. touch "${PYENV_ROOT}/versions/${2:-$1}/bin/activate"
  56. }
  57. remove_conda() {
  58. remove_version "${2:-$1}"
  59. }
  60. @test "display prefix of virtualenv created by virtualenv" {
  61. stub pyenv-version-name "echo foo"
  62. stub pyenv-prefix "foo : echo \"${PYENV_ROOT}/versions/foo\""
  63. create_virtualenv "foo" "2.7.11"
  64. PYENV_VERSION="foo" run pyenv-virtualenv-prefix
  65. assert_success
  66. assert_output <<OUT
  67. ${PYENV_ROOT}/versions/2.7.11
  68. OUT
  69. unstub pyenv-version-name
  70. unstub pyenv-prefix
  71. remove_virtualenv "foo" "2.7.11"
  72. }
  73. @test "display prefix of virtualenv created by virtualenv (pypy)" {
  74. stub pyenv-version-name "echo foo"
  75. stub pyenv-prefix "foo : echo \"${PYENV_ROOT}/versions/foo\""
  76. create_virtualenv_pypy "foo" "pypy-4.0.1"
  77. PYENV_VERSION="foo" run pyenv-virtualenv-prefix
  78. assert_success
  79. assert_output <<OUT
  80. ${PYENV_ROOT}/versions/pypy-4.0.1
  81. OUT
  82. unstub pyenv-version-name
  83. unstub pyenv-prefix
  84. remove_virtualenv "foo" "pypy-4.0.1"
  85. }
  86. @test "display prefix of virtualenv created by virtualenv (jython)" {
  87. stub pyenv-version-name "echo foo"
  88. stub pyenv-prefix "foo : echo \"${PYENV_ROOT}/versions/foo\""
  89. create_virtualenv_jython "foo" "jython-2.7.0"
  90. PYENV_VERSION="foo" run pyenv-virtualenv-prefix
  91. assert_success
  92. assert_output <<OUT
  93. ${PYENV_ROOT}/versions/jython-2.7.0
  94. OUT
  95. unstub pyenv-version-name
  96. unstub pyenv-prefix
  97. remove_virtualenv "foo" "jython-2.7.0"
  98. }
  99. @test "display prefixes of virtualenv created by virtualenv" {
  100. stub pyenv-version-name "echo foo:bar"
  101. stub pyenv-prefix "foo : echo \"${PYENV_ROOT}/versions/foo\"" \
  102. "bar : echo \"${PYENV_ROOT}/versions/bar\""
  103. create_virtualenv "foo" "2.7.11"
  104. create_virtualenv "bar" "3.5.1"
  105. PYENV_VERSION="foo:bar" run pyenv-virtualenv-prefix
  106. assert_success
  107. assert_output <<OUT
  108. ${PYENV_ROOT}/versions/2.7.11:${PYENV_ROOT}/versions/3.5.1
  109. OUT
  110. unstub pyenv-version-name
  111. unstub pyenv-prefix
  112. remove_virtualenv "foo" "2.7.11"
  113. remove_virtualenv "bar" "3.5.1"
  114. }
  115. @test "display prefix of virtualenv created by pyvenv" {
  116. stub pyenv-version-name "echo foo"
  117. stub pyenv-prefix "foo : echo \"${PYENV_ROOT}/versions/foo\""
  118. create_pyvenv "foo" "3.3.6"
  119. PYENV_VERSION="foo" run pyenv-virtualenv-prefix
  120. assert_success
  121. assert_output <<OUT
  122. ${PYENV_ROOT}/versions/3.3.6
  123. OUT
  124. unstub pyenv-version-name
  125. unstub pyenv-prefix
  126. remove_pyvenv "foo" "3.3.6"
  127. }
  128. @test "display prefixes of virtualenv created by pyvenv" {
  129. stub pyenv-version-name "echo foo:bar"
  130. stub pyenv-prefix "foo : echo \"${PYENV_ROOT}/versions/foo\"" \
  131. "bar : echo \"${PYENV_ROOT}/versions/bar\""
  132. create_pyvenv "foo" "3.3.6"
  133. create_pyvenv "bar" "3.4.4"
  134. PYENV_VERSION="foo:bar" run pyenv-virtualenv-prefix
  135. assert_success
  136. assert_output <<OUT
  137. ${PYENV_ROOT}/versions/3.3.6:${PYENV_ROOT}/versions/3.4.4
  138. OUT
  139. unstub pyenv-version-name
  140. unstub pyenv-prefix
  141. remove_pyvenv "foo" "3.3.6"
  142. remove_pyvenv "bar" "3.4.4"
  143. }
  144. @test "display prefix of virtualenv created by conda" {
  145. stub pyenv-version-name "echo miniconda3-3.16.0/envs/foo"
  146. stub pyenv-prefix "miniconda3-3.16.0/envs/foo : echo \"${PYENV_ROOT}/versions/miniconda3-3.16.0/envs/foo\""
  147. create_conda "miniconda3-3.16.0/envs/foo" "miniconda3-3.16.0"
  148. PYENV_VERSION="miniconda3-3.16.0/envs/foo" run pyenv-virtualenv-prefix
  149. assert_success
  150. assert_output <<OUT
  151. ${PYENV_ROOT}/versions/miniconda3-3.16.0/envs/foo
  152. OUT
  153. unstub pyenv-version-name
  154. unstub pyenv-prefix
  155. remove_conda "miniconda3-3.16.0/envs/foo" "miniconda3-3.16.0"
  156. }
  157. @test "should fail if the version is the system" {
  158. stub pyenv-version-name "echo system"
  159. PYENV_VERSION="system" run pyenv-virtualenv-prefix
  160. assert_failure
  161. assert_output <<OUT
  162. pyenv-virtualenv: version \`system' is not a virtualenv
  163. OUT
  164. unstub pyenv-version-name
  165. }
  166. @test "should fail if the version is not a virtualenv" {
  167. stub pyenv-version-name "echo 3.4.4"
  168. stub pyenv-prefix "3.4.4 : echo \"${PYENV_ROOT}/versions/3.4.4\""
  169. create_version "3.4.4"
  170. PYENV_VERSION="3.4.4" run pyenv-virtualenv-prefix
  171. assert_failure
  172. assert_output <<OUT
  173. pyenv-virtualenv: version \`3.4.4' is not a virtualenv
  174. OUT
  175. unstub pyenv-version-name
  176. unstub pyenv-prefix
  177. remove_version "3.4.4"
  178. }
  179. @test "should fail if one of the versions is not a virtualenv" {
  180. stub pyenv-version-name "echo venv33:3.4.4"
  181. stub pyenv-prefix "venv33 : echo \"${PYENV_ROOT}/versions/venv33\"" \
  182. "3.4.4 : echo \"${PYENV_ROOT}/versions/3.4.4\""
  183. create_virtualenv "venv33" "3.3.6"
  184. create_version "3.4.4"
  185. PYENV_VERSION="venv33:3.4.4" run pyenv-virtualenv-prefix
  186. assert_failure
  187. assert_output <<OUT
  188. pyenv-virtualenv: version \`3.4.4' is not a virtualenv
  189. OUT
  190. unstub pyenv-version-name
  191. unstub pyenv-prefix
  192. remove_virtualenv "venv33" "3.3.6"
  193. remove_version "3.4.4"
  194. }