From 8d10a1366ac4059ef07f3babb263b1c5397fa8e5 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Sat, 25 Oct 2014 21:39:35 -0700 Subject: fix coverage for backend parametrization Any test that takes a backend is required to provide the requires_backend_interface decorator. --- tests/conftest.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/conftest.py b/tests/conftest.py index 9dc37d38..27cf13b0 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -27,17 +27,12 @@ def pytest_generate_tests(metafunc): if "backend" in metafunc.fixturenames: filtered_backends = [] for backend in selected_backends: - try: - required = metafunc.function.requires_backend_interface - except AttributeError: - # function does not have requires_backend_interface decorator + required = metafunc.function.requires_backend_interface + required_interfaces = tuple( + mark.kwargs["interface"] for mark in required + ) + if isinstance(backend, required_interfaces): filtered_backends.append(backend) - else: - required_interfaces = tuple( - mark.kwargs["interface"] for mark in required - ) - if isinstance(backend, required_interfaces): - filtered_backends.append(backend) # If you pass an empty list to parametrize Bad Things(tm) happen # as of pytest 2.6.4 when the test also has a parametrize decorator -- cgit v1.2.3 From 22eb4c91914cd2f0ad2cb67ad27e5bfb60400492 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Mon, 27 Oct 2014 10:24:43 -0700 Subject: Added attributes that are part of hte interface to several test fakes --- tests/hazmat/backends/test_commoncrypto.py | 1 + tests/hazmat/backends/test_openssl.py | 3 +++ tests/hazmat/primitives/test_block.py | 1 + tests/hazmat/primitives/test_ec.py | 2 +- tests/hazmat/primitives/test_hashes.py | 2 ++ tests/hazmat/primitives/test_hmac.py | 2 ++ tests/hazmat/primitives/test_pbkdf2hmac.py | 2 ++ 7 files changed, 12 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/hazmat/backends/test_commoncrypto.py b/tests/hazmat/backends/test_commoncrypto.py index 28d1a6ca..6bb0ede0 100644 --- a/tests/hazmat/backends/test_commoncrypto.py +++ b/tests/hazmat/backends/test_commoncrypto.py @@ -30,6 +30,7 @@ from ...utils import raises_unsupported_algorithm class DummyCipher(object): name = "dummy-cipher" block_size = 128 + digest_size = None @pytest.mark.skipif("commoncrypto" not in diff --git a/tests/hazmat/backends/test_openssl.py b/tests/hazmat/backends/test_openssl.py index 39708f82..ebd8686c 100644 --- a/tests/hazmat/backends/test_openssl.py +++ b/tests/hazmat/backends/test_openssl.py @@ -52,6 +52,7 @@ class DummyMode(object): @utils.register_interface(interfaces.CipherAlgorithm) class DummyCipher(object): name = "dummy-cipher" + key_size = None @utils.register_interface(interfaces.AsymmetricPadding) @@ -62,6 +63,8 @@ class DummyPadding(object): @utils.register_interface(interfaces.HashAlgorithm) class DummyHash(object): name = "dummy-hash" + block_size = None + digest_size = None class DummyMGF(object): diff --git a/tests/hazmat/primitives/test_block.py b/tests/hazmat/primitives/test_block.py index 6ee230a7..14f76758 100644 --- a/tests/hazmat/primitives/test_block.py +++ b/tests/hazmat/primitives/test_block.py @@ -44,6 +44,7 @@ class DummyMode(object): @utils.register_interface(interfaces.CipherAlgorithm) class DummyCipher(object): name = "dummy-cipher" + key_size = None @pytest.mark.requires_backend_interface(interface=CipherBackend) diff --git a/tests/hazmat/primitives/test_ec.py b/tests/hazmat/primitives/test_ec.py index decb3716..e6a9146c 100644 --- a/tests/hazmat/primitives/test_ec.py +++ b/tests/hazmat/primitives/test_ec.py @@ -68,7 +68,7 @@ class DummyCurve(object): @utils.register_interface(interfaces.EllipticCurveSignatureAlgorithm) class DummySignatureAlgorithm(object): - pass + algorithm = None @utils.register_interface(EllipticCurveBackend) diff --git a/tests/hazmat/primitives/test_hashes.py b/tests/hazmat/primitives/test_hashes.py index ba4f53af..0fdd7550 100644 --- a/tests/hazmat/primitives/test_hashes.py +++ b/tests/hazmat/primitives/test_hashes.py @@ -33,6 +33,8 @@ from ...utils import raises_unsupported_algorithm @utils.register_interface(interfaces.HashAlgorithm) class UnsupportedDummyHash(object): name = "unsupported-dummy-hash" + block_size = None + digest_size = None @pytest.mark.requires_backend_interface(interface=HashBackend) diff --git a/tests/hazmat/primitives/test_hmac.py b/tests/hazmat/primitives/test_hmac.py index baf8a299..3553632c 100644 --- a/tests/hazmat/primitives/test_hmac.py +++ b/tests/hazmat/primitives/test_hmac.py @@ -33,6 +33,8 @@ from ...utils import raises_unsupported_algorithm @utils.register_interface(interfaces.HashAlgorithm) class UnsupportedDummyHash(object): name = "unsupported-dummy-hash" + block_size = None + digest_size = None @pytest.mark.supported( diff --git a/tests/hazmat/primitives/test_pbkdf2hmac.py b/tests/hazmat/primitives/test_pbkdf2hmac.py index e928fc6a..c140c14d 100644 --- a/tests/hazmat/primitives/test_pbkdf2hmac.py +++ b/tests/hazmat/primitives/test_pbkdf2hmac.py @@ -31,6 +31,8 @@ from ...utils import raises_unsupported_algorithm @utils.register_interface(interfaces.HashAlgorithm) class DummyHash(object): name = "dummy-hash" + block_size = None + digest_size = None class TestPBKDF2HMAC(object): -- cgit v1.2.3