forked from emsig/empymod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruntests.sh
executable file
·114 lines (96 loc) · 2.43 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
#!/bin/bash
# Help text
usage="
$(basename "$0") [-hcpmdw] [-v VERSION(S)]
Run pytest for empymod locally in an isolated venv before submitting to
GitHub/Travis-CI; by default for all supported python versions of empymod.
where:
-h : Show this help text.
-v : Python 3.x version, e.g. '-v 7' for Python 3.7. Default: '6 7 8'.
-c : Use channel 'conda-forge' instead of channel 'defaults'.
-p : Print output of conda.
-m : Run tests without matplotlib/IPython.
-d : Delete environments after tests
-w : Disable warnings
"
# Set default values
CHAN=defaults
PYTHON3VERSION="6 7 8"
PRINT="/dev/null"
PCKGS="numpy scipy numba pytest pytest-cov"
MPLIPY="matplotlib IPython"
STR2="** WITH matplotlib/IPython "
PROPS="--mpl --flake8"
INST="pytest-flake8 pytest-mpl scooby"
SD="_soft-dep"
WARN=""
# Get Optional Input
while getopts "hv:cpmdw" opt; do
case $opt in
h) echo "$usage"
exit
;;
v) PYTHON3VERSION=$OPTARG
;;
c) CHAN=conda-forge
;;
p) PRINT="/dev/tty"
;;
m) MPLIPY=""
STR2="** NO matplotlib/IPython "
PROPS="--flake8"
INST="pytest-flake8"
SD=""
;;
d) DELETE=true
;;
w) WARN="--disable-warnings"
;;
:) printf "missing argument for -%s\n" "$OPTARG" >&2
echo "$usage" >&2
exit 1
;;
\?) printf "illegal option: -%s\n" "$OPTARG" >&2
echo "$usage" >&2
exit 1
;;
esac
done
# Loop over Python versions
for i in ${PYTHON3VERSION[@]}; do
# Environment name
NAME=test_3${i}_${CHAN}${SD}
# Print info
STR=" PYTHON 3.${i} ** Channel $CHAN $STR2"
LENGTH=$(( ($(tput cols) - ${#STR}) / 2 - 2 ))
printf "\n "
printf '\e[1m\e[34m%*s' "${LENGTH}" '' | tr ' ' -
if [ $((${#STR}%2)) -ne 0 ];
then
printf "-"
fi
printf "${STR}"
printf '%*s\n' "${LENGTH}" '' | tr ' ' -
printf "\e[0m\n"
# Create venv, with channel CHAN
if [ ! -d "$HOME/anaconda3/envs/$NAME" ]; then
conda create -y -n $NAME -c $CHAN python=3.${i} $PCKGS $MPLIPY &> $PRINT
fi
# Activate venv
source activate $NAME
# Install flake8
if [ ! -d "$HOME/anaconda3/envs"+$NAME ]; then
pip install $INST &> $PRINT
fi
# Run tests
cp tests/matplotlibrc .
pytest --cov=empymod $PROPS $WARN
rm matplotlibrc
coverage html
# De-activate venv
conda deactivate
# Remove venv
if [ "$DELETE" = true ] ; then
conda remove -y -n $NAME --all &> $PRINT
fi
done