From 112963e296aadfdeaa4e2624c3b81b6b8c726a06 Mon Sep 17 00:00:00 2001 From: Alex Stapleton Date: Wed, 26 Mar 2014 17:39:29 +0000 Subject: Address most of my own comments --- tests/test_utils.py | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'tests/test_utils.py') diff --git a/tests/test_utils.py b/tests/test_utils.py index b63f1bab..a8046dc3 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -21,13 +21,15 @@ import pretend import pytest import cryptography +from cryptography.exceptions import UnsupportedAlgorithm, _Reasons + import cryptography_vectors from .utils import ( check_backend_support, check_for_iface, load_cryptrec_vectors, load_fips_dsa_key_pair_vectors, load_hash_vectors, load_nist_vectors, load_pkcs1_vectors, load_rsa_nist_vectors, load_vectors_from_file, - select_backends + raises_unsupported_algorithm, select_backends ) @@ -1608,3 +1610,32 @@ de61329a78d526f65245380ce877e979c5b50de66c9c30d66382c8f254653d25a1eb1d3a4897d7\ def test_vector_version(): assert cryptography.__version__ == cryptography_vectors.__version__ + + +def test_raises_unsupported_algorithm_wrong_type(): + # Check that it asserts if the wrong type of exception is raised. + + class TestException(Exception): + pass + + with pytest.raises(TestException): + with raises_unsupported_algorithm(None): + raise TestException + + +def test_raises_unsupported_algorithm_wrong_reason(): + # Check that it asserts if the wrong reason code is raised. + with pytest.raises(AssertionError): + with raises_unsupported_algorithm(None): + raise UnsupportedAlgorithm("An error.", + _Reasons.BACKEND_MISSING_INTERFACE) + + +def test_raises_unsupported_algorithm(): + # Check that it doesnt assert if the right things are raised. + with raises_unsupported_algorithm( + _Reasons.BACKEND_MISSING_INTERFACE + ) as exc: + raise UnsupportedAlgorithm("An error.", + _Reasons.BACKEND_MISSING_INTERFACE) + assert exc -- cgit v1.2.3 From d80195e1712469ae59d1f9adc306ebfa23cfb59c Mon Sep 17 00:00:00 2001 From: Alex Stapleton Date: Wed, 26 Mar 2014 20:41:31 +0000 Subject: Update tests --- tests/test_utils.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'tests/test_utils.py') diff --git a/tests/test_utils.py b/tests/test_utils.py index a8046dc3..b430f567 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1612,23 +1612,28 @@ def test_vector_version(): assert cryptography.__version__ == cryptography_vectors.__version__ +@pytest.mark.xfail def test_raises_unsupported_algorithm_wrong_type(): # Check that it asserts if the wrong type of exception is raised. - - class TestException(Exception): - pass - - with pytest.raises(TestException): - with raises_unsupported_algorithm(None): - raise TestException + with raises_unsupported_algorithm(None): + raise Exception +@pytest.mark.xfail def test_raises_unsupported_algorithm_wrong_reason(): # Check that it asserts if the wrong reason code is raised. - with pytest.raises(AssertionError): - with raises_unsupported_algorithm(None): - raise UnsupportedAlgorithm("An error.", - _Reasons.BACKEND_MISSING_INTERFACE) + with raises_unsupported_algorithm(None): + raise UnsupportedAlgorithm("An error.", + _Reasons.BACKEND_MISSING_INTERFACE) + + +@pytest.mark.xfail +def test_raises_unsupported_no_exc(): + # Check that it raises if no exception is raised. + with raises_unsupported_algorithm( + _Reasons.BACKEND_MISSING_INTERFACE + ): + pass def test_raises_unsupported_algorithm(): -- cgit v1.2.3 From 5e4c8c3666860fbe7320ea2227428f530cc8f176 Mon Sep 17 00:00:00 2001 From: Alex Stapleton Date: Thu, 27 Mar 2014 16:38:00 +0000 Subject: Fixes to @alex's comments --- tests/test_utils.py | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) (limited to 'tests/test_utils.py') diff --git a/tests/test_utils.py b/tests/test_utils.py index b430f567..939845fc 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1612,35 +1612,38 @@ def test_vector_version(): assert cryptography.__version__ == cryptography_vectors.__version__ -@pytest.mark.xfail def test_raises_unsupported_algorithm_wrong_type(): - # Check that it asserts if the wrong type of exception is raised. - with raises_unsupported_algorithm(None): - raise Exception + # Check that it raises if the wrong type of exception is raised. + class TestException(Exception): + pass + + with pytest.raises(TestException): + with raises_unsupported_algorithm(None): + raise TestException -@pytest.mark.xfail def test_raises_unsupported_algorithm_wrong_reason(): - # Check that it asserts if the wrong reason code is raised. - with raises_unsupported_algorithm(None): - raise UnsupportedAlgorithm("An error.", - _Reasons.BACKEND_MISSING_INTERFACE) + # Check that it fails if the wrong reason code is raised. + with pytest.raises(pytest.fail.Exception): + with raises_unsupported_algorithm(None): + raise UnsupportedAlgorithm("An error.", + _Reasons.BACKEND_MISSING_INTERFACE) -@pytest.mark.xfail def test_raises_unsupported_no_exc(): - # Check that it raises if no exception is raised. - with raises_unsupported_algorithm( - _Reasons.BACKEND_MISSING_INTERFACE - ): - pass + # Check that it fails if no exception is raised. + with pytest.raises(pytest.fail.Exception): + with raises_unsupported_algorithm( + _Reasons.BACKEND_MISSING_INTERFACE + ): + pass def test_raises_unsupported_algorithm(): # Check that it doesnt assert if the right things are raised. with raises_unsupported_algorithm( _Reasons.BACKEND_MISSING_INTERFACE - ) as exc: + ) as exc_info: raise UnsupportedAlgorithm("An error.", _Reasons.BACKEND_MISSING_INTERFACE) - assert exc + assert exc_info.type is UnsupportedAlgorithm -- cgit v1.2.3 From 85a791f0fa061ec644f5bfca41ee6038eeef38eb Mon Sep 17 00:00:00 2001 From: Alex Stapleton Date: Thu, 27 Mar 2014 16:55:41 +0000 Subject: Pain the bikeshed a different colour --- tests/test_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/test_utils.py') diff --git a/tests/test_utils.py b/tests/test_utils.py index 939845fc..d0b70663 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1624,7 +1624,7 @@ def test_raises_unsupported_algorithm_wrong_type(): def test_raises_unsupported_algorithm_wrong_reason(): # Check that it fails if the wrong reason code is raised. - with pytest.raises(pytest.fail.Exception): + with pytest.raises(AssertionError): with raises_unsupported_algorithm(None): raise UnsupportedAlgorithm("An error.", _Reasons.BACKEND_MISSING_INTERFACE) -- cgit v1.2.3