3 source /home/scott/bin/color_vars.sh
5 ROOT=/home/scott/lib/python_modules
12 PERF_TESTS=("string_utils_test.py")
17 echo "Usage: dup <string> <count>"
20 local times=$(seq 1 $2)
28 echo "Usage: make_header <required title> <color>"
32 local title_len=${#title}
33 title_len=$((title_len + 4))
36 local right=$(($width-($title_len+$left)))
39 echo -ne "[ ${color}${title}${NC} ]"
45 echo "Usage: $0 [-a]|[-i][-u][-d] [--coverage]"
47 echo "Runs tests under ${ROOT}. Options control which test types:"
49 echo " -a | --all . . . . . . . . . . . . Run all types of tests"
50 echo " -d | --doctests . . . . . . . . . Run doctests"
51 echo " -u | --unittests . . . . . . . . . Run unittests"
52 echo " -i | --integration . . . . . . . . Run integration tests"
57 while [[ $# -gt 0 ]]; do
78 echo "Argument $key was not recognized."
87 if [ $(expr ${DOCTEST} + ${UNITTEST} + ${INTEGRATION}) -eq 0 ]; then
92 if [ ${COVERAGE} -eq 1 ]; then
97 if [ ${DOCTEST} -eq 1 ]; then
98 for doctest in $(grep -lR doctest ${ROOT}/*); do
99 if [[ ${doctest} == *.py ]]; then
100 BASE=$(basename ${doctest})
101 BASE="${BASE} (doctest)"
102 make_header "${BASE}" "${CYAN}"
103 if [ ${COVERAGE} -eq 1 ]; then
104 OUT=$( coverage run --source ${HOME}/lib --append ${doctest} 2>&1 )
106 OUT=$( python3 ${doctest} 2>&1 )
108 TESTS_RUN=$((TESTS_RUN+1))
109 FAILED=$( echo "${OUT}" | grep '\*\*\*Test Failed\*\*\*' | wc -l )
110 if [ $FAILED == 0 ]; then
114 FAILURES=$((FAILURES+1))
115 FAILED_TESTS="${FAILED_TESTS},${BASE} (python3 ${doctest})"
121 if [ ${UNITTEST} -eq 1 ]; then
122 for test in $(find ${ROOT} -name "*_test.py" -print); do
123 BASE=$(basename ${test})
124 HDR="${BASE} (unittest)"
125 make_header "${HDR}" "${GREEN}"
126 if [ ${COVERAGE} -eq 1 ]; then
127 coverage run --source ${HOME}/lib --append ${test} --unittests_ignore_perf
128 if [[ " ${PERF_TESTS[*]} " =~ " ${BASE} " ]]; then
129 echo "(re-running w/o coverage to record perf results)."
135 if [ $? -ne 0 ]; then
136 FAILURES=$((FAILURES+1))
137 FAILED_TESTS="${FAILED_TESTS},${BASE} (python3 ${test})"
139 TESTS_RUN=$((TESTS_RUN+1))
143 if [ ${INTEGRATION} -eq 1 ]; then
144 for test in $(find ${ROOT} -name "*_itest.py" -print); do
145 BASE=$(basename ${test})
146 HDR="${BASE} (integration test)"
147 make_header "${HDR}" "${ORANGE}"
148 if [ ${COVERAGE} -eq 1 ]; then
149 coverage run --source ${HOME}/lib --append ${test}
153 if [ $? -ne 0 ]; then
154 FAILURES=$((FAILURES+1))
155 FAILED_TESTS="${FAILED_TESTS},${BASE} (python3 ${test})"
157 TESTS_RUN=$((TESTS_RUN+1))
161 if [ ${COVERAGE} -eq 1 ]; then
162 make_header "Code Coverage Report" "${GREEN}"
163 coverage report --omit=config-3.8.py,*_test.py,*_itest.py --sort=-cover
165 echo "To recall this report w/o re-running the tests:"
167 echo " $ coverage report --omit=config-3.8.py,*_test.py,*_itest.py --sort=-cover"
169 echo "...from the 'tests' directory. Note that subsequent calls to "
170 echo "run_tests.sh with --coverage will klobber previous results. See:"
172 echo " https://coverage.readthedocs.io/en/6.2/"
176 if [ ${FAILURES} -ne 0 ]; then
177 FAILED_TESTS=$(echo ${FAILED_TESTS} | sed 's/^,/__/g')
178 FAILED_TESTS=$(echo ${FAILED_TESTS} | sed 's/,/\n__/g')
179 if [ ${FAILURES} -eq 1 ]; then
180 echo -e "${RED}There was ${FAILURES}/${TESTS_RUN} failure:"
182 echo -e "${RED}There were ${FAILURES}/${TESTS_RUN} failures:"
184 echo "${FAILED_TESTS}"
188 echo -e "${BLACK}${ON_GREEN}All (${TESTS_RUN}) test(s) passed.${NC}"