Skip to content

Commit a8c48d0

Browse files
committed
Perfom pythonwrap-related tests for all Python versions
Signed-off-by: Michał Górny <mgorny@gentoo.org>
1 parent 4fa71fd commit a8c48d0

File tree

8 files changed

+216
-137
lines changed

8 files changed

+216
-137
lines changed

tests/python-argv0-test

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,47 @@
33
echo "${TEST_NAME} -- regression test for argv[0] -> sys.executable setting"
44

55
set -- ${PYTHON_IMPLS}
6+
GOOD=0
7+
BAD=0
68

7-
while true; do
8-
if [ ${#} -lt 1 ]; then
9-
echo 'No working Python interpreter found (?!)' >&2
10-
do_exit 77
11-
fi
9+
while [ ${#} -gt 0 ]; do
10+
export EPYTHON="${1}"
11+
shift
1212

1313
# We have to have the proper Python version installed.
14-
if ! "${1}" --version >&2; then
15-
shift
16-
else
17-
break
14+
if ! "${EPYTHON}" --version >&2; then
15+
continue
1816
fi
19-
done
20-
21-
export EPYTHON=${1}
2217

23-
echo "Python used: ${EPYTHON}" >&2
18+
echo "Testing Python: ${EPYTHON}" >&2
19+
PYTHON_PATH=$(command -v "${EPYTHON}")
2420

25-
PYTHON_PATH=$(command -v "${EPYTHON}")
21+
mkdir -p "${TEST_DIR}/${EPYTHON}"
22+
ln -f -s "${PYTHON_PATH}" "${TEST_DIR}/${EPYTHON}/python"
2623

27-
mkdir -p "${TEST_DIR}/${EPYTHON}"
28-
ln -f -s "${PYTHON_PATH}" "${TEST_DIR}/${EPYTHON}/python"
24+
# replace with C wrapper
25+
ln -f -s python-exec2c "${TEST_DIR}/python"
2926

30-
# replace with C wrapper
31-
ln -f -s python-exec2c "${TEST_DIR}/python"
27+
ORIG_EXE=$("${PYTHON_PATH}" -c 'import os.path, sys; print(os.path.realpath(sys.executable))')
28+
WRAP_EXE=$("${TEST_DIR}/python" -c 'import os.path, sys; print(os.path.realpath(sys.executable))')
3229

33-
ORIG_EXE=$("${PYTHON_PATH}" -c 'import os.path, sys; print(os.path.realpath(sys.executable))')
34-
WRAP_EXE=$("${TEST_DIR}/python" -c 'import os.path, sys; print(os.path.realpath(sys.executable))')
30+
echo "Original realpath(sys.executable): ${ORIG_EXE}"
31+
echo "Wrapped realpath(sys.executable): ${WRAP_EXE}"
3532

36-
echo "Original realpath(sys.executable): ${ORIG_EXE}"
37-
echo "Wrapped realpath(sys.executable): ${WRAP_EXE}"
33+
if [ "${ORIG_EXE}" = "${WRAP_EXE}" ]; then
34+
: $(( GOOD++ ))
35+
else
36+
: $(( BAD++ ))
37+
fi
38+
done
3839

39-
if [ "${ORIG_EXE}" = "${WRAP_EXE}" ]; then
40-
do_exit 0
40+
if [ ${BAD} -eq 0 ]; then
41+
if [ ${GOOD} -eq 0 ]; then
42+
echo 'No working Python interpreter found (?!)' >&2
43+
do_exit 77
44+
else
45+
do_exit 0
46+
fi
4147
else
4248
do_exit 1
4349
fi

tests/pythonwrap-__file__-test

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,43 @@
33
echo "${TEST_NAME} -- test whether Python wrapper sets __file__ correctly"
44

55
set -- ${PYTHON_IMPLS}
6+
GOOD=0
7+
BAD=0
68

7-
while true; do
8-
if [ ${#} -lt 1 ]; then
9-
echo 'No working Python interpreter found (?!)' >&2
10-
do_exit 77
11-
fi
9+
while [ ${#} -gt 0 ]; do
10+
MY_PYTHON="${1}"
11+
shift
1212

1313
# We have to have the proper Python version installed.
14-
if ! "${1}" --version >&2; then
15-
shift
16-
else
17-
break
14+
if ! "${MY_PYTHON}" --version >&2; then
15+
continue
1816
fi
19-
done
20-
21-
MY_PYTHON=${1}
2217

23-
echo "Python used: ${MY_PYTHON}" >&2
18+
echo "Testing Python: ${MY_PYTHON}" >&2
19+
write_impl "${MY_PYTHON}" "print(__file__)"
2420

25-
write_impl "${MY_PYTHON}" "print(__file__)"
21+
# The value should be the same as if variant was run directly.
22+
V_EXP=$("${MY_PYTHON}" "${TEST_DIR}/${MY_PYTHON}/${TEST_TMP}")
23+
V_GOT=$("${MY_PYTHON}" "${TEST_DIR}/${TEST_TMP}")
2624

27-
# The value should be the same as if variant was run directly.
28-
V_EXP=$("${MY_PYTHON}" "${TEST_DIR}/${MY_PYTHON}/${TEST_TMP}")
29-
V_GOT=$("${MY_PYTHON}" "${TEST_DIR}/${TEST_TMP}")
25+
echo "Expected: ${V_EXP}" >&2
26+
echo "Received: ${V_GOT}" >&2
27+
if [ "${V_EXP}" = "${V_GOT}" ]; then
28+
echo "Correct!" >&2
29+
: $(( GOOD++ ))
30+
else
31+
echo "No match." >&2
32+
: $(( BAD++ ))
33+
fi
34+
done
3035

31-
echo "Expected: ${V_EXP}" >&2
32-
echo "Received: ${V_GOT}" >&2
33-
if [ "${V_EXP}" = "${V_GOT}" ]; then
34-
echo "Correct!" >&2
35-
do_exit 0
36+
if [ ${BAD} -eq 0 ]; then
37+
if [ ${GOOD} -eq 0 ]; then
38+
echo 'No working Python interpreter found (?!)' >&2
39+
do_exit 77
40+
else
41+
do_exit 0
42+
fi
3643
else
37-
echo "No match." >&2
3844
do_exit 1
3945
fi

tests/pythonwrap-abs-symlink-test

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,36 @@
33
echo "${TEST_NAME} -- test whether Python wrapper follows (relative) symlinks"
44

55
set -- ${PYTHON_IMPLS}
6+
GOOD=0
7+
BAD=0
68

7-
while true; do
8-
if [ ${#} -lt 1 ]; then
9-
echo 'No working Python interpreter found (?!)' >&2
10-
do_exit 77
11-
fi
9+
while [ ${#} -gt 0 ]; do
10+
MY_PYTHON="${1}"
11+
shift
1212

1313
# We have to have the proper Python version installed.
14-
if ! "${1}" --version >&2; then
15-
shift
16-
else
17-
break
14+
if ! "${MY_PYTHON}" --version >&2; then
15+
continue
1816
fi
19-
done
20-
21-
MY_PYTHON=${1}
2217

23-
echo "Python used: ${MY_PYTHON}" >&2
18+
echo "Testing Python: ${MY_PYTHON}" >&2
19+
write_impl "${MY_PYTHON}" "import sys; sys.exit(0)"
20+
do_sym "${PWD}/${TEST_DIR}/${TEST_TMP}" "${TEST_TMP}.symlink"
2421

25-
write_impl "${MY_PYTHON}" "import sys; sys.exit(0)"
26-
do_sym "${PWD}/${TEST_DIR}/${TEST_TMP}" "${TEST_TMP}.symlink"
22+
if do_test_noexit "${MY_PYTHON}" "${TEST_TMP}.symlink"; then
23+
: $(( GOOD++ ))
24+
else
25+
: $(( BAD++ ))
26+
fi
27+
done
2728

28-
do_test "${MY_PYTHON}" "${TEST_TMP}.symlink"
29+
if [ ${BAD} -eq 0 ]; then
30+
if [ ${GOOD} -eq 0 ]; then
31+
echo 'No working Python interpreter found (?!)' >&2
32+
do_exit 77
33+
else
34+
do_exit 0
35+
fi
36+
else
37+
do_exit 1
38+
fi

tests/pythonwrap-argv0-test

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,44 @@
33
echo "${TEST_NAME} -- test whether Python wrapper sets sys.argv[0] correctly"
44

55
set -- ${PYTHON_IMPLS}
6+
GOOD=0
7+
BAD=0
68

7-
while true; do
8-
if [ ${#} -lt 1 ]; then
9-
echo 'No working Python interpreter found (?!)' >&2
10-
do_exit 77
11-
fi
9+
while [ ${#} -gt 0 ]; do
10+
MY_PYTHON="${1}"
11+
shift
1212

1313
# We have to have the proper Python version installed.
14-
if ! "${1}" --version >&2; then
15-
shift
16-
else
17-
break
14+
if ! "${MY_PYTHON}" --version >&2; then
15+
continue
1816
fi
19-
done
20-
21-
MY_PYTHON=${1}
2217

23-
echo "Python used: ${MY_PYTHON}" >&2
18+
echo "Testing Python: ${MY_PYTHON}" >&2
19+
write_impl "${MY_PYTHON}" "import sys; print(sys.argv[0])"
2420

25-
write_impl "${MY_PYTHON}" "import sys; print(sys.argv[0])"
21+
# The value should be the same as if variant was run directly.
22+
V_EXP=$("${MY_PYTHON}" "${TEST_DIR}/${MY_PYTHON}/${TEST_TMP}")
23+
V_GOT=$("${MY_PYTHON}" "${TEST_DIR}/${TEST_TMP}")
2624

27-
# The value should be the same as if variant was run directly.
28-
V_EXP=$("${MY_PYTHON}" "${TEST_DIR}/${MY_PYTHON}/${TEST_TMP}")
29-
V_GOT=$("${MY_PYTHON}" "${TEST_DIR}/${TEST_TMP}")
25+
echo "Expected: ${V_EXP}" >&2
26+
echo "Received: ${V_GOT}" >&2
27+
if [ "${V_EXP}" = "${V_GOT}" ]; then
28+
echo "Correct!" >&2
29+
: $(( GOOD++ ))
30+
else
31+
echo "No match." >&2
32+
: $(( BAD++ ))
33+
do_exit 1
34+
fi
35+
done
3036

31-
echo "Expected: ${V_EXP}" >&2
32-
echo "Received: ${V_GOT}" >&2
33-
if [ "${V_EXP}" = "${V_GOT}" ]; then
34-
echo "Correct!" >&2
35-
do_exit 0
37+
if [ ${BAD} -eq 0 ]; then
38+
if [ ${GOOD} -eq 0 ]; then
39+
echo 'No working Python interpreter found (?!)' >&2
40+
do_exit 77
41+
else
42+
do_exit 0
43+
fi
3644
else
37-
echo "No match." >&2
3845
do_exit 1
3946
fi

tests/pythonwrap-copy-test

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,39 @@
33
echo "${TEST_NAME} -- test whether Python wrapper works when copied (instead of symlinked)"
44

55
set -- ${PYTHON_IMPLS}
6+
GOOD=0
7+
BAD=0
68

7-
while true; do
8-
if [ ${#} -lt 1 ]; then
9-
echo 'No Python implementation installed (?!)' >&2
10-
do_exit 77
11-
fi
9+
# replace with a copy
10+
rm "${TEST_DIR}/${TEST_TMP}"
11+
cp "${TEST_DIR}/python-exec2" "${TEST_DIR}/${TEST_TMP}"
1212

13-
# we have to have the proper Python version installed
14-
if "${1}" --version >&2; then
15-
break
16-
fi
13+
while [ ${#} -gt 0 ]; do
14+
export EPYTHON="${1}"
1715
shift
18-
done
1916

20-
export EPYTHON=${1}
17+
# We have to have the proper Python version installed.
18+
if ! "${EPYTHON}" --version >&2; then
19+
continue
20+
fi
2121

22-
write_impl "${EPYTHON}" "import sys; sys.exit(0)"
22+
echo "Testing Python: ${EPYTHON}" >&2
23+
write_impl "${EPYTHON}" "import sys; sys.exit(0)"
2324

24-
# replace with a copy
25-
rm "${TEST_DIR}/${TEST_TMP}"
26-
cp "${TEST_DIR}/python-exec2" "${TEST_DIR}/${TEST_TMP}"
25+
if do_test_noexit "${EPYTHON}" "${TEST_TMP}"; then
26+
: $(( GOOD++ ))
27+
else
28+
: $(( BAD++ ))
29+
fi
30+
done
2731

28-
do_test "${EPYTHON}" "${TEST_TMP}"
32+
if [ ${BAD} -eq 0 ]; then
33+
if [ ${GOOD} -eq 0 ]; then
34+
echo 'No working Python interpreter found (?!)' >&2
35+
do_exit 77
36+
else
37+
do_exit 0
38+
fi
39+
else
40+
do_exit 1
41+
fi

tests/pythonwrap-deep-symlink-test

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,38 @@
33
echo "${TEST_NAME} -- test whether Python wrapper follows (relative) symlinks"
44

55
set -- ${PYTHON_IMPLS}
6+
GOOD=0
7+
BAD=0
68

7-
while true; do
8-
if [ ${#} -lt 1 ]; then
9-
echo 'No working Python interpreter found (?!)' >&2
10-
do_exit 77
11-
fi
9+
while [ ${#} -gt 0 ]; do
10+
MY_PYTHON="${1}"
11+
shift
1212

1313
# We have to have the proper Python version installed.
14-
if ! "${1}" --version >&2; then
15-
shift
16-
else
17-
break
14+
if ! "${MY_PYTHON}" --version >&2; then
15+
continue
1816
fi
19-
done
20-
21-
MY_PYTHON=${1}
2217

23-
echo "Python used: ${MY_PYTHON}" >&2
18+
echo "Testing Python: ${MY_PYTHON}" >&2
19+
write_impl "${MY_PYTHON}" "import sys; sys.exit(0)"
20+
do_sym "${TEST_TMP}" "${TEST_TMP}-symI"
21+
do_sym "${TEST_TMP}-symI" "${TEST_TMP}-symII"
22+
do_sym "${TEST_TMP}-symII" "${TEST_TMP}-symIII"
2423

25-
write_impl "${MY_PYTHON}" "import sys; sys.exit(0)"
26-
do_sym "${TEST_TMP}" "${TEST_TMP}-symI"
27-
do_sym "${TEST_TMP}-symI" "${TEST_TMP}-symII"
28-
do_sym "${TEST_TMP}-symII" "${TEST_TMP}-symIII"
24+
if do_test_noexit "${MY_PYTHON}" "${TEST_TMP}-symIII"; then
25+
: $(( GOOD++ ))
26+
else
27+
: $(( BAD++ ))
28+
fi
29+
done
2930

30-
do_test "${MY_PYTHON}" "${TEST_TMP}-symIII"
31+
if [ ${BAD} -eq 0 ]; then
32+
if [ ${GOOD} -eq 0 ]; then
33+
echo 'No working Python interpreter found (?!)' >&2
34+
do_exit 77
35+
else
36+
do_exit 0
37+
fi
38+
else
39+
do_exit 1
40+
fi

0 commit comments

Comments
 (0)