Skip to content

Commit 57fb3f4

Browse files
committed
add condition coverage
1 parent 5fa2fd8 commit 57fb3f4

File tree

2 files changed

+105
-1
lines changed

2 files changed

+105
-1
lines changed

.travis.yml

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ language: python
66
cache: pip
77
before_cache:
88
- rm -f $HOME/.cache/pip/log/debug.log
9+
# place the slowest (instrumental and py2.6) first
910
matrix:
1011
include:
12+
- python: 2.7
13+
env: INSTRUMENTAL=yes
1114
- python: 2.6
1215
env: TOX_ENV=py26
1316
- python: 2.7
@@ -29,13 +32,51 @@ matrix:
2932
- python: pypy3
3033
env: TOX_ENV=pypy3
3134

35+
# for instrumental we're checking if the coverage changed from base branch
36+
# so collect that info
37+
before_install:
38+
- |
39+
echo -e "TRAVIS_PULL_REQUEST=$TRAVIS_PULL_REQUEST\n" \
40+
"TRAVIS_REPO_SLUG=$TRAVIS_REPO_SLUG\n" \
41+
"TRAVIS_PULL_REQUEST=$TRAVIS_PULL_REQUEST\n" \
42+
"TRAVIS_COMMIT=$TRAVIS_COMMIT\n" \
43+
"TRAVIS_PYTHON_VERSION=$TRAVIS_PYTHON_VERSION"
44+
- |
45+
# workaround https://github.com/travis-ci/travis-ci/issues/2666
46+
if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
47+
URL="https://github.com/${TRAVIS_REPO_SLUG}/pull/${TRAVIS_PULL_REQUEST}.patch"
48+
# `--location` makes curl follow redirects
49+
PR_FIRST=$(curl --silent --show-error --location $URL | head -1 | grep -o -E '\b[0-9a-f]{40}\b' | tr -d '\n')
50+
TRAVIS_COMMIT_RANGE=$PR_FIRST^..$TRAVIS_COMMIT
51+
fi
52+
# sanity check current commit
53+
- git rev-parse HEAD
54+
- echo "TRAVIS_COMMIT_RANGE=$TRAVIS_COMMIT_RANGE"
55+
- git fetch origin master:refs/remotes/origin/master
56+
57+
3258
install:
3359
- pip list
3460
- if [[ -e build-requirements-${TRAVIS_PYTHON_VERSION}.txt ]]; then travis_retry pip install -r build-requirements-${TRAVIS_PYTHON_VERSION}.txt; else travis_retry pip install -r build-requirements.txt; fi
61+
- if [[ $INSTRUMENTAL ]]; then travis_retry pip install instrumental; fi
3562
- pip list
3663
script:
37-
- tox -e $TOX_ENV
64+
- if [[ $TOX_ENV ]]; then tox -e $TOX_ENV; fi
3865
- tox -e speed
66+
- cp diff-instrumental.py diff-instrumental-2.py
67+
- |
68+
if [[ $INSTRUMENTAL && $TRAVIS_PULL_REQUEST != "false" ]]; then
69+
git checkout $PR_FIRST^
70+
# exclude the super slow test_malformed_sigs.py, until #127 is merged
71+
files="src/ecdsa/test_der.py src/ecdsa/test_ecdsa.py src/ecdsa/test_ellipticcurve.py src/ecdsa/test_numbertheory.py src/ecdsa/test_pyecdsa.py"
72+
instrumental -t ecdsa -i 'test.*|.*_version' `which pytest` $files
73+
instrumental -f .instrumental.cov -s
74+
instrumental -f .instrumental.cov -s | python diff-instrumental-2.py --save .diff-instrumental
75+
git checkout $TRAVIS_COMMIT
76+
instrumental -t ecdsa -i 'test.*|.*_version' `which pytest` $files
77+
instrumental -f .instrumental.cov -sr
78+
instrumental -f .instrumental.cov -s | python diff-instrumental-2.py --read .diff-instrumental --fail-under 70 --max-difference 0.1
79+
fi
3980
after_success:
4081
- coveralls
4182

diff-instrumental.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
from __future__ import print_function
2+
import sys
3+
import getopt
4+
5+
fail_under = None
6+
max_difference = 0
7+
read_location = None
8+
save_location = None
9+
10+
argv = sys.argv[1:]
11+
12+
opts, args = getopt.getopt(
13+
argv, "s:r:",
14+
["fail-under=", "max-difference=", "save=", "read="])
15+
if args:
16+
raise ValueError("Unexpected parameters: {0}".format(args))
17+
for opt, arg in opts:
18+
if opt == "-s" or opt == "--save":
19+
save_location = arg
20+
elif opt == "-r" or opt == "--read":
21+
read_location = arg
22+
elif opt == "--fail-under":
23+
fail_under = float(arg)/100.0
24+
elif opt == "--max-difference":
25+
max_difference = float(arg)/100.0
26+
else:
27+
raise ValueError("Unknown option: {0}".format(opt))
28+
29+
total_hits = 0
30+
total_count = 0
31+
32+
for line in sys.stdin.readlines():
33+
if not line.startswith("ecdsa"):
34+
continue
35+
36+
fields = line.split()
37+
hit, count = fields[1].split('/')
38+
total_hits += int(hit)
39+
total_count += int(count)
40+
41+
coverage = total_hits * 1.0 / total_count
42+
43+
if read_location:
44+
with open(read_location, "r") as f:
45+
old_coverage = float(f.read())
46+
print("Old coverage: {0:6.2f}%".format(old_coverage*100))
47+
48+
if save_location:
49+
with open(save_location, "w") as f:
50+
f.write("{0:1.40f}".format(coverage))
51+
52+
print("Coverage: {0:6.2f}%".format(coverage*100))
53+
54+
if read_location:
55+
print("Difference: {0:6.2f}%".format((old_coverage - coverage)*100))
56+
57+
if fail_under and coverage < fail_under:
58+
print("ERROR: Insufficient coverage.", file=sys.stderr)
59+
sys.exit(1)
60+
61+
if read_location and coverage - old_coverage < max_difference:
62+
print("ERROR: Too big decrease in coverage", file=sys.stderr)
63+
sys.exit(1)

0 commit comments

Comments
 (0)