forked from etetoolkit/ete
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_tests.sh
executable file
·375 lines (315 loc) · 12.5 KB
/
run_tests.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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
#!/bin/bash
# run_tests.sh -- created 2016-04-28, Renato Alves
source bash_colors.sh
export TOP_PID=$$
# If a command in a pipe fails, the whole command fails
set -o pipefail
REAL=true
PLATFORM='unknown'
unamestr=`uname`
if [[ "$unamestr" == 'Linux' ]]; then
PLATFORM='Linux'
elif [[ "$unamestr" == 'Darwin' ]]; then
PLATFORM='Darwin'
fi
function run {
clr_bold " $@"
if [ $REAL == true ]; then
eval $@ || (clr_red "ERRORS FOUND!" && exit 1)
fi
}
usage() {
echo >&2 ""
echo >&2 "This script runs the test suite provided with ete3."
echo >&2 "Without any optional parameters it defaults to running the api tests"
echo >&2 "on a Python 3.5 environment."
echo >&2 ""
echo >&2 "Usage:"
echo >&2 " $0 [option] [-v version] [testset]"
echo >&2 ""
echo >&2 "Optional parameters:"
echo >&2 " -h|--help = help: shows the current information"
echo >&2 " --setup-only = setup-only: configures and updates the testing environment but skips tests"
echo >&2 " --test-only = test-only: skips configuration of environment and runs tests"
echo >&2 " -l = enable logging to tests.log"
echo >&2 " -s = show the content of tests.log at the end of execution (implies -l)"
echo >&2 " -x = install ete3 external apps in the test environment"
echo >&2 " -v = python version to use for running tests. (default: 3.5)"
echo >&2 " --qt4 = qt4 is used for running tests. (default: qt5)"
echo >&2 " testset = set of tests to run. (default: api) (for full testsuite use all)"
echo >&2 ""
}
valid_version() {
if [ -z "$1" ]; then
echo "$2" # No version was specified
else
if ! [[ $1 =~ ^[2-3](\.[0-9]|\.[1-9][0-9]){0,2}$ ]]; then
echo >&2 -e "\nERROR: Python version should be in one of the following formats: 3, 3.5, 3.5.12 not $1"
usage
kill -s TERM $TOP_PID
else
echo "$1"
fi
fi
}
handle_error() {
if [ "$1" != "0" ]; then
echo >&2 -e "\n$2"
echo >&2 "$3"
# NOTE Not sure why this isn't working anymore.
# It should send a non-zero exit code but it always reports 0
# which is super bad because it silences errors in the testsuite
#kill -s TERM $TOP_PID
# We workaround using exit and the exitcode seen by handle_error
exit "$1"
fi
}
optional() {
if [ "x$1" == "x" ]; then
echo "$2"
else
echo "$1"
fi
}
setup_miniconda3() {
if ! [ -f "${CONDA}/bin/conda" ]; then
clr_green ">>> Downloading miniconda for $PLATFORM... "
echo "${CONDA}/bin/conda"
if [[ $PLATFORM == 'Linux' ]]; then
run "wget -nv https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh 2>&1 | tee -a ${LOG}"
handle_error "$?" "ERROR: Failed to download miniconda installation script" "$wget_output"
clr_green "DONE"
elif [[ $PLATFORM == 'Darwin' ]]; then
run "wget -nv https://repo.continuum.io/miniconda/Miniconda3-latest-MacOSX-x86_64.sh -O miniconda.sh 2>&1 | tee -a ${LOG}"
handle_error "$?" "ERROR: Failed to download miniconda installation script" "$wget_output"
clr_green "DONE"
else
handle_error "1" "OS not supported"
fi
clr_green ">>> Installing miniconda... "
run "bash miniconda.sh -b -p "${CONDA}" 2>&1 | tee -a ${LOG}"
handle_error "$?" "ERROR: Failed to install miniconda" "$install_output"
clr_green "DONE"
clr_green ">>> Updating miniconda packages and package information... "
run "${CONDA}/bin/conda update -q -y conda 2>&1 | tee -a ${LOG}"
handle_error "$?" "ERROR: Failed to update conda packages" "$conda_update_output"
clr_green "DONE"
clr_green ">>> Cleaning up miniconda installation files... "
run "rm -f miniconda.sh 2>&1 | tee -a ${LOG}"
handle_error "$?" "ERROR: Failed to remove miniconda.sh" "$clean_output"
clr_green "DONE"
fi
clr_green ">>> Collecting information about conda... "
run "${CONDA}/bin/conda info -a 2>&1 | tee -a ${LOG}"
handle_error "$?" "ERROR: Failed to collect information about conda" "$info_output"
clr_green "DONE"
}
setup_miniconda2() {
if ! [ -f "${CONDA}/bin/conda" ]; then
clr_green ">>> Downloading miniconda for $PLATFORM... "
echo "${CONDA}/bin/conda"
if [[ $PLATFORM == 'Linux' ]]; then
run "wget -nv https://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh -O miniconda.sh 2>&1 | tee -a ${LOG}"
handle_error "$?" "ERROR: Failed to download miniconda installation script" "$wget_output"
clr_green "DONE"
elif [[ $PLATFORM == 'Darwin' ]]; then
run "wget -nv https://repo.continuum.io/miniconda/Miniconda2-latest-MacOSX-x86_64.sh -O miniconda.sh 2>&1 | tee -a ${LOG}"
handle_error "$?" "ERROR: Failed to download miniconda installation script" "$wget_output"
clr_green "DONE"
else
handle_error "1" "OS not supported"
fi
clr_green ">>> Installing miniconda... "
run "bash miniconda.sh -b -p "${CONDA}" 2>&1 | tee -a ${LOG}"
handle_error "$?" "ERROR: Failed to install miniconda" "$install_output"
clr_green "DONE"
clr_green ">>> Updating miniconda packages and package information... "
run "${CONDA}/bin/conda update -q -y conda 2>&1 | tee -a ${LOG}"
handle_error "$?" "ERROR: Failed to update conda packages" "$conda_update_output"
clr_green "DONE"
clr_green ">>> Cleaning up miniconda installation files... "
run "rm -f miniconda.sh 2>&1 | tee -a ${LOG}"
handle_error "$?" "ERROR: Failed to remove miniconda.sh" "$clean_output"
clr_green "DONE"
fi
clr_green ">>> Collecting information about conda... "
run "${CONDA}/bin/conda info -a 2>&1 | tee -a ${LOG}"
handle_error "$?" "ERROR: Failed to collect information about conda" "$info_output"
clr_green "DONE"
}
create_env_qt4() {
# env_output=$("${CONDA}/bin/conda" env list | grep "test_${VERSION}")
# if [ $? == 0 ]; then
# # Env already created. Nothing to do
# echo >&2 "### Using existing conda environment test_${VERSION}."
# return 0
# fi
clr_green ">>> Creating test environment for version ${VERSION}... "
run "${CONDA}/bin/conda env remove -y -n test_${VERSION} || true"
run "${CONDA}/bin/conda create -q -y -n test_${VERSION} python=${VERSION} pip=10 pyqt=4 qt=4 numpy=1.16.4 six lxml coverage scikit-bio biopython=1.74 scipy=1.2.1"
clr_green "DONE"
}
create_env() {
# env_output=$("${CONDA}/bin/conda" env list | grep "test_${VERSION}")
# if [ $? == 0 ]; then
# # Env already created. Nothing to do
# echo >&2 "### Using existing conda environment test_${VERSION}."
# return 0
# fi
clr_green ">>> Creating test environment for version ${VERSION}... "
run "${CONDA}/bin/conda env remove -y -n test_${VERSION} || true"
run "${CONDA}/bin/conda create -q -y -n test_${VERSION} python=${VERSION} pyqt numpy six lxml coverage scikit-bio biopython scipy"
clr_green "DONE"
# clr_green ">>> Updating conda packages in environment test_${VERSION}... "
# run "source ${CONDA}/bin/activate test_${VERSION} 2>&1 && ${CONDA}/bin/conda update -y --all 2>&1 | tee -a ${LOG}"
# handle_error "$?" "ERROR: Failed to update packages in the conda environment" "$update_conda_output"
# clr_green "DONE"
}
create_env_27() {
clr_green ">>> Creating test environment for version ${VERSION}... "
run "${CONDA}/bin/conda env remove -y -n test_${VERSION} || true"
run "${CONDA}/bin/conda create -q -y -n test_${VERSION} python=${VERSION} pyqt qt numpy six lxml coverage scikit-bio biopython scipy -c conda-forge"
clr_green "DONE"
}
install_external_apps() {
if [ "$EXTERNAL_APPS" == "1" ]; then
clear_green ">>> Installing external packages in environment test_${VERSION}... "
run "${CONDA}/bin/activate test_${VERSION} 2>&1 && ${CONDA}/bin/conda install -c etetoolkit ete3_external_apps -y 2>&1 | tee -a ${LOG}"
handle_error "$?" "ERROR: Failed to install ete3 external apps in the conda environment" "$external_apps_output"
clear_green "DONE"
fi
}
install_ete() {
clr_green ">>> Installing latest ete in test environment... "
run "source ${CONDA}/bin/activate test_${VERSION} 2>&1 && python setup.py install --donottrackinstall 2>&1 | tee -a ${LOG}"
handle_error "$?" "ERROR: Failed to install/update ete to the latest commit on test_${VERSION}" "$update_output"
clr_green "DONE"
}
showlog() {
if [ "$SHOWLOG" == "1" ]; then
echo -e ">>> Showing contents of test log:\n"
[ -f "${LOG}" ] && cat "${LOG}"
fi
}
run_tests() {
#clr_green ">>> Obtaining deployed python version... "
#run "${CONDA}/bin/activate test_${VERSION} &>/dev/null && python --version 2>&1"
#handle_error "$?" "ERROR: couldn't obtain python version" "$py_version_output"
#echo "DONE"
clr_green ">>> Obtaining ete3 version... "
run "source ${CONDA}/bin/activate test_${VERSION} &>/dev/null && ete3 version 2>&1"
handle_error "$?" "ERROR: couldn't obtain ete3 version" "$ete_version_output"
echo "DONE"
clr_green ">>> Running tests on ete ${ete_version_output} using ${py_version_output}... "
run "source ${CONDA}/bin/activate test_${VERSION} 2>&1 && coverage run -m ete3.test.test_${TESTSET}"
handle_error "$?" "ERROR: One or more tests failed on test_${VERSION}" "$tests_output"
echo "DONE"
echo "### All tests passed successfully"
}
# Location of current script
FILEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
EXTERNAL_APPS=0
SETUP=1
TEST=1
QT4=0
# Logfile
NULL_LOG="/dev/null"
LOG="${NULL_LOG}"
DEFAULT_LOG="${FILEDIR}/tests.log"
SHOWLOG=0
# Parse args using getopt (instead of getopts) to allow arguments before options
if [[ $PLATFORM == 'Linux' ]]; then
ARGS="$(getopt -o v:lshx -l help,test-only,setup-only,qt4 -n "$0" -- "$@" 2>/dev/null)"
elif [[ $PLATFORM == 'Darwin' ]]; then
ARGS="$(/usr/local/opt/gnu-getopt/bin/getopt -o v:lshx -l help,test-only,setup-only,qt4 -n "$0" -- "$@" 2>/dev/null)"
else
handle_error "1" "OS not supported"
fi
if [ "$?" != "0" ]; then
usage
handle_error "1" "ERROR: Check the arguments passed. At least one was not valid."
fi
# reorganize arguments as returned by getopt
eval set -- "$ARGS"
echo OPTIONS:$ARGS
while true; do
case "$1" in
# Shift before to throw away option
# Shift after if option has a required positional argument
-l)
shift
LOG="${DEFAULT_LOG}"
;;
-s)
shift
SHOWLOG=1
LOG="${DEFAULT_LOG}"
;;
-v)
shift
# Validate provided python version to use for tests
VERSION="$1"
shift
;;
-x)
shift
EXTERNAL_APPS=1
;;
--setup-only) # setup/install only
shift
TEST=0
;;
--test-only) # test only
shift
SETUP=0
;;
--qt4) # qt4
shift
QT4=1
;;
-h|--help)
usage
exit
;;
--)
shift
break
;;
esac
done
VERSION="$(valid_version "${VERSION}" 3.5)"
TESTSET="$(optional "$1" api)"
SLEEP=2 # Time to wait for xvfb to start and be functional
[ ! -f "ete3/test/test_${TESTSET}.py" ] && usage && handle_error "1" "ERROR: Invalid testset selected ${TESTSET}"
if [ "${LOG}" == "${NULL_LOG}" ]; then
echo "### Running ${TESTSET} tests with Python ${VERSION}"
else
echo "### Running ${TESTSET} tests with Python ${VERSION} and logging to ${LOG}"
fi
# Empty logfile
echo -n > "${LOG}"
# At any of these signals conditionally show the contents of the logfile
trap 'exitcode=$? ; showlog ; exit $exitcode' EXIT HUP INT QUIT TERM
if [ "$VERSION" == "2.7" ]; then
CONDA="${FILEDIR}/test_tmp/miniconda2"
else
CONDA="${FILEDIR}/test_tmp/miniconda3"
fi
if [ "${SETUP}" == "1" ]; then
if [ "$QT4" == "1" ]; then
setup_miniconda3
create_env_qt4
elif [ "$VERSION" == "2.7" ]; then
setup_miniconda2
create_env_27
else
setup_miniconda3
create_env
fi
install_external_apps
install_ete
fi
if [ "${TEST}" == "1" ]; then
run_tests
fi
showlog