-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_tests.bash
executable file
·119 lines (110 loc) · 3.68 KB
/
run_tests.bash
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/bash
#
# Run unit tests and pytest files
# and generate coverage report
#
# Note:
# - The status of the last command determines whether the dockerfile run fails.
# - This is normally pytest which returns success (0) if no tests fail,
# excluding tests marked with xfail.
# - Disables nitpicking shellcheck:
# SC2010: Don't use ls | grep
# SC2046: Quote this to prevent word splitting.
# SC2086: Double quote to prevent globbing and word splitting.
#
# Usage:
# $ ./tools/run_tests.bash
# $ ./tools/run_tests.bash --coverage
#
# Set bash regular and/or verbose tracing
DEBUG_LEVEL=${DEBUG_LEVEL:-0}
if [ "$DEBUG_LEVEL" -ge 3 ]; then
echo "in $0 $* [$(date)]"
fi
if [ "${TRACE:-0}" = "1" ]; then
set -o xtrace
fi
if [ "${VERBOSE:-0}" = "1" ]; then
set -o verbose
fi
# Get directory locations
dir=$(dirname "${BASH_SOURCE[0]}")
## OLD:
## tools="$(dirname "$(realpath -s "$0")")"
## base="$tools/.."
base="$dir/.."
mezcla="$base/mezcla"
tests="$mezcla/tests"
example_tests="$mezcla/examples/tests"
# Optionally source temporary settings script
temp_script="$dir/_temp_test_settings.bash"
if [ -e "$temp_script" ]; then
env_before=$(printenv)
source "$temp_script"
env_after=$(printenv)
if [ "$env_before" != "$env_after" ]; then
echo "FYI: environment changes made via $temp_script"
fi
fi
##
## TEMP:
echo "DEBUG_LEVEL=$DEBUG_LEVEL"
# Get tests to run
TEST_REGEX="${TEST_REGEX:-"."}"
# Note: TEST_REGEX is for only running the specified tests,
# and, FILTER_REGEX is for disabling particular tests.
# Both are meant as expedients, not long-term solutions.
## TEMP: DEFAULT_FILTER_REGEX="(test_audio|test_extract_document_text|test_format_profile|test_hugging_face_speechrec|test_hugging_face_translation|test_keras_param_search|test_kenlm_example|test_spell|test_text_processing)"
DEFAULT_FILTER_REGEX="(not-a-real-test.py)"
FILTER_REGEX="${FILTER_REGEX:-"$DEFAULT_FILTER_REGEX"}"
# shellcheck disable=SC2010
if [[ ("$TEST_REGEX" != ".") || ("$FILTER_REGEX" != "") ]]; then
## OLD:
## tests=$(ls "$tests"/*.py | grep --perl-regexp "$TEST_REGEX")
## example_tests=$(ls "$example_tests"/*.py | grep --perl-regexp "$TEST_REGEX")
tests=$(ls "$tests"/*.py | grep --perl-regexp "$TEST_REGEX" | grep --invert-match --perl-regexp "$FILTER_REGEX")
example_tests=$(ls "$example_tests"/*.py | grep --perl-regexp "$TEST_REGEX" | grep --invert-match --perl-regexp "$FILTER_REGEX")
fi
#
## OLD: echo -e "Running tests on $tests; also running $example_tests\n"
echo -n "Running tests on $tests"
if [ "$example_tests" == "" ]; then
echo "Running no example tests"
else
echo "Also running $example_tests"
fi
echo ""
echo -n "via "
python3 --version
# Remove mezcla package if running under Docker (or act)
# TODO2: check with Bruno whether still needed
if [ "$USER" == "docker" ]; then
pip uninstall mezcla &> /dev/null # Avoid conflicts with installed Mezcla
fi
# Make sure mezcla in python path
export PYTHONPATH="$mezcla/:$PYTHONPATH"
# Run with coverage enabled
test_result=0
# shellcheck disable=SC2046,SC2086
if [ "$1" == "--coverage" ]; then
export COVERAGE_RCFILE="$base/.coveragerc"
export CHECK_COVERAGE='true'
coverage erase
coverage run -m pytest $tests $example_tests
coverage combine
coverage html
test_result="$?"
else
## OLD: pytest $tests $example_tests
pytest_options="${PYTEST_OPTIONS:-}"
pytest $pytest_options $tests $example_tests
test_result="$?"
fi
# End of processing
if [ "$DEBUG_LEVEL" -ge 3 ]; then
echo "out $0 [$(date)]"
fi
# Return status code used by Github actions
## TODO3: integrate support for Jupyter notebooks tests and use combined result;
## see run_tests.bash in shell-scripts repo.
exit "$test_result"