Skip to content

Commit 53d87a4

Browse files
committed
coverage: exclude environment branches in test cases
since some branching in hypothesis strategies and in handling different python, hypothesis, openssl and unittest versions is necessary, ignore them for branch coverage remove benchmarking code and dead code from test_pyecdsa.py (we have speed.py now) and exclude a disabled test case from coverage
1 parent 7d9c556 commit 53d87a4

File tree

5 files changed

+15
-31
lines changed

5 files changed

+15
-31
lines changed

src/ecdsa/test_ecdsa.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
HYP_SETTINGS = {}
1717
# old hypothesis doesn't have the "deadline" setting
18-
if sys.version_info > (2, 7):
18+
if sys.version_info > (2, 7): # pragma: no branch
1919
# SEC521p is slow, allow long execution for it
2020
HYP_SETTINGS["deadline"] = 5000
2121

src/ecdsa/test_ellipticcurve.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
try:
1010
from hypothesis import HealthCheck
1111
HC_PRESENT=True
12-
except ImportError:
12+
except ImportError: # pragma: no cover
1313
HC_PRESENT=False
1414
from .numbertheory import inverse_mod
1515
from .ellipticcurve import CurveFp, INFINITY, Point
1616

1717

1818
HYP_SETTINGS={}
19-
if HC_PRESENT:
19+
if HC_PRESENT: # pragma: no branch
2020
HYP_SETTINGS['suppress_health_check']=[HealthCheck.too_slow]
2121
HYP_SETTINGS['deadline'] = 5000
2222

src/ecdsa/test_malformed_sigs.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import hashlib
44
try:
55
from hashlib import algorithms_available
6-
except ImportError:
6+
except ImportError: # pragma: no cover
77
algorithms_available = [
88
"md5", "sha1", "sha224", "sha256", "sha384", "sha512"]
99
from functools import partial
@@ -82,7 +82,7 @@ def st_fuzzed_sig(draw, keys_and_sigs):
8282
note("Remove bytes: {0}".format(to_remove))
8383

8484
# decide which bytes of the original signature should be changed
85-
if sig:
85+
if sig: # pragma: no branch
8686
xors = draw(st.dictionaries(
8787
st.integers(min_value=0, max_value=len(sig)-1),
8888
st.integers(min_value=1, max_value=255)))
@@ -110,7 +110,7 @@ def st_fuzzed_sig(draw, keys_and_sigs):
110110

