diff options
author | Alex Stapleton <alexs@prol.etari.at> | 2014-03-26 17:39:29 +0000 |
---|---|---|
committer | Alex Stapleton <alexs@prol.etari.at> | 2014-03-27 07:31:12 +0000 |
commit | 112963e296aadfdeaa4e2624c3b81b6b8c726a06 (patch) | |
tree | cd3c462d09860a8c01ad756acf60acb89b23fd1b /tests/test_utils.py | |
parent | 7a489dbd116edd4ca5a6104b74748f3a4f712d15 (diff) | |
download | cryptography-112963e296aadfdeaa4e2624c3b81b6b8c726a06.tar.gz cryptography-112963e296aadfdeaa4e2624c3b81b6b8c726a06.tar.bz2 cryptography-112963e296aadfdeaa4e2624c3b81b6b8c726a06.zip |
Address most of my own comments
Diffstat (limited to 'tests/test_utils.py')
-rw-r--r-- | tests/test_utils.py | 33 |
1 files changed, 32 insertions, 1 deletions
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 |