-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathruntest
executable file
·102 lines (81 loc) · 3.84 KB
/
runtest
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
#!/bin/sh
DEFAULT_PRODUCTION_HOST="pavics.ouranos.ca"
NOTEBOOKS="$1"
if [ -z "$NOTEBOOKS" ]; then
NOTEBOOKS="notebooks/*.ipynb"
fi
set -x
if [ -n "$FORCE_PAVICS_HOST" ]; then
# jenkins work-around for envinject incompatibility with pipeline
echo "FORCE_PAVICS_HOST='$FORCE_PAVICS_HOST'"
echo "Overriding PAVICS_HOST with value from FORCE_PAVICS_HOST"
PAVICS_HOST="$FORCE_PAVICS_HOST"
fi
if [ ! -z "$PAVICS_HOST" ]; then
echo "Will run notebooks against $PAVICS_HOST"
if [ -z "$TEST_NO_USE_PROD_DATA" ]; then
# * .ncml links will always comes from the production server, not the server
# under test since we do not perform regex replace for .ncml links.
#
# * Any lines marked with TEST_USE_PROD_DATA will also use data from prod
# and avoid having to replicate data to test servers.
sed -i "/\(\.ncml\|TEST_USE_PROD_DATA\)/!s/$DEFAULT_PRODUCTION_HOST/$PAVICS_HOST/g" $NOTEBOOKS
else
# Change everything to $PAVICS_HOST (system under test).
sed -i "s/$DEFAULT_PRODUCTION_HOST/$PAVICS_HOST/g" $NOTEBOOKS
fi
git diff # not working for notebooks from other repos
fi
# suppress "InsecureRequestWarning: Unverified HTTPS request is being made"
# so tests still pass when user want to disable ssl cert verification
export PYTHONWARNINGS="ignore:Unverified HTTPS request"
# Allow full override of ALL configs before running test suite.
if [ -n "$CONFIG_OVERRIDE_SCRIPT_URL" ]; then
TMP_CONF_OVERRIDE="/tmp/conf_override"
rm -vf "$TMP_CONF_OVERRIDE"
if echo "$CONFIG_OVERRIDE_SCRIPT_URL" | grep -e ^http ; then
# Use tee to log content of override script for traceability.
curl --silent "$CONFIG_OVERRIDE_SCRIPT_URL" | tee "$TMP_CONF_OVERRIDE"
else
# Not starting with http, it's a local file.
# Local file can be previously created by CONFIG_PARAMETERS_SCRIPT_URL.
# See example in test-override/jenkins-params-raven-specific-nb.include.sh.
TMP_CONF_OVERRIDE="$CONFIG_OVERRIDE_SCRIPT_URL"
# Log content of override script for traceability.
cat "$TMP_CONF_OVERRIDE"
fi
# Source script so it can alter ALL existing variables in the current context.
if [ -f "$TMP_CONF_OVERRIDE" ]; then
. "$TMP_CONF_OVERRIDE"
fi
fi
py.test --nbval $NOTEBOOKS --nbval-sanitize-with notebooks/output-sanitize.cfg $PYTEST_EXTRA_OPTS
EXIT_CODE="$?"
# lowercase SAVE_RESULTING_NOTEBOOK string
SAVE_RESULTING_NOTEBOOK="`echo "$SAVE_RESULTING_NOTEBOOK" | tr '[:upper:]' '[:lower:]'`"
# save notebooks resulting from the run
# this might not be the same as what py.test have seen since it's another run
# user can manually diff the original with the resulting notebooks this way:
# nbdiff original.ipynb resulting.ipynb.output.ipynb (conda install nbdime)
# work-around as nbval can not save the result of the run
# see https://github.com/computationalmodelling/nbval/issues/112
if [ x"$SAVE_RESULTING_NOTEBOOK" = xtrue ]; then
mkdir -p buildout
for nb in $NOTEBOOKS; do
filename="`basename "$nb"`"
filename="`echo "$filename" | sed "s/.ipynb$//"`" # remove .ipynb ext
if [ -e "buildout/${filename}.output.ipynb" ]; then
# prevent name clash
filename="${filename}_`date '+%s'`"
fi
# Timeout must not be more than 240s (4 mins). Default in Jenkinsfile.
# Tutorial notebooks should be fast so user do not lose patience waiting
# for them to run. If more than 4 mins, in addition to simplifying the
# notebook, should also check machine performance.
jupyter nbconvert --to notebook --execute \
--ExecutePreprocessor.timeout=${SAVE_RESULTING_NOTEBOOK_TIMEOUT:=240} --allow-errors \
--output-dir buildout --output "${filename}.output.ipynb" "$nb"
done
fi
# exit with return code from py.test
exit $EXIT_CODE