mirror of
https://github.com/pyenv/pyenv.git
synced 2025-11-15 14:53:53 -05:00
Merge remote-tracking branch 'rbenv/master' into rbenv-1.0
This commit is contained in:
@@ -2,22 +2,13 @@
|
||||
|
||||
load test_helper
|
||||
|
||||
export GIT_DIR="${PYENV_TEST_DIR}/.git"
|
||||
|
||||
setup() {
|
||||
mkdir -p "$HOME"
|
||||
git config --global user.name "Tester"
|
||||
git config --global user.email "tester@test.local"
|
||||
|
||||
mkdir -p "${PYENV_TEST_DIR}/bin"
|
||||
cat > "${PYENV_TEST_DIR}/bin/git" <<CMD
|
||||
#!$BASH
|
||||
if [[ \$1 == remote && \$PWD != "\$PYENV_TEST_DIR"/* ]]; then
|
||||
echo "not allowed" >&2
|
||||
exit 1
|
||||
else
|
||||
exec $(which git) "\$@"
|
||||
fi
|
||||
CMD
|
||||
chmod +x "${PYENV_TEST_DIR}/bin/git"
|
||||
cd "$PYENV_TEST_DIR"
|
||||
}
|
||||
|
||||
git_commit() {
|
||||
@@ -28,47 +19,37 @@ git_commit() {
|
||||
assert [ ! -e "$PYENV_ROOT" ]
|
||||
run pyenv---version
|
||||
assert_success
|
||||
[[ $output == "pyenv 20"* ]]
|
||||
[[ $output == "ybenv "?.?.? ]]
|
||||
}
|
||||
|
||||
@test "doesn't read version from non-pyenv repo" {
|
||||
mkdir -p "$PYENV_ROOT"
|
||||
cd "$PYENV_ROOT"
|
||||
git init
|
||||
git remote add origin https://github.com/homebrew/homebrew.git
|
||||
git_commit
|
||||
git tag v1.0
|
||||
|
||||
cd "$PYENV_TEST_DIR"
|
||||
run pyenv---version
|
||||
assert_success
|
||||
[[ $output == "pyenv 20"* ]]
|
||||
[[ $output == "pyenv "?.?.? ]]
|
||||
}
|
||||
|
||||
@test "reads version from git repo" {
|
||||
mkdir -p "$PYENV_ROOT"
|
||||
cd "$PYENV_ROOT"
|
||||
git init
|
||||
git remote add origin https://github.com/yyuu/pyenv.git
|
||||
git_commit
|
||||
git tag v20380119
|
||||
git tag v0.4.1
|
||||
git_commit
|
||||
git_commit
|
||||
|
||||
cd "$PYENV_TEST_DIR"
|
||||
run pyenv---version
|
||||
assert_success
|
||||
[[ $output == "pyenv 20380119-2-g"* ]]
|
||||
assert_success "pyenv 0.4.1-2-g$(git rev-parse --short HEAD)"
|
||||
}
|
||||
|
||||
@test "prints default version if no tags in git repo" {
|
||||
mkdir -p "$PYENV_ROOT"
|
||||
cd "$PYENV_ROOT"
|
||||
git init
|
||||
git remote add origin https://github.com/yyuu/pyenv.git
|
||||
git_commit
|
||||
|
||||
cd "$PYENV_TEST_DIR"
|
||||
run pyenv---version
|
||||
[[ $output == "pyenv 20"* ]]
|
||||
[[ $output == "pyenv "?.?.? ]]
|
||||
}
|
||||
|
||||
@@ -43,27 +43,14 @@ python
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "supports hook path with spaces" {
|
||||
hook_path="${PYENV_TEST_DIR}/custom stuff/pyenv hooks"
|
||||
mkdir -p "${hook_path}/exec"
|
||||
echo "export HELLO='from hook'" > "${hook_path}/exec/hello.bash"
|
||||
|
||||
export PYENV_VERSION=system
|
||||
PYENV_HOOK_PATH="$hook_path" run pyenv-exec env
|
||||
assert_success
|
||||
assert_line "HELLO=from hook"
|
||||
}
|
||||
|
||||
@test "carries original IFS within hooks" {
|
||||
hook_path="${PYENV_TEST_DIR}/pyenv.d"
|
||||
mkdir -p "${hook_path}/exec"
|
||||
cat > "${hook_path}/exec/hello.bash" <<SH
|
||||
create_hook exec hello.bash <<SH
|
||||
hellos=(\$(printf "hello\\tugly world\\nagain"))
|
||||
echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
|
||||
SH
|
||||
|
||||
export PYENV_VERSION=system
|
||||
PYENV_HOOK_PATH="$hook_path" IFS=$' \t\n' run pyenv-exec env
|
||||
IFS=$' \t\n' run pyenv-exec env
|
||||
assert_success
|
||||
assert_line "HELLO=:hello:ugly:world:again"
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
load test_helper
|
||||
|
||||
@test "default" {
|
||||
run pyenv global
|
||||
run pyenv-global
|
||||
assert_success
|
||||
assert_output "system"
|
||||
}
|
||||
@@ -20,7 +20,7 @@ load test_helper
|
||||
mkdir -p "$PYENV_ROOT/versions/1.2.3"
|
||||
run pyenv-global "1.2.3"
|
||||
assert_success
|
||||
run pyenv global
|
||||
run pyenv-global
|
||||
assert_success "1.2.3"
|
||||
}
|
||||
|
||||
|
||||
@@ -2,11 +2,6 @@
|
||||
|
||||
load test_helper
|
||||
|
||||
create_hook() {
|
||||
mkdir -p "$1/$2"
|
||||
touch "$1/$2/$3"
|
||||
}
|
||||
|
||||
@test "prints usage help given no argument" {
|
||||
run pyenv-hooks
|
||||
assert_failure "Usage: pyenv hooks <command>"
|
||||
@@ -15,11 +10,13 @@ create_hook() {
|
||||
@test "prints list of hooks" {
|
||||
path1="${PYENV_TEST_DIR}/pyenv.d"
|
||||
path2="${PYENV_TEST_DIR}/etc/pyenv_hooks"
|
||||
create_hook "$path1" exec "hello.bash"
|
||||
create_hook "$path1" exec "ahoy.bash"
|
||||
create_hook "$path1" exec "invalid.sh"
|
||||
create_hook "$path1" which "boom.bash"
|
||||
create_hook "$path2" exec "bueno.bash"
|
||||
PYENV_HOOK_PATH="$path1"
|
||||
create_hook exec "hello.bash"
|
||||
create_hook exec "ahoy.bash"
|
||||
create_hook exec "invalid.sh"
|
||||
create_hook which "boom.bash"
|
||||
PYENV_HOOK_PATH="$path2"
|
||||
create_hook exec "bueno.bash"
|
||||
|
||||
PYENV_HOOK_PATH="$path1:$path2" run pyenv-hooks exec
|
||||
assert_success
|
||||
@@ -33,8 +30,10 @@ OUT
|
||||
@test "supports hook paths with spaces" {
|
||||
path1="${PYENV_TEST_DIR}/my hooks/pyenv.d"
|
||||
path2="${PYENV_TEST_DIR}/etc/pyenv hooks"
|
||||
create_hook "$path1" exec "hello.bash"
|
||||
create_hook "$path2" exec "ahoy.bash"
|
||||
PYENV_HOOK_PATH="$path1"
|
||||
create_hook exec "hello.bash"
|
||||
PYENV_HOOK_PATH="$path2"
|
||||
create_hook exec "ahoy.bash"
|
||||
|
||||
PYENV_HOOK_PATH="$path1:$path2" run pyenv-hooks exec
|
||||
assert_success
|
||||
@@ -45,8 +44,8 @@ OUT
|
||||
}
|
||||
|
||||
@test "resolves relative paths" {
|
||||
path="${PYENV_TEST_DIR}/pyenv.d"
|
||||
create_hook "$path" exec "hello.bash"
|
||||
PYENV_HOOK_PATH="${PYENV_TEST_DIR}/pyenv.d"
|
||||
create_hook exec "hello.bash"
|
||||
mkdir -p "$HOME"
|
||||
|
||||
PYENV_HOOK_PATH="${HOME}/../pyenv.d" run pyenv-hooks exec
|
||||
|
||||
@@ -25,12 +25,24 @@ load test_helper
|
||||
}
|
||||
|
||||
@test "detect parent shell" {
|
||||
root="$(cd $BATS_TEST_DIRNAME/.. && pwd)"
|
||||
SHELL=/bin/false run pyenv-init -
|
||||
assert_success
|
||||
assert_line "export PYENV_SHELL=bash"
|
||||
}
|
||||
|
||||
@test "detect parent shell from script" {
|
||||
mkdir -p "$PYENV_TEST_DIR"
|
||||
cd "$PYENV_TEST_DIR"
|
||||
cat > myscript.sh <<OUT
|
||||
#!/bin/sh
|
||||
eval "\$(pyenv-init -)"
|
||||
echo \$PYENV_SHELL
|
||||
OUT
|
||||
chmod +x myscript.sh
|
||||
run ./myscript.sh /bin/zsh
|
||||
assert_success "sh"
|
||||
}
|
||||
|
||||
@test "setup shell completions (fish)" {
|
||||
root="$(cd $BATS_TEST_DIRNAME/.. && pwd)"
|
||||
run pyenv-init - fish
|
||||
|
||||
@@ -19,24 +19,11 @@ setup() {
|
||||
assert_success "1.2.3"
|
||||
}
|
||||
|
||||
@test "supports legacy .pyenv-version file" {
|
||||
echo "1.2.3" > .pyenv-version
|
||||
run pyenv-local
|
||||
assert_success "1.2.3"
|
||||
}
|
||||
|
||||
@test "local .python-version has precedence over .pyenv-version" {
|
||||
echo "2.7" > .pyenv-version
|
||||
echo "3.4" > .python-version
|
||||
run pyenv-local
|
||||
assert_success "3.4"
|
||||
}
|
||||
|
||||
@test "ignores version in parent directory" {
|
||||
@test "discovers version file in parent directory" {
|
||||
echo "1.2.3" > .python-version
|
||||
mkdir -p "subdir" && cd "subdir"
|
||||
run pyenv-local
|
||||
assert_failure
|
||||
assert_success "1.2.3"
|
||||
}
|
||||
|
||||
@test "ignores PYENV_DIR" {
|
||||
@@ -64,40 +51,9 @@ setup() {
|
||||
assert [ "$(cat .python-version)" = "1.2.3" ]
|
||||
}
|
||||
|
||||
@test "renames .pyenv-version to .python-version" {
|
||||
echo "2.7.6" > .pyenv-version
|
||||
mkdir -p "${PYENV_ROOT}/versions/3.3.3"
|
||||
run pyenv-local
|
||||
assert_success "2.7.6"
|
||||
run pyenv-local "3.3.3"
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
pyenv: removed existing \`.pyenv-version' file and migrated
|
||||
local version specification to \`.python-version' file
|
||||
OUT
|
||||
assert [ ! -e .pyenv-version ]
|
||||
assert [ "$(cat .python-version)" = "3.3.3" ]
|
||||
}
|
||||
|
||||
@test "doesn't rename .pyenv-version if changing the version failed" {
|
||||
echo "2.7.6" > .pyenv-version
|
||||
assert [ ! -e "${PYENV_ROOT}/versions/3.3.3" ]
|
||||
run pyenv-local "3.3.3"
|
||||
assert_failure "pyenv: version \`3.3.3' not installed"
|
||||
assert [ ! -e .python-version ]
|
||||
assert [ "$(cat .pyenv-version)" = "2.7.6" ]
|
||||
}
|
||||
|
||||
@test "unsets local version" {
|
||||
touch .python-version
|
||||
run pyenv-local --unset
|
||||
assert_success ""
|
||||
assert [ ! -e .pyenv-version ]
|
||||
}
|
||||
|
||||
@test "unsets alternate version file" {
|
||||
touch .pyenv-version
|
||||
run pyenv-local --unset
|
||||
assert_success ""
|
||||
assert [ ! -e .pyenv-version ]
|
||||
assert [ ! -e .python-version ]
|
||||
}
|
||||
|
||||
@@ -70,6 +70,7 @@ load test_helper
|
||||
}
|
||||
|
||||
@test "PYENV_HOOK_PATH includes pyenv built-in plugins" {
|
||||
unset PYENV_HOOK_PATH
|
||||
run pyenv echo "PYENV_HOOK_PATH"
|
||||
assert_success ":${PYENV_ROOT}/pyenv.d:${BATS_TEST_DIRNAME%/*}/pyenv.d:/usr/local/etc/pyenv.d:/etc/pyenv.d:/usr/lib/pyenv/hooks"
|
||||
assert_success "${PYENV_ROOT}/pyenv.d:${BATS_TEST_DIRNAME%/*}/pyenv.d:/usr/local/etc/pyenv.d:/etc/pyenv.d:/usr/lib/pyenv/hooks"
|
||||
}
|
||||
|
||||
@@ -86,15 +86,13 @@ OUT
|
||||
}
|
||||
|
||||
@test "carries original IFS within hooks" {
|
||||
hook_path="${PYENV_TEST_DIR}/pyenv.d"
|
||||
mkdir -p "${hook_path}/rehash"
|
||||
cat > "${hook_path}/rehash/hello.bash" <<SH
|
||||
create_hook rehash hello.bash <<SH
|
||||
hellos=(\$(printf "hello\\tugly world\\nagain"))
|
||||
echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
|
||||
exit
|
||||
SH
|
||||
|
||||
PYENV_HOOK_PATH="$hook_path" IFS=$' \t\n' run pyenv-rehash
|
||||
IFS=$' \t\n' run pyenv-rehash
|
||||
assert_success
|
||||
assert_output "HELLO=:hello:ugly:world:again"
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ if [ -z "$PYENV_TEST_DIR" ]; then
|
||||
|
||||
export PYENV_ROOT="${PYENV_TEST_DIR}/root"
|
||||
export HOME="${PYENV_TEST_DIR}/home"
|
||||
export PYENV_HOOK_PATH="${PYENV_ROOT}/pyenv.d"
|
||||
|
||||
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
|
||||
PATH="${PYENV_TEST_DIR}/bin:$PATH"
|
||||
@@ -129,3 +130,11 @@ path_without() {
|
||||
path="${path#:}"
|
||||
echo "${path%:}"
|
||||
}
|
||||
|
||||
create_hook() {
|
||||
mkdir -p "${PYENV_HOOK_PATH}/$1"
|
||||
touch "${PYENV_HOOK_PATH}/$1/$2"
|
||||
if [ ! -t 0 ]; then
|
||||
cat > "${PYENV_HOOK_PATH}/$1/$2"
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -12,6 +12,12 @@ create_file() {
|
||||
touch "$1"
|
||||
}
|
||||
|
||||
@test "detects global 'version' file" {
|
||||
create_file "${PYENV_ROOT}/version"
|
||||
run pyenv-version-file
|
||||
assert_success "${PYENV_ROOT}/version"
|
||||
}
|
||||
|
||||
@test "prints global file if no version files exist" {
|
||||
assert [ ! -e "${PYENV_ROOT}/version" ]
|
||||
assert [ ! -e ".python-version" ]
|
||||
@@ -19,45 +25,12 @@ create_file() {
|
||||
assert_success "${PYENV_ROOT}/version"
|
||||
}
|
||||
|
||||
@test "detects 'global' file" {
|
||||
create_file "${PYENV_ROOT}/global"
|
||||
run pyenv-version-file
|
||||
assert_success "${PYENV_ROOT}/global"
|
||||
}
|
||||
|
||||
@test "detects 'default' file" {
|
||||
create_file "${PYENV_ROOT}/default"
|
||||
run pyenv-version-file
|
||||
assert_success "${PYENV_ROOT}/default"
|
||||
}
|
||||
|
||||
@test "'version' has precedence over 'global' and 'default'" {
|
||||
create_file "${PYENV_ROOT}/version"
|
||||
create_file "${PYENV_ROOT}/global"
|
||||
create_file "${PYENV_ROOT}/default"
|
||||
run pyenv-version-file
|
||||
assert_success "${PYENV_ROOT}/version"
|
||||
}
|
||||
|
||||
@test "in current directory" {
|
||||
create_file ".python-version"
|
||||
run pyenv-version-file
|
||||
assert_success "${PYENV_TEST_DIR}/.python-version"
|
||||
}
|
||||
|
||||
@test "legacy file in current directory" {
|
||||
create_file ".pyenv-version"
|
||||
run pyenv-version-file
|
||||
assert_success "${PYENV_TEST_DIR}/.pyenv-version"
|
||||
}
|
||||
|
||||
@test ".python-version has precedence over legacy file" {
|
||||
create_file ".python-version"
|
||||
create_file ".pyenv-version"
|
||||
run pyenv-version-file
|
||||
assert_success "${PYENV_TEST_DIR}/.python-version"
|
||||
}
|
||||
|
||||
@test "in parent directory" {
|
||||
create_file ".python-version"
|
||||
mkdir -p project
|
||||
@@ -74,14 +47,6 @@ create_file() {
|
||||
assert_success "${PYENV_TEST_DIR}/project/.python-version"
|
||||
}
|
||||
|
||||
@test "legacy file has precedence if higher" {
|
||||
create_file ".python-version"
|
||||
create_file "project/.pyenv-version"
|
||||
cd project
|
||||
run pyenv-version-file
|
||||
assert_success "${PYENV_TEST_DIR}/project/.pyenv-version"
|
||||
}
|
||||
|
||||
@test "PYENV_DIR has precedence over PWD" {
|
||||
create_file "widget/.python-version"
|
||||
create_file "project/.python-version"
|
||||
@@ -97,3 +62,14 @@ create_file() {
|
||||
PYENV_DIR="${PYENV_TEST_DIR}/widget/blank" run pyenv-version-file
|
||||
assert_success "${PYENV_TEST_DIR}/project/.python-version"
|
||||
}
|
||||
|
||||
@test "finds version file in target directory" {
|
||||
create_file "project/.python-version"
|
||||
run pyenv-version-file "${PWD}/project"
|
||||
assert_success "${PYENV_TEST_DIR}/project/.python-version"
|
||||
}
|
||||
|
||||
@test "fails when no version file in target directory" {
|
||||
run pyenv-version-file "$PWD"
|
||||
assert_failure ""
|
||||
}
|
||||
|
||||
@@ -22,9 +22,30 @@ setup() {
|
||||
assert_success "system"
|
||||
}
|
||||
|
||||
@test "PYENV_VERSION can be overridden by hook" {
|
||||
create_version "2.7.11"
|
||||
create_version "3.5.1"
|
||||
create_hook version-name test.bash <<<"PYENV_VERSION=3.5.1"
|
||||
|
||||
PYENV_VERSION=2.7.11 run pyenv-version-name
|
||||
assert_success "3.5.1"
|
||||
}
|
||||
|
||||
@test "carries original IFS within hooks" {
|
||||
create_hook version-name hello.bash <<SH
|
||||
hellos=(\$(printf "hello\\tugly world\\nagain"))
|
||||
echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
|
||||
SH
|
||||
|
||||
export PYENV_VERSION=system
|
||||
IFS=$' \t\n' run pyenv-version-name env
|
||||
assert_success
|
||||
assert_line "HELLO=:hello:ugly:world:again"
|
||||
}
|
||||
|
||||
@test "PYENV_VERSION has precedence over local" {
|
||||
create_version "2.7.6"
|
||||
create_version "3.3.3"
|
||||
create_version "2.7.11"
|
||||
create_version "3.5.1"
|
||||
|
||||
cat > ".python-version" <<<"2.7.6"
|
||||
run pyenv-version-name
|
||||
|
||||
@@ -31,8 +31,26 @@ setup() {
|
||||
assert_success "${PWD}/.python-version"
|
||||
}
|
||||
|
||||
@test "detects alternate version file" {
|
||||
touch .pyenv-version
|
||||
run pyenv-version-origin
|
||||
assert_success "${PWD}/.pyenv-version"
|
||||
@test "reports from hook" {
|
||||
create_hook version-origin test.bash <<<"PYENV_VERSION_ORIGIN=plugin"
|
||||
|
||||
PYENV_VERSION=1 run pyenv-version-origin
|
||||
assert_success "plugin"
|
||||
}
|
||||
|
||||
@test "carries original IFS within hooks" {
|
||||
create_hook version-origin hello.bash <<SH
|
||||
hellos=(\$(printf "hello\\tugly world\\nagain"))
|
||||
echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
|
||||
SH
|
||||
|
||||
export PYENV_VERSION=system
|
||||
IFS=$' \t\n' run pyenv-version-origin env
|
||||
assert_success
|
||||
assert_line "HELLO=:hello:ugly:world:again"
|
||||
}
|
||||
|
||||
@test "doesn't inherit PYENV_VERSION_ORIGIN from environment" {
|
||||
PYENV_VERSION_ORIGIN=ignored run pyenv-version-origin
|
||||
assert_success "${PYENV_ROOT}/version"
|
||||
}
|
||||
|
||||
@@ -113,15 +113,13 @@ OUT
|
||||
}
|
||||
|
||||
@test "carries original IFS within hooks" {
|
||||
hook_path="${PYENV_TEST_DIR}/pyenv.d"
|
||||
mkdir -p "${hook_path}/which"
|
||||
cat > "${hook_path}/which/hello.bash" <<SH
|
||||
create_hook which hello.bash <<SH
|
||||
hellos=(\$(printf "hello\\tugly world\\nagain"))
|
||||
echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
|
||||
exit
|
||||
SH
|
||||
|
||||
PYENV_HOOK_PATH="$hook_path" IFS=$' \t\n' PYENV_VERSION=system run pyenv-which anything
|
||||
IFS=$' \t\n' PYENV_VERSION=system run pyenv-which anything
|
||||
assert_success
|
||||
assert_output "HELLO=:hello:ugly:world:again"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user