Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

115 рядки
2.8 KiB

  1. #!/usr/bin/env bats
  2. load test_helper
  3. create_executable() {
  4. name="${1?}"
  5. shift 1
  6. bin="${PYENV_ROOT}/versions/${PYENV_VERSION}/bin"
  7. mkdir -p "$bin"
  8. { if [ $# -eq 0 ]; then cat -
  9. else echo "$@"
  10. fi
  11. } | sed -Ee '1s/^ +//' > "${bin}/$name"
  12. chmod +x "${bin}/$name"
  13. }
  14. @test "fails with invalid version" {
  15. export PYENV_VERSION="3.4"
  16. run pyenv-exec python -V
  17. assert_failure "pyenv: version \`3.4' is not installed (set by PYENV_VERSION environment variable)"
  18. }
  19. @test "fails with invalid version set from file" {
  20. mkdir -p "$PYENV_TEST_DIR"
  21. cd "$PYENV_TEST_DIR"
  22. echo 2.7 > .python-version
  23. run pyenv-exec rspec
  24. assert_failure "pyenv: version \`2.7' is not installed (set by $PWD/.python-version)"
  25. }
  26. @test "completes with names of executables" {
  27. export PYENV_VERSION="3.4"
  28. create_executable "fab" "#!/bin/sh"
  29. create_executable "python" "#!/bin/sh"
  30. pyenv-rehash
  31. run pyenv-completions exec
  32. assert_success
  33. assert_output <<OUT
  34. --help
  35. fab
  36. python
  37. OUT
  38. }
  39. @test "carries original IFS within hooks" {
  40. create_hook exec hello.bash <<SH
  41. hellos=(\$(printf "hello\\tugly world\\nagain"))
  42. echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
  43. SH
  44. export PYENV_VERSION=system
  45. IFS=$' \t\n' run pyenv-exec env
  46. assert_success
  47. assert_line "HELLO=:hello:ugly:world:again"
  48. }
  49. @test "forwards all arguments" {
  50. export PYENV_VERSION="3.4"
  51. create_executable "python" <<SH
  52. #!$BASH
  53. echo \$0
  54. for arg; do
  55. # hack to avoid bash builtin echo which can't output '-e'
  56. printf " %s\\n" "\$arg"
  57. done
  58. SH
  59. run pyenv-exec python -w "/path to/python script.rb" -- extra args
  60. assert_success
  61. assert_output <<OUT
  62. ${PYENV_ROOT}/versions/3.4/bin/python
  63. -w
  64. /path to/python script.rb
  65. --
  66. extra
  67. args
  68. OUT
  69. }
  70. @test "sys.executable with system version (#98)" {
  71. system_python="$(python3 -c 'import sys; print(sys.executable)')"
  72. PYENV_VERSION="custom"
  73. create_executable "python3" ""
  74. unset PYENV_VERSION
  75. pyenv-rehash
  76. run pyenv-exec python3 -c 'import sys; print(sys.executable)'
  77. assert_success "${system_python}"
  78. }
  79. @test 'PATH is not modified with system Python' {
  80. # Create a wrapper executable that verifies PATH.
  81. PYENV_VERSION="custom"
  82. create_executable "python3" '[[ "$PATH" == "${PYENV_TEST_DIR}/root/versions/custom/bin:"* ]] || { echo "unexpected:$PATH"; exit 2;}'
  83. unset PYENV_VERSION
  84. pyenv-rehash
  85. # Path is not modified with system Python.
  86. run pyenv-exec python3 -c 'import os; print(os.getenv("PATH"))'
  87. assert_success "$PATH"
  88. # Path is modified with custom Python.
  89. PYENV_VERSION=custom run pyenv-exec python3
  90. assert_success
  91. # Path is modified with custom:system Python.
  92. PYENV_VERSION=custom:system run pyenv-exec python3
  93. assert_success
  94. # Path is not modified with system:custom Python.
  95. PYENV_VERSION=system:custom run pyenv-exec python3 -c 'import os; print(os.getenv("PATH"))'
  96. assert_success "$PATH"
  97. }