您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

156 行
2.9 KiB

  1. #!/usr/bin/env bats
  2. load test_helper
  3. create_version() {
  4. mkdir -p "${PYENV_ROOT}/versions/$1"
  5. }
  6. setup() {
  7. mkdir -p "$PYENV_TEST_DIR"
  8. cd "$PYENV_TEST_DIR"
  9. }
  10. stub_system_python() {
  11. local stub="${PYENV_TEST_DIR}/bin/python"
  12. mkdir -p "$(dirname "$stub")"
  13. touch "$stub" && chmod +x "$stub"
  14. }
  15. @test "no versions installed" {
  16. stub_system_python
  17. assert [ ! -d "${PYENV_ROOT}/versions" ]
  18. run pyenv-versions
  19. assert_success "* system (set by ${PYENV_ROOT}/version)"
  20. }
  21. @test "not even system python available" {
  22. PATH="$(path_without python)" run pyenv-versions
  23. assert_failure
  24. assert_output "Warning: no Python detected on the system"
  25. }
  26. @test "bare output no versions installed" {
  27. assert [ ! -d "${PYENV_ROOT}/versions" ]
  28. run pyenv-versions --bare
  29. assert_success ""
  30. }
  31. @test "single version installed" {
  32. stub_system_python
  33. create_version "3.3"
  34. run pyenv-versions
  35. assert_success
  36. assert_output <<OUT
  37. * system (set by ${PYENV_ROOT}/version)
  38. 3.3
  39. OUT
  40. }
  41. @test "single version bare" {
  42. create_version "3.3"
  43. run pyenv-versions --bare
  44. assert_success "3.3"
  45. }
  46. @test "multiple versions" {
  47. stub_system_python
  48. create_version "2.7.6"
  49. create_version "3.3.3"
  50. create_version "3.4.0"
  51. run pyenv-versions
  52. assert_success
  53. assert_output <<OUT
  54. * system (set by ${PYENV_ROOT}/version)
  55. 2.7.6
  56. 3.3.3
  57. 3.4.0
  58. OUT
  59. }
  60. @test "indicates current version" {
  61. stub_system_python
  62. create_version "3.3.3"
  63. create_version "3.4.0"
  64. PYENV_VERSION=3.3.3 run pyenv-versions
  65. assert_success
  66. assert_output <<OUT
  67. system
  68. * 3.3.3 (set by PYENV_VERSION environment variable)
  69. 3.4.0
  70. OUT
  71. }
  72. @test "bare doesn't indicate current version" {
  73. create_version "3.3.3"
  74. create_version "3.4.0"
  75. PYENV_VERSION=3.3.3 run pyenv-versions --bare
  76. assert_success
  77. assert_output <<OUT
  78. 3.3.3
  79. 3.4.0
  80. OUT
  81. }
  82. @test "globally selected version" {
  83. stub_system_python
  84. create_version "3.3.3"
  85. create_version "3.4.0"
  86. cat > "${PYENV_ROOT}/version" <<<"3.3.3"
  87. run pyenv-versions
  88. assert_success
  89. assert_output <<OUT
  90. system
  91. * 3.3.3 (set by ${PYENV_ROOT}/version)
  92. 3.4.0
  93. OUT
  94. }
  95. @test "per-project version" {
  96. stub_system_python
  97. create_version "3.3.3"
  98. create_version "3.4.0"
  99. cat > ".python-version" <<<"3.3.3"
  100. run pyenv-versions
  101. assert_success
  102. assert_output <<OUT
  103. system
  104. * 3.3.3 (set by ${PYENV_TEST_DIR}/.python-version)
  105. 3.4.0
  106. OUT
  107. }
  108. @test "ignores non-directories under versions" {
  109. create_version "3.3"
  110. touch "${PYENV_ROOT}/versions/hello"
  111. run pyenv-versions --bare
  112. assert_success "3.3"
  113. }
  114. @test "lists symlinks under versions" {
  115. create_version "2.7.8"
  116. ln -s "2.7.8" "${PYENV_ROOT}/versions/2.7"
  117. run pyenv-versions --bare
  118. assert_success
  119. assert_output <<OUT
  120. 2.7
  121. 2.7.8
  122. OUT
  123. }
  124. @test "doesn't list symlink aliases when --skip-aliases" {
  125. create_version "1.8.7"
  126. ln -s "1.8.7" "${PYENV_ROOT}/versions/1.8"
  127. mkdir moo
  128. ln -s "${PWD}/moo" "${PYENV_ROOT}/versions/1.9"
  129. run pyenv-versions --bare --skip-aliases
  130. assert_success
  131. assert_output <<OUT
  132. 1.8.7
  133. 1.9
  134. OUT
  135. }