forked from Yelp/pgctl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test
executable file
·55 lines (46 loc) · 1.47 KB
/
test
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
#!/bin/bash
set -eu
export TOP=$(dirname $(readlink -f $0))
export PROJECT=pgctl
export COVERAGE_PROCESS_START=$TOP/.coveragerc
combine() {
unset COVERAGE_PROCESS_START
coverage combine --rcfile=$TOP/.coveragerc
coverage html --rcfile=$TOP/.coveragerc
coverage report --rcfile=$TOP/.coveragerc --fail-under 100
}
fail() {
combine
echo '[31;1mFAIL[m'
}
trap fail ERR
# the travis default umask is 002, but ubuntu's is 022
umask 022
set -x
# See: https://bitbucket.org/ned/coveragepy/issue/340/keyerror-subpy
if [ -n "$VIRTUAL_ENV" -a -d $VIRTUAL_ENV/local ]; then
rm -rf $VIRTUAL_ENV/local
find $VIRTUAL_ENV -name '*.pyc' -print0 | xargs -0r rm
find $VIRTUAL_ENV -name '__pycache__' -print0 | xargs -0r rmdir
fi
# clean out any leftover coverage data
rm -f $TOP/.coverage.* $TOP/.coverage
# we actually do want to get coverage for our test-infra scripts:
# See: http://nedbatchelder.com/code/coverage/subprocess.html
$TOP/tests/testing/install_coverage_pth.py
# default arguments
if [ -z "$*" ]; then
NCPU=$(getconf _NPROCESSORS_CONF)
if "${CI:-false}"; then
# Under CI, we don't get to use all the CPU.
# NOTE: Parallelism is disabled in CI because coverage flakes (#176)
n=0
else
n=$((NCPU > 5? NCPU/5 : 1))
fi
set -- -n $n $TOP/tests $($TOP/tests/testing/get_modulefile.py $PROJECT)
# don't measure coverage during linting
COVERAGE_PROCESS_START= pre-commit run --all-files
fi
py.test "$@"
combine