forked from TDAmeritrade/stumpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·202 lines (184 loc) · 6.63 KB
/
test.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#!/bin/bash
test_mode="all"
print_mode="verbose"
# Parse command line arguments
for var in "$@"
do
if [[ $var == "unit" ]]; then
test_mode="unit"
elif [[ $var == "coverage" ]]; then
test_mode="coverage"
elif [[ $var == "custom" ]]; then
test_mode="custom"
elif [[ $var == "silent" || $var == "print" ]]; then
print_mode="silent"
else
echo "Using default test_mode=\"all\""
fi
done
###############
# Functions #
###############
check_errs()
{
# Function. Parameter 1 is the return code
if [[ $1 -ne "0" ]]; then
echo "Error: pytest encountered exit code $1"
# as a bonus, make our script exit with the right error code.
exit $1
fi
}
check_black()
{
echo "Checking Black Code Formatting"
black --check --diff ./
check_errs $?
}
check_flake()
{
echo "Checking Flake8 Style Guide Enforcement"
flake8 ./
check_errs $?
}
check_print()
{
if [[ $print_mode == "verbose" ]]; then
if [[ `grep print */*.py | wc -l` -gt "0" ]]; then
echo "Error: print statement found in code"
grep print */*.py
exit 1
fi
fi
}
check_naive()
{
# Check if there are any naive implementations not at start of test file
for testfile in tests/test_*.py
do
last_naive="$(grep -n 'def naive_' $testfile | tail -n 1 | awk -F: '{print $1}')"
first_test="$(grep -n 'def test_' $testfile | head -n 1 | awk -F: '{print $1}')"
if [[ ! -z $last_naive && ! -z $first_test && $last_naive -gt $first_test ]]; then
echo "Error: naive implementation found in the middle of $testfile line $last_naive"
exit 1
fi
done
}
test_custom()
{
# export NUMBA_DISABLE_JIT=1
# export NUMBA_ENABLE_CUDASIM=1
# Test one or more user-defined functions repeatedly
for VARIABLE in {1..10}
do
pytest -x -W ignore::DeprecationWarning tests/test_.py
check_errs $?
done
clean_up
exit 0
}
test_unit()
{
echo "Testing Numba JIT Compiled Functions"
pytest -rsx -W ignore::RuntimeWarning -W ignore::DeprecationWarning tests/test_gpu_stump.py
pytest -x -W ignore::RuntimeWarning -W ignore::DeprecationWarning tests/test_core.py
check_errs $?
pytest -x -W ignore::RuntimeWarning -W ignore::DeprecationWarning tests/test_config.py
check_errs $?
pytest -x -W ignore::RuntimeWarning -W ignore::DeprecationWarning tests/test_stump.py tests/test_mstump.py tests/test_stumpi.py
check_errs $?
pytest -x -W ignore::RuntimeWarning -W ignore::DeprecationWarning tests/test_scrump.py
check_errs $?
pytest -x -W ignore::RuntimeWarning -W ignore::DeprecationWarning tests/test_stumped.py
check_errs $?
pytest -x -W ignore::RuntimeWarning -W ignore::DeprecationWarning tests/test_mstumped.py
check_errs $?
pytest -x -W ignore::RuntimeWarning -W ignore::DeprecationWarning tests/test_ostinato.py
check_errs $?
pytest -x -W ignore::RuntimeWarning -W ignore::DeprecationWarning tests/test_gpu_ostinato.py
pytest -x -W ignore::RuntimeWarning -W ignore::DeprecationWarning tests/test_mpdist.py
check_errs $?
pytest -x -W ignore::RuntimeWarning -W ignore::DeprecationWarning tests/test_motifs.py
check_errs $?
pytest -x -W ignore::RuntimeWarning -W ignore::DeprecationWarning tests/test_mmotifs.py
check_errs $?
pytest -x -W ignore::RuntimeWarning -W ignore::DeprecationWarning tests/test_gpu_mpdist.py
pytest -x -W ignore::RuntimeWarning -W ignore::DeprecationWarning tests/test_snippets.py
check_errs $?
pytest -rsx -W ignore::RuntimeWarning -W ignore::DeprecationWarning tests/test_gpu_stimp.py
pytest -x -W ignore::RuntimeWarning -W ignore::DeprecationWarning tests/test_stimp.py
check_errs $?
# aamp
pytest -rsx -W ignore::RuntimeWarning -W ignore::DeprecationWarning tests/test_gpu_aamp.py
pytest -x -W ignore::RuntimeWarning -W ignore::DeprecationWarning tests/test_aamp.py tests/test_maamp.py tests/test_scraamp.py tests/test_aampi.py
check_errs $?
pytest -x -W ignore::RuntimeWarning -W ignore::DeprecationWarning tests/test_scraamp.py
check_errs $?
pytest -x -W ignore::RuntimeWarning -W ignore::DeprecationWarning tests/test_aamped.py
check_errs $?
pytest -x -W ignore::RuntimeWarning -W ignore::DeprecationWarning tests/test_maamped.py
check_errs $?
pytest -x -W ignore::RuntimeWarning -W ignore::DeprecationWarning tests/test_aamp_ostinato.py
check_errs $?
pytest -x -W ignore::RuntimeWarning -W ignore::DeprecationWarning tests/test_gpu_aamp_ostinato.py
pytest -x -W ignore::RuntimeWarning -W ignore::DeprecationWarning tests/test_aampdist.py
check_errs $?
pytest -x -W ignore::RuntimeWarning -W ignore::DeprecationWarning tests/test_aamp_motifs.py
check_errs $?
pytest -x -W ignore::RuntimeWarning -W ignore::DeprecationWarning tests/test_aamp_mmotifs.py
check_errs $?
pytest -x -W ignore::RuntimeWarning -W ignore::DeprecationWarning tests/test_gpu_aampdist.py
pytest -x -W ignore::RuntimeWarning -W ignore::DeprecationWarning tests/test_aampdist_snippets.py
check_errs $?
pytest -rsx -W ignore::RuntimeWarning -W ignore::DeprecationWarning tests/test_gpu_aamp_stimp.py
pytest -x -W ignore::RuntimeWarning -W ignore::DeprecationWarning tests/test_aamp_stimp.py
check_errs $?
pytest -x -W ignore::DeprecationWarning tests/test_non_normalized_decorator.py
check_errs $?
}
test_coverage()
{
echo "Disabling Numba JIT and CUDA Compiled Functions"
export NUMBA_DISABLE_JIT=1
export NUMBA_ENABLE_CUDASIM=1
# echo "Testing Python Functions"
# pytest -x -W ignore::RuntimeWarning -W ignore::DeprecationWarning tests
# check_errs $?
echo "Testing Code Coverage"
coverage run --source=. -m pytest -x -W ignore::RuntimeWarning -W ignore::DeprecationWarning
check_errs $?
coverage report -m --skip-covered --omit=setup.py
}
clean_up()
{
echo "Cleaning Up"
rm -rf "dask-worker-space"
rm -rf "stumpy/__pycache__/"
}
###########
# Main #
###########
clean_up
check_black
check_flake
check_print
check_naive
if [[ $test_mode == "unit" ]]; then
echo "Executing Unit Tests Only"
test_unit
elif [[ $test_mode == "coverage" ]]; then
echo "Executing Code Coverage Only"
test_coverage
elif [[ $test_mode == "custom" ]]; then
echo "Executing Custom User-Defined Tests Only"
# Define tests in `test_custom` function above
# echo "Disabling Numba JIT and CUDA Compiled Functions"
# export NUMBA_DISABLE_JIT=1
# export NUMBA_ENABLE_CUDASIM=1
test_custom
else
echo "Executing Unit Tests And Code Coverage"
test_unit
clean_up
test_coverage
fi
clean_up