-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathrun-tests
More file actions
executable file
·99 lines (87 loc) · 3.39 KB
/
run-tests
File metadata and controls
executable file
·99 lines (87 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/bash
## Copyright (C) 2025 - 2026 ENCRYPTED SUPPORT LLC <adrelanos@whonix.org>
## See the file COPYING for copying conditions.
set -eux
git_toplevel="$(git rev-parse --show-toplevel)"
pyrc="${git_toplevel}/pyproject.toml"
pythonpath="${git_toplevel}/usr/lib/python3/dist-packages"
ci_tests_dir="${git_toplevel}/ci/tests"
export PYTHONPATH="${pythonpath}${PYTHONPATH+":${PYTHONPATH}"}"
pytest=(python3 -m pytest -o 'python_files=tests/*.py')
## Separate pytest config for ci/tests/<pkg>/, which uses standard
## test_*.py discovery rather than tests/*.py. Run via
## --import-mode=importlib so a test file named e.g. test_stdisplay.py
## can't shadow the real stdisplay package on PYTHONPATH (defensive
## - currently only test_property.py lives there).
pytest_ci_tests=(python3 -m pytest --import-mode=importlib)
black=(black --config="${pyrc}" --color --diff --check)
pylint=(pylint --rcfile="${pyrc}")
mypy=(mypy --config-file="${pyrc}")
py_lib_to_test_list=(
'stdisplay'
'sanitize_string'
'strip_markup'
'unicode_show'
'strict_config_parser'
'append_shared'
)
for py_lib_to_test in "${py_lib_to_test_list[@]}"; do
cd -- "${pythonpath}/${py_lib_to_test}/"
# Ideally, these variables should be ignored by the tests...
NO_COLOR="" COLORTERM="" TERM="xterm-direct" "${pytest[@]}" "${@}"
"${black[@]}" .
#find . -type f -name "*.py" -print0 | xargs -0 "${pylint[@]}"
"${pylint[@]}" .
"${mypy[@]}" .
done
## Tests added under ci/tests/<pkg>/ are CI-only and not shipped in
## the .deb (debian/helper-scripts.install ships 'usr/*'). Currently
## only the Hypothesis property tests live here. Each test file
## imports from its package via PYTHONPATH set above; no cross-test
## imports, so no conftest gymnastics required.
##
## We deliberately skip pylint/mypy on ci/tests/ - test code value-vs-cost
## for strict typing is low, and cross-package linting from this layout
## requires extra sys.path / mypy_path plumbing that isn't worth the
## maintenance cost. black --check still runs so style stays consistent.
if [ "${CI:-}" = "true" ] || [ "${ALLOW_LOCAL:-}" = "true" ]; then
for py_lib_to_test in "${py_lib_to_test_list[@]}"; do
test_path="${ci_tests_dir}/${py_lib_to_test}"
if [ -d "${test_path}" ]; then
cd -- "${test_path}"
NO_COLOR="" COLORTERM="" TERM="xterm-direct" \
"${pytest_ci_tests[@]}" "${@}"
"${black[@]}" .
fi
done
fi
stdin_file_read_utils=(stcat stcatn)
stdin_implicit_read_utils=(sttee stsponge strip-markup unicode-show)
stdin_utils=("${stdin_file_read_utils[@]}" "${stdin_implicit_read_utils[@]}")
utils=(stprint stecho sanitize-string "${stdin_utils[@]}")
cd -- "${git_toplevel}/usr/bin"
"${black[@]}" -- "${utils[@]}"
"${pylint[@]}" -- "${utils[@]}"
## 'file_name' (not 'file') so we don't shadow the 'file' command.
for file_name in "${utils[@]}"; do
"${mypy[@]}" -- "${file_name}"
done
for util in "${stdin_file_read_utils[@]}"; do
./"${util}" <&-
./"${util}" - <&-
done
for util in "${stdin_implicit_read_utils[@]}"; do
./"${util}" <&-
done
## sanitize-string needs special handling because it takes a mandatory output
## string length argument.
./sanitize-string -- nolimit <&-
if ! [ -d "${HOME}/trojan-source" ]; then
printf "%s\n" "WARNING: Not running unicode-testscript, ${HOME}/trojan-source does not exist.
To get it:
cd ~
git clone git@github.com:nickboucher/trojan-source.git" >&2
exit 1
fi
cd -- "${git_toplevel}"
./unicode-testscript