forked from m-lab/collectd-mlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runtests
executable file
·63 lines (53 loc) · 1.67 KB
/
runtests
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
#!/bin/bash
#
# runtests runs pylint and coverage checks on all *_test.py and tested modules.
#
# Normal operation is to execute runtests with no arguments. Optionally,
# runtests accepts a single argument for the name of a test file.
#
# Example:
# ./runtests config/mlab_test.py
#
# To report additional status information during the coverage report.
# DEBUG=1 ./runtests [test_file]
#
if test -z "$( type -p coverage )" ; then
echo "please install python-mock"
echo "please install python-coverage"
exit 1
fi
if test -z "$( type -p pylint )" ; then
echo "please install pylint"
exit 1
fi
# Only test the first command line argument (if present), otherwise test all
# files that end with _test.py.
TEST_FILES=${1:-$( find ./ -name "*_test.py" )}
# If DEBUG is set, enable verbose coverage status ("-v") during the run.
VERBOSE_COVERAGE=${DEBUG:+-v}
# Exit on first execution error.
set -e
# Set coverage reports output path to base directory for combination later.
export COVERAGE_FILE="$PWD/.coverage"
HTMLDIR="$PWD/coverage-report"
mkdir -p "${HTMLDIR}"
# Erase old reports.
coverage -e
rm -f .coverage*
for filename in ${TEST_FILES} ; do
# Run pylint on file and the test.
# A non-zero exit status will exit runtests.
echo "${filename}"
pylint ${filename/_test/}
pylint ${filename}
pushd $(dirname $filename) > /dev/null
# Run coverage on the test (which imports the file itself).
basefile=$(basename $filename)
echo coverage -p -x ${basefile} ${VERBOSE_COVERAGE}
coverage -p -x ${basefile} ${VERBOSE_COVERAGE}
popd > /dev/null
done
# Combine all reports above.
coverage -c
# Generate HTML report, storing output to HTMLDIR.
coverage -b -d "${HTMLDIR}"