pyenv/test/version-file-write.bats
native-api dc873cf568
Support missing versions being present and set in a local .python-version (#3134)
Requested in https://github.com/pyenv/pyenv/issues/2680
for deployments with a stock `.pyenv-version` that can use any
of a number of Python versions
and for compatibility with `uv`.

* Support `pyenv local --force`
* Support `pyenv-version-file-write --force`
* Support `pyenv version-name --force`
* Ignore missing versions when searching for executables
* Display "commmand not found" even when there are nonexistent versions

* exec.bats: replace `python` and `rspec` with something that doesn't exist globally, either
in Ubuntu Github CI, `python` exists globally
2024-12-16 02:32:45 +03:00

38 lines
1020 B
Bash

#!/usr/bin/env bats
load test_helper
setup() {
mkdir -p "$PYENV_TEST_DIR"
cd "$PYENV_TEST_DIR"
}
@test "invocation without 2 arguments prints usage" {
run pyenv-version-file-write
assert_failure "Usage: pyenv version-file-write [-f|--force] <file> <version> [...]"
run pyenv-version-file-write "one" ""
assert_failure
}
@test "setting nonexistent version fails" {
assert [ ! -e ".python-version" ]
run pyenv-version-file-write ".python-version" "2.7.6"
assert_failure "pyenv: version \`2.7.6' not installed"
assert [ ! -e ".python-version" ]
}
@test "setting nonexistent version succeeds with force" {
assert [ ! -e ".python-version" ]
run pyenv-version-file-write --force ".python-version" "2.7.6"
assert_success
assert [ -e ".python-version" ]
}
@test "writes value to arbitrary file" {
mkdir -p "${PYENV_ROOT}/versions/2.7.6"
assert [ ! -e "my-version" ]
run pyenv-version-file-write "${PWD}/my-version" "2.7.6"
assert_success ""
assert [ "$(cat my-version)" = "2.7.6" ]
}