Skip to content

Commit 4fca61f

Browse files
authored
Merge pull request #217 from tomato42/py-spec-cover
Exclude version specific coverage
2 parents e223e8e + 7b04230 commit 4fca61f

File tree

5 files changed

+21
-17
lines changed

5 files changed

+21
-17
lines changed

src/ecdsa/_compat.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def str_idx_as_int(string, index):
1414
return ord(val)
1515

1616

17-
if sys.version_info < (3, 0):
17+
if sys.version_info < (3, 0): # pragma: no branch
1818

1919
def normalise_bytes(buffer_object):
2020
"""Cast the input into array of bytes."""
@@ -24,7 +24,11 @@ def normalise_bytes(buffer_object):
2424
def hmac_compat(ret):
2525
return ret
2626

27-
if sys.version_info < (2, 7) or sys.version_info < (2, 7, 4):
27+
if sys.version_info < (2, 7) or sys.version_info < ( # pragma: no branch
28+
2,
29+
7,
30+
4,
31+
):
2832

2933
def remove_whitespace(text):
3034
"""Removes all whitespace from passed in string"""
@@ -38,11 +42,11 @@ def remove_whitespace(text):
3842

3943

4044
else:
41-
if sys.version_info < (3, 4):
45+
if sys.version_info < (3, 4): # pragma: no branch
4246
# on python 3.3 hmac.hmac.update() accepts only bytes, on newer
4347
# versions it does accept memoryview() also
4448
def hmac_compat(data):
45-
if not isinstance(data, bytes):
49+
if not isinstance(data, bytes): # pragma: no branch
4650
return bytes(data)
4751
return data
4852

src/ecdsa/der.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ def remove_bitstring(string, expect_unused=_sentry):
386386

387387

388388
def unpem(pem):
389-
if isinstance(pem, text_type):
389+
if isinstance(pem, text_type): # pragma: no branch
390390
pem = pem.encode()
391391

392392
d = b("").join(

src/ecdsa/test_ecdh.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -300,18 +300,15 @@ def test_ecdh_with_openssl(vcurve):
300300

301301
if vcurve.openssl_name not in OPENSSL_SUPPORTED_CURVES:
302302
pytest.skip("system openssl does not support " + vcurve.openssl_name)
303-
return
304303

305304
try:
306305
hlp = run_openssl("pkeyutl -help")
307-
if hlp.find("-derive") == 0:
306+
if hlp.find("-derive") == 0: # pragma: no cover
308307
pytest.skip("system openssl does not support `pkeyutl -derive`")
309-
return
310-
except RunOpenSslError:
308+
except RunOpenSslError: # pragma: no cover
311309
pytest.skip("system openssl does not support `pkeyutl -derive`")
312-
return
313310

314-
if os.path.isdir("t"):
311+
if os.path.isdir("t"): # pragma: no branch
315312
shutil.rmtree("t")
316313
os.mkdir("t")
317314
run_openssl(
@@ -353,7 +350,7 @@ def test_ecdh_with_openssl(vcurve):
353350
run_openssl(
354351
"pkeyutl -derive -inkey t/privkey2.pem -peerkey t/pubkey1.pem -out t/secret2"
355352
)
356-
except RunOpenSslError:
353+
except RunOpenSslError: # pragma: no cover
357354
pytest.skip("system openssl does not support `pkeyutl -derive`")
358355
return
359356

@@ -362,7 +359,7 @@ def test_ecdh_with_openssl(vcurve):
362359
with open("t/secret1", "rb") as e:
363360
ssl_secret2 = e.read()
364361

365-
if len(ssl_secret1) != vk1.curve.baselen:
362+
if len(ssl_secret1) != vk1.curve.baselen: # pragma: no cover
366363
pytest.skip("system openssl does not support `pkeyutl -derive`")
367364
return
368365

src/ecdsa/util.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
oid_ecMQV = (1, 3, 132, 1, 13)
3535

36-
if sys.version_info >= (3,):
36+
if sys.version_info >= (3,): # pragma: no branch
3737

3838
def entropy_to_bits(ent_256):
3939
"""Convert a bytestring to string of 0's and 1's"""
@@ -47,7 +47,7 @@ def entropy_to_bits(ent_256):
4747
return "".join(bin(ord(x))[2:].zfill(8) for x in ent_256)
4848

4949

50-
if sys.version_info < (2, 7):
50+
if sys.version_info < (2, 7): # pragma: no branch
5151
# Can't add a method to a built-in type so we are stuck with this
5252
def bit_length(x):
5353
return len(bin(x)) - 2
@@ -99,7 +99,7 @@ def __init__(self, seed):
9999
def __call__(self, numbytes):
100100
a = [next(self.generator) for i in range(numbytes)]
101101

102-
if PY2:
102+
if PY2: # pragma: no branch
103103
return "".join(a)
104104
else:
105105
return bytes(a)

tox.ini

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ basepython=python3.9
5858
[testenv:coverage]
5959
sitepackages=True
6060
whitelist_externals=coverage
61-
commands = coverage run --branch -m pytest --hypothesis-show-statistics {posargs:src/ecdsa}
61+
commands =
62+
coverage run --branch -m pytest --hypothesis-show-statistics {posargs:src/ecdsa}
63+
coverage xml
64+
coverage report -m
6265

6366
[testenv:speed]
6467
commands = {envpython} speed.py

0 commit comments

Comments
 (0)