Skip to content

Commit eab6ac1

Browse files
author
Rebecka Gulliksson
committed
Cleanup of tests expecting an exception (using py.test instead or rewritten).
1 parent 5d5bf58 commit eab6ac1

1 file changed

Lines changed: 8 additions & 19 deletions

File tree

tests/test_2_jwk.py

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from jwkest.jwk import RSAKey
2020
from jwkest.jwk import base64_to_long
2121
import os.path
22+
import pytest
2223

2324
__author__ = 'rohe0002'
2425
BASEDIR = os.path.abspath(os.path.dirname(__file__))
@@ -54,14 +55,12 @@ def test_urlsafe_base64decode():
5455
s0 = base64.b64encode(data)
5556
# try to convert it back to long, should throw an exception if the strict
5657
# function is used
57-
try:
58-
l = base64url_to_long(s0)
59-
except ValueError:
60-
pass
61-
else:
62-
assert False
63-
# Not else
58+
with pytest.raises(ValueError):
59+
base64url_to_long(s0)
60+
61+
# Not else, should not raise exception
6462
l = base64_to_long(s0)
63+
assert l
6564

6665

6766
def test_pem_cert2rsa():
@@ -238,25 +237,15 @@ def test_cmp_rsa_ec():
238237

239238
_key2 = ECKey(**ECKEY)
240239

241-
try:
242-
assert _key1 == _key2
243-
except AssertionError:
244-
pass
245-
else:
246-
assert False
240+
assert _key1 != _key2
247241

248242

249243
def test_cmp_neq_ec():
250244
priv, pub = P256.key_pair()
251245
_key1 = ECKey(x=pub[0], y=pub[1], d=priv, crv="P-256")
252246
_key2 = ECKey(**ECKEY)
253247

254-
try:
255-
assert _key1 == _key2
256-
except AssertionError:
257-
pass
258-
else:
259-
assert False
248+
assert _key1 != _key2
260249

261250

262251
JWKS = {"keys": [

0 commit comments

Comments
 (0)