forked from Project-MONAI/MONAI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruntests.sh
executable file
·157 lines (133 loc) · 3.58 KB
/
runtests.sh
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#! /bin/bash
set -e
# Test script for running all tests
homedir="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$homedir"
export PYTHONPATH="$homedir:$PYTHONPATH"
echo "$PYTHONPATH"
# configuration values
doCoverage=false
doQuickTests=false
doNetTests=false
doDryRun=false
doZooTests=false
doCodeFormat=false
# testing command to run
cmd="python3"
cmdprefix=""
# parse arguments
for i in "$@"
do
case $i in
--coverage)
doCoverage=true
;;
--quick)
doQuickTests=true
;;
--net)
doNetTests=true
;;
--dryrun)
doDryRun=true
;;
--zoo)
doZooTests=true
;;
--codeformat)
doCodeFormat=true
;;
*)
echo "runtests.sh [--codeformat] [--coverage] [--quick] [--net] [--dryrun] [--zoo]"
exit 1
;;
esac
done
# report on code format
if [ "$doCodeFormat" = 'true' ]
then
# Ensure that the necessary packages for code format testing are installed
if [[ ! -f "$(which flake8)" ]] || [[ ! -f "$(which black)" ]]; then
pip install -r requirements-dev.txt
fi
set +e # Disable exit on failure so that diagnostics can be given on failure
echo "----------------------------------"
echo "Verifying black formatting checks."
black --check "$(pwd)"
black_status=$?
echo "----------------------------------"
if [ ${black_status} -ne 0 ];
then
echo "----------------------------------"
echo "black code formatting test failed!"
echo "::: Run"
echo "::: black \"$(pwd)\""
echo "::: to auto fixing formatting errors"
echo "----------------------------------"
exit ${black_status}
else
echo "*** black code format tests passed. ***"
fi
echo "-----------------------------------"
echo "Verifying flake8 formatting checks."
MYPYPATH="$(pwd)/monai" flake8 "$(pwd)" --count --statistics
flake8_status=$?
echo "-----------------------------------"
if [ ${flake8_status} -ne 0 ];
then
echo "----------------------------------"
echo "Formatting test failed!"
echo "Manually review and fix listed formatting errors"
exit ${flake8_status}
else
echo "*** flake8 code format tests passed. ***"
fi
set -e # Re-enable exit on failure
fi
# When running --quick, require doCoverage as well and set QUICKTEST environmental
# variable to disable slow unit tests from running.
if [ "$doQuickTests" = 'true' ]
then
doCoverage=true
export QUICKTEST=True
fi
# commands are echoed instead of run in this case
if [ "$doDryRun" = 'true' ]
then
echo "Dry run commands:"
cmdprefix="dryrun "
# create a dry run function which prints the command prepended with spaces for neatness
function dryrun { echo " " "$@" ; }
fi
# set command and clear previous coverage data
if [ "$doCoverage" = 'true' ]
then
cmd="coverage run -a --source ."
${cmdprefix} coverage erase
fi
# # download test data if needed
# if [ ! -d testing_data ] && [ "$doDryRun" != 'true' ]
# then
# fi
# unit tests
${cmdprefix}${cmd} -m unittest -v
# network training/inference/eval tests
if [ "$doNetTests" = 'true' ]
then
for i in tests/integration_*.py
do
echo "$i"
${cmdprefix}${cmd} "$i"
done
fi
# run model zoo tests
if [ "$doZooTests" = 'true' ]
then
echo "ERROR: --zoo options not yet implemented"
exit 255
fi
# report on coverage
if [ "$doCoverage" = 'true' ]
then
${cmdprefix}coverage report --skip-covered -m
fi