111111
params = {}
112112
# not supported in hypothesis 2.0.0
113-
if sys.version_info >= (2, 7):
113+
if sys.version_info >= (2, 7): # pragma: no branch
114114
from hypothesis import HealthCheck
115115
# deadline=5s because NIST521p are slow to verify
116116
params["deadline"] = 5000
@@ -180,7 +180,7 @@ def st_der_integer(*args, **kwargs):
180180
INTEGER.
181181
Parameters are passed to hypothesis.strategy.integer.
182182
"""
183-
if "min_value" not in kwargs:
183+
if "min_value" not in kwargs: # pragma: no branch
184184
kwargs["min_value"] = 0
185185
return st.builds(encode_integer, st.integers(*args, **kwargs))
186186

src/ecdsa/test_numbertheory.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
try:
1313
from hypothesis import HealthCheck
1414
HC_PRESENT=True
15-
except ImportError:
15+
except ImportError: # pragma: no cover
1616
HC_PRESENT=False
1717
from .numbertheory import (SquareRootError, factorization, gcd, lcm,
1818
jacobi, inverse_mod,
@@ -85,7 +85,7 @@ def st_two_nums_rel_prime(draw):
8585

8686
@st.composite
8787
def st_primes(draw, *args, **kwargs):
88-
if "min_value" not in kwargs:
88+
if "min_value" not in kwargs: # pragma: no branch
8989
kwargs["min_value"] = 1
9090
prime = draw(st.sampled_from(smallprimes) |
9191
st.integers(*args, **kwargs)
@@ -161,7 +161,7 @@ def st_comp_no_com_fac(draw):
161161

162162

163163
HYP_SETTINGS = {}
164-
if HC_PRESENT:
164+
if HC_PRESENT: # pragma: no branch
165165
HYP_SETTINGS['suppress_health_check']=[HealthCheck.filter_too_much,
166166
HealthCheck.too_slow]
167167
# the factorization() sometimes takes a long time to finish

src/ecdsa/test_pyecdsa.py

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ def run_openssl(cmd):
5252
return stdout.decode()
5353

5454

55-
BENCH = False
56-
57-
5855
class ECDSA(unittest.TestCase):
5956
def test_basic(self):
6057
priv = SigningKey.generate()
@@ -103,8 +100,6 @@ def test_lengths(self):
103100
self.assertEqual(len(pub.to_string()), default.verifying_key_length)
104101
sig = priv.sign(b("data"))
105102
self.assertEqual(len(sig), default.signature_length)
106-
if BENCH:
107-
print_()
108103
for curve in (NIST192p, NIST224p, NIST256p, NIST384p, NIST521p,
109104
BRAINPOOLP160r1, BRAINPOOLP192r1, BRAINPOOLP224r1,
110105
BRAINPOOLP256r1, BRAINPOOLP320r1, BRAINPOOLP384r1,
@@ -121,13 +116,6 @@ def test_lengths(self):
121116
sig = priv.sign(b("data"))
122117
sign_time = time.time() - start
123118
self.assertEqual(len(sig), curve.signature_length)
124-
if BENCH:
125-
start = time.time()
126-
pub1.verify(sig, b("data"))
127-
verify_time = time.time() - start
128-
print_("%s: siglen=%d, keygen=%0.3fs, sign=%0.3f, verify=%0.3f" \
129-
% (curve.name, curve.signature_length,
130-
keygen_time, sign_time, verify_time))
131119

132120
def test_serialize(self):
133121
seed = b("secret")
@@ -177,10 +165,6 @@ def assertTruePrivkeysEqual(self, priv1, priv2):
177165
self.assertEqual(priv1.privkey.public_key.generator,
178166
priv2.privkey.public_key.generator)
179167

180-
def failIfPrivkeysEqual(self, priv1, priv2):
181-
self.failIfEqual(priv1.privkey.secret_multiplier,
182-
priv2.privkey.secret_multiplier)
183-
184168
def test_privkey_creation(self):
185169
s = b("all the entropy in the entire world, compressed into one line")
186170

@@ -729,9 +713,9 @@ def get_openssl_messagedigest_arg(self):
729713
# e.g. "OpenSSL 1.0.0 29 Mar 2010", or "OpenSSL 1.0.0a 1 Jun 2010",
730714
# or "OpenSSL 0.9.8o 01 Jun 2010"
731715
vs = v.split()[1].split(".")
732-
if vs >= ["1", "0", "0"]:
716+
if vs >= ["1", "0", "0"]: # pragma: no cover
733717
return "-SHA1"
734-
else:
718+
else: # pragma: no cover
735719
return "-ecdsa-with-SHA1"
736720

737721
# sk: 1:OpenSSL->python 2:python->OpenSSL
@@ -809,7 +793,7 @@ def do_test_from_openssl(self, curve):
809793
# OpenSSL: create sk, vk, sign.
810794
# Python: read vk(3), checksig(5), read sk(1), sign, check
811795
mdarg = self.get_openssl_messagedigest_arg()
812-
if os.path.isdir("t"):
796+
if os.path.isdir("t"): # pragma: no cover
813797
shutil.rmtree("t")
814798
os.mkdir("t")
815799
run_openssl("ecparam -name %s -genkey -out t/privkey.pem" % curvename)
@@ -904,7 +888,7 @@ def do_test_to_openssl(self, curve):
904888
# Python: create sk, vk, sign.
905889
# OpenSSL: read vk(4), checksig(6), read sk(2), sign, check
906890
mdarg = self.get_openssl_messagedigest_arg()
907-
if os.path.isdir("t"):
891+
if os.path.isdir("t"): # pragma: no cover
908892
shutil.rmtree("t")
909893
os.mkdir("t")
910894
sk = SigningKey.generate(curve=curve)
@@ -1019,7 +1003,7 @@ def test_randrange(self, i):
10191003
n = util.randrange(order, entropy=entropy)
10201004
self.assertTrue(1 <= n < order, (1, n, order))
10211005

1022-
def OFF_test_prove_uniformity(self):
1006+
def OFF_test_prove_uniformity(self): # pragma: no cover
10231007
order = 2**8 - 2
10241008
counts = dict([(i, 0) for i in range(1, order)])
10251009
assert 0 not in counts

0 commit comments

Comments
 (0)