2014-01-02 11:48:22 -05:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
load test_helper
|
|
|
|
|
|
|
|
setup() {
|
|
|
|
mkdir -p "$PYENV_TEST_DIR"
|
|
|
|
cd "$PYENV_TEST_DIR"
|
|
|
|
}
|
|
|
|
|
|
|
|
create_file() {
|
|
|
|
mkdir -p "$(dirname "$1")"
|
2018-02-26 03:32:43 -05:00
|
|
|
echo "system" > "$1"
|
2014-01-02 11:48:22 -05:00
|
|
|
}
|
|
|
|
|
2015-12-28 22:04:53 -05:00
|
|
|
@test "detects global 'version' file" {
|
2016-03-01 20:39:52 -05:00
|
|
|
create_file "${PYENV_ROOT}/version"
|
2014-01-02 11:48:22 -05:00
|
|
|
run pyenv-version-file
|
|
|
|
assert_success "${PYENV_ROOT}/version"
|
|
|
|
}
|
|
|
|
|
2015-12-28 22:04:53 -05:00
|
|
|
@test "prints global file if no version files exist" {
|
2016-03-01 20:39:52 -05:00
|
|
|
assert [ ! -e "${PYENV_ROOT}/version" ]
|
|
|
|
assert [ ! -e ".python-version" ]
|
2014-01-02 11:48:22 -05:00
|
|
|
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 "in parent directory" {
|
|
|
|
create_file ".python-version"
|
|
|
|
mkdir -p project
|
|
|
|
cd project
|
|
|
|
run pyenv-version-file
|
|
|
|
assert_success "${PYENV_TEST_DIR}/.python-version"
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "topmost file has precedence" {
|
|
|
|
create_file ".python-version"
|
|
|
|
create_file "project/.python-version"
|
|
|
|
cd project
|
|
|
|
run pyenv-version-file
|
|
|
|
assert_success "${PYENV_TEST_DIR}/project/.python-version"
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "PYENV_DIR has precedence over PWD" {
|
|
|
|
create_file "widget/.python-version"
|
|
|
|
create_file "project/.python-version"
|
|
|
|
cd project
|
|
|
|
PYENV_DIR="${PYENV_TEST_DIR}/widget" run pyenv-version-file
|
|
|
|
assert_success "${PYENV_TEST_DIR}/widget/.python-version"
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "PWD is searched if PYENV_DIR yields no results" {
|
|
|
|
mkdir -p "widget/blank"
|
|
|
|
create_file "project/.python-version"
|
|
|
|
cd project
|
|
|
|
PYENV_DIR="${PYENV_TEST_DIR}/widget/blank" run pyenv-version-file
|
|
|
|
assert_success "${PYENV_TEST_DIR}/project/.python-version"
|
|
|
|
}
|
2015-12-23 09:19:54 -05:00
|
|
|
|
|
|
|
@test "finds version file in target directory" {
|
2016-03-01 20:39:52 -05:00
|
|
|
create_file "project/.python-version"
|
|
|
|
run pyenv-version-file "${PWD}/project"
|
|
|
|
assert_success "${PYENV_TEST_DIR}/project/.python-version"
|
2015-12-23 09:19:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "fails when no version file in target directory" {
|
2016-03-01 20:39:52 -05:00
|
|
|
run pyenv-version-file "$PWD"
|
2015-12-23 09:19:54 -05:00
|
|
|
assert_failure ""
|
|
|
|
}
|