This repository has been archived by the owner on Dec 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 239
/
runtests.sh
executable file
·122 lines (106 loc) · 2.39 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
#!/bin/bash
#
# Run the Pyflame test suite.
#
# If invoked without arguments, this will make a best effort to run the test
# suite against python2 and python3. If you would like to force the test suite
# to run against a specific version of python, invoke with the python
# interpreter names as arguments. These should be strings suitable for passing
# to virtualenv -p.
set -e
ENVDIR="./.test_env"
trap 'rm -rf ${ENVDIR}' EXIT
VERBOSE=0
export PYMAJORVERSION
while getopts ":hvx" opt; do
case $opt in
h)
echo "Usage: $0 [-h] [-x] python..."
exit 1
;;
v)
VERBOSE=1
;;
x)
set -x
;;
\?)
echo "Invalid option: -$OPTARG" >&2
;;
esac
done
shift "$((OPTIND-1))"
exists() {
command -v "$1" &>/dev/null
}
pytest() {
if [ "$VERBOSE" -eq 0 ]; then
py.test -q "$@"
else
py.test -v "$@"
fi
}
mkvenv() {
if exists virtualenv-3; then
virtualenv-3 "$@"
elif exists virtualenv; then
virtualenv "$@"
else
echo "failed to find virtualenv command"
exit 1
fi
}
# Run tests using pip; $1 = python version
run_pip_tests() {
local activated
if [ -z "${VIRTUAL_ENV}" ]; then
rm -rf "${ENVDIR}"
mkvenv -q -p "$1" "${ENVDIR}" &>/dev/null
# shellcheck source=/dev/null
. "${ENVDIR}/bin/activate"
activated=1
else
echo "Warning: reusing virtualenv"
fi
PYMAJORVERSION=$(python -c 'import sys; print(sys.version_info[0])')
echo "Running test suite against interpreter $("$1" --version 2>&1)"
find tests/ -name '*.pyc' -delete
pip install -q pytest
pytest -v tests/
if [ "$activated" -eq 1 ]; then
deactivate
fi
}
# Make a best effort to run the tests against some Python version.
try_pip_tests() {
if command -v "$1" &>/dev/null; then
run_pip_tests "$1"
else
echo "skipping $1 tests (no such command)"
fi
}
# Tests run when building RPMs are not allowed to use virtualenv.
run_rpm_tests() {
for pytest in py.test-2 py.test-2.7; do
if exists "$pytest"; then
PYMAJORVERSION=2 "$pytest" -v tests/
break
fi
done
for pytest in py.test-3 py.test-3.4; do
if exists "$pytest"; then
PYMAJORVERSION=3 "$pytest" -v tests/
break
fi
done
}
if [ $# -eq 0 ]; then
PYMAJORVERSION=2 try_pip_tests python2
PYMAJORVERSION=3 try_pip_tests python3
elif [ "$1" = "rpm" ]; then
run_rpm_tests
else
for py in "$@"; do
run_pip_tests "$py"
done
fi