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.

103 lines
2.4 KiB

  1. #!/usr/bin/env bats
  2. load test_helper
  3. setup() {
  4. mkdir -p "${PYENV_TEST_DIR}/myproject"
  5. cd "${PYENV_TEST_DIR}/myproject"
  6. }
  7. @test "no version" {
  8. assert [ ! -e "${PWD}/.python-version" ]
  9. run pyenv-local
  10. assert_failure "pyenv: no local version configured for this directory"
  11. }
  12. @test "local version" {
  13. echo "1.2.3" > .python-version
  14. run pyenv-local
  15. assert_success "1.2.3"
  16. }
  17. @test "supports legacy .pyenv-version file" {
  18. echo "1.2.3" > .pyenv-version
  19. run pyenv-local
  20. assert_success "1.2.3"
  21. }
  22. @test "local .python-version has precedence over .pyenv-version" {
  23. echo "2.7" > .pyenv-version
  24. echo "3.4" > .python-version
  25. run pyenv-local
  26. assert_success "3.4"
  27. }
  28. @test "ignores version in parent directory" {
  29. echo "1.2.3" > .python-version
  30. mkdir -p "subdir" && cd "subdir"
  31. run pyenv-local
  32. assert_failure
  33. }
  34. @test "ignores PYENV_DIR" {
  35. echo "1.2.3" > .python-version
  36. mkdir -p "$HOME"
  37. echo "3.4-home" > "${HOME}/.python-version"
  38. PYENV_DIR="$HOME" run pyenv-local
  39. assert_success "1.2.3"
  40. }
  41. @test "sets local version" {
  42. mkdir -p "${PYENV_ROOT}/versions/1.2.3"
  43. run pyenv-local 1.2.3
  44. assert_success ""
  45. assert [ "$(cat .python-version)" = "1.2.3" ]
  46. }
  47. @test "changes local version" {
  48. echo "1.0-pre" > .python-version
  49. mkdir -p "${PYENV_ROOT}/versions/1.2.3"
  50. run pyenv-local
  51. assert_success "1.0-pre"
  52. run pyenv-local 1.2.3
  53. assert_success ""
  54. assert [ "$(cat .python-version)" = "1.2.3" ]
  55. }
  56. @test "renames .pyenv-version to .python-version" {
  57. echo "2.7.6" > .pyenv-version
  58. mkdir -p "${PYENV_ROOT}/versions/3.3.3"
  59. run pyenv-local
  60. assert_success "2.7.6"
  61. run pyenv-local "3.3.3"
  62. assert_success
  63. assert_output <<OUT
  64. pyenv: removed existing \`.pyenv-version' file and migrated
  65. local version specification to \`.python-version' file
  66. OUT
  67. assert [ ! -e .pyenv-version ]
  68. assert [ "$(cat .python-version)" = "3.3.3" ]
  69. }
  70. @test "doesn't rename .pyenv-version if changing the version failed" {
  71. echo "2.7.6" > .pyenv-version
  72. assert [ ! -e "${PYENV_ROOT}/versions/3.3.3" ]
  73. run pyenv-local "3.3.3"
  74. assert_failure "pyenv: version \`3.3.3' not installed"
  75. assert [ ! -e .python-version ]
  76. assert [ "$(cat .pyenv-version)" = "2.7.6" ]
  77. }
  78. @test "unsets local version" {
  79. touch .python-version
  80. run pyenv-local --unset
  81. assert_success ""
  82. assert [ ! -e .pyenv-version ]
  83. }
  84. @test "unsets alternate version file" {
  85. touch .pyenv-version
  86. run pyenv-local --unset
  87. assert_success ""
  88. assert [ ! -e .pyenv-version ]
  89. }