diff options
author | Alex Stapleton <alexs@prol.etari.at> | 2014-03-27 16:38:00 +0000 |
---|---|---|
committer | Alex Stapleton <alexs@prol.etari.at> | 2014-03-27 16:38:00 +0000 |
commit | 5e4c8c3666860fbe7320ea2227428f530cc8f176 (patch) | |
tree | 0da4c43bf5c31f13b6cc6f677ce0d068ecaae055 /tests | |
parent | d80195e1712469ae59d1f9adc306ebfa23cfb59c (diff) | |
download | cryptography-5e4c8c3666860fbe7320ea2227428f530cc8f176.tar.gz cryptography-5e4c8c3666860fbe7320ea2227428f530cc8f176.tar.bz2 cryptography-5e4c8c3666860fbe7320ea2227428f530cc8f176.zip |
Fixes to @alex's comments
Diffstat (limited to 'tests')
-rw-r--r-- | tests/hazmat/backends/test_commoncrypto.py | 4 | ||||
-rw-r--r-- | tests/test_utils.py | 37 | ||||
-rw-r--r-- | tests/utils.py | 6 |
3 files changed, 25 insertions, 22 deletions
diff --git a/tests/hazmat/backends/test_commoncrypto.py b/tests/hazmat/backends/test_commoncrypto.py index 40a9f4a1..7c703f67 100644 --- a/tests/hazmat/backends/test_commoncrypto.py +++ b/tests/hazmat/backends/test_commoncrypto.py @@ -16,9 +16,7 @@ from __future__ import absolute_import, division, print_function import pytest from cryptography import utils -from cryptography.exceptions import ( - InternalError, _Reasons -) +from cryptography.exceptions import InternalError, _Reasons from cryptography.hazmat.bindings.commoncrypto.binding import Binding from cryptography.hazmat.primitives import interfaces from cryptography.hazmat.primitives.ciphers.algorithms import AES 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 diff --git a/tests/utils.py b/tests/utils.py index f948642e..3e5ea5f3 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -70,10 +70,12 @@ def check_backend_support(item): @contextmanager -def raises_unsupported_algorithm(cause): +def raises_unsupported_algorithm(reason): with pytest.raises(UnsupportedAlgorithm) as exc_info: yield exc_info - assert exc_info.value._cause is cause + + if exc_info.value._reason is not reason: + pytest.fail("Did not get expected reason tag for UnsupportedAlgorithm") def load_vectors_from_file(filename, loader): |