tests: python-buid: use helpers from core (#3572)

This commit is contained in:
Ayush 2026-09-30 08:58:46 +05:30 committed by GitHub
parent 699e27fb27
commit 2e3d62a129
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 75 deletions

View File

@ -1,3 +1,5 @@
source "${BATS_TEST_DIRNAME}/../../../test/test_helper.bash"
setup() {
export PYTHON_BUILD_CURL_OPTS=
export PYTHON_BUILD_HTTP_CLIENT="curl"
@ -69,12 +71,6 @@ install_fixture() {
run python-build $args "$FIXTURE_ROOT/$name" "$destination"
}
assert() {
if ! "$@"; then
flunk "failed: $@"
fi
}
refute() {
if "$@"; then
flunk "expected to fail: $@"
@ -99,32 +95,6 @@ assert_success() {
fi
}
assert_failure() {
if [ "$status" -eq 0 ]; then
flunk "expected failed exit status"
elif [ "$#" -gt 0 ]; then
assert_output "$1"
fi
}
assert_equal() {
if [ "$1" != "$2" ]; then
{ echo "expected:"
echo "$1"
echo "actual:"
echo "$2"
} | flunk
fi
}
assert_output() {
local expected
if [ $# -eq 0 ]; then expected="$(cat -)"
else expected="$1"
fi
assert_equal "$expected" "$output"
}
assert_output_contains() {
local expected="$1"
if [ -z "$expected" ]; then
@ -137,46 +107,3 @@ assert_output_contains() {
} | flunk
}
}
assert_line() {
if [ "$1" -ge 0 ] 2>/dev/null; then
assert_equal "$2" "${lines[$1]}"
else
local line
for line in "${lines[@]}"; do
if [ "$line" = "$1" ]; then return 0; fi
done
flunk "expected line \`$1'" $'\n'\
"output: $output"
fi
}
# Output a modified PATH that ensures that the given executable is not present,
# but in which system utils necessary for pyenv operation are still available.
path_without() {
local path=":${PATH}:"
for exe; do
local found alt util
for found in $(PATH="$path" type -aP "$exe"); do
found="${found%/*}"
if [ "$found" != "${PYENV_ROOT}/shims" ]; then
alt="${PYENV_TEST_DIR}/$(echo "${found#/}" | tr '/' '-')"
mkdir -p "$alt"
for util in bash head cut readlink greadlink tr; do
if [ -x "${found}/$util" ]; then
ln -s "${found}/$util" "${alt}/$util"
fi
done
path="${path/:${found}:/:${alt}:}"
fi
done
done
path="${path#:}"
path="${path%:}"
echo "$path"
}
skip_if_nonposix_security() {
true "${1:?}" "${2:?}"
test "$@" && skip "UNIX permission bits are being overridden" || true
}

View File

@ -68,6 +68,7 @@ assert_success() {
if [ "$status" -ne 0 ]; then
flunk "command failed with exit status $status" $'\n'\
"output: $output"
return 1
fi
_assert_output_if_provided "$@"
}
@ -76,6 +77,7 @@ assert_failure() {
if [ "$status" -eq 0 ]; then
flunk "expected failed exit status" $'\n'\
"output: $output"
return 1
fi
_assert_output_if_provided "$@"
}