Skip to content

Commit 4c92d31

Browse files
authored
Merge pull request #141 from tomato42/instrumental
Add condition coverage
2 parents 188f09e + 31a1f73 commit 4c92d31

File tree

3 files changed

+125
-3
lines changed

3 files changed

+125
-3
lines changed

.travis.yml

Lines changed: 61 additions & 3 deletions
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
@@ -39,13 +42,68 @@ matrix:
3942
allow_failures:
4043
- python: nightly
4144

45+
# for instrumental we're checking if the coverage changed from base branch
46+
# so collect that info
47+
before_install:
48+
- |
49+
echo -e "TRAVIS_PULL_REQUEST=$TRAVIS_PULL_REQUEST\n" \
50+
"TRAVIS_REPO_SLUG=$TRAVIS_REPO_SLUG\n" \
51+
"TRAVIS_PULL_REQUEST=$TRAVIS_PULL_REQUEST\n" \
52+
"TRAVIS_COMMIT=$TRAVIS_COMMIT\n" \
53+
"TRAVIS_PYTHON_VERSION=$TRAVIS_PYTHON_VERSION"
54+
- |
55+
# workaround https://github.com/travis-ci/travis-ci/issues/2666
56+
if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
57+
URL="https://github.com/${TRAVIS_REPO_SLUG}/pull/${TRAVIS_PULL_REQUEST}.patch"
58+
# `--location` makes curl follow redirects
59+
PR_FIRST=$(curl --silent --show-error --location $URL | head -1 | grep -o -E '\b[0-9a-f]{40}\b' | tr -d '\n')
60+
TRAVIS_COMMIT_RANGE=$PR_FIRST^..$TRAVIS_COMMIT
61+
fi
62+
# sanity check current commit
63+
- git rev-parse HEAD
64+
- echo "TRAVIS_COMMIT_RANGE=$TRAVIS_COMMIT_RANGE"
65+
- git fetch origin master:refs/remotes/origin/master
66+
67+
4268
install:
4369
- pip list
44-
- 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
70+
- |
71+
if [[ -e build-requirements-${TRAVIS_PYTHON_VERSION}.txt ]]; then
72+
travis_retry pip install -r build-requirements-${TRAVIS_PYTHON_VERSION}.txt;
73+
else
74+
travis_retry pip install -r build-requirements.txt;
75+
fi
76+
- if [[ $INSTRUMENTAL ]]; then travis_retry pip install instrumental; fi
4577
- pip list
4678
script:
47-
- tox -e $TOX_ENV
79+
- if [[ $TOX_ENV ]]; then tox -e $TOX_ENV; fi
4880
- tox -e speed
81+
- cp diff-instrumental.py diff-instrumental-2.py
82+
- |
83+
if [[ $INSTRUMENTAL && $TRAVIS_PULL_REQUEST != "false" ]]; then
84+
git checkout $PR_FIRST^
85+
# exclude the super slow test_malformed_sigs.py, until #127 is merged
86+
files="$(ls src/ecdsa/test*.py | grep -v test_malformed_sigs.py)"
87+
instrumental -t ecdsa -i 'test.*|.*_version' `which pytest` $files
88+
instrumental -f .instrumental.cov -s
89+
instrumental -f .instrumental.cov -s | python diff-instrumental-2.py --save .diff-instrumental
90+
git checkout $TRAVIS_COMMIT
91+
instrumental -t ecdsa -i 'test.*|.*_version' `which pytest` $files
92+
instrumental -f .instrumental.cov -sr
93+
fi
94+
- |
95+
if [[ $INSTRUMENTAL && $TRAVIS_PULL_REQUEST == "false" ]]; then
96+
# exclude the super slow test_malformed_sigs.py, until #127 is merged
97+
files="$(ls src/ecdsa/test*.py | grep -v test_malformed_sigs.py)"
98+
instrumental -t ecdsa -i 'test.*|.*_version' `which pytest` $files
99+
instrumental -f .instrumental.cov -s
100+
# just log the values when merging
101+
instrumental -f .instrumental.cov -s | python diff-instrumental-2.py
102+
fi
103+
- |
104+
if [[ $INSTRUMENTAL && $TRAVIS_PULL_REQUEST != "false" ]]; then
105+
instrumental -f .instrumental.cov -s | python diff-instrumental-2.py --read .diff-instrumental --fail-under 70 --max-difference -0.1
106+
fi
49107
after_success:
50-
- coveralls
108+
- if [[ -z $INSTRUMENTAL ]]; then coveralls; fi
51109

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
[![build status](https://travis-ci.org/warner/python-ecdsa.png)](http://travis-ci.org/warner/python-ecdsa)
44
[![Coverage Status](https://coveralls.io/repos/warner/python-ecdsa/badge.svg)](https://coveralls.io/r/warner/python-ecdsa)
5+
[![condition coverage](https://img.shields.io/badge/condition%20coverage-78%25-yellow)](https://travis-ci.org/warner/python-ecdsa/jobs/600079269#L1587)
56
[![Latest Version](https://img.shields.io/pypi/v/ecdsa.svg?style=flat)](https://pypi.python.org/pypi/ecdsa/)
67

78

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)