aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_utils.py
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2014-03-27 11:04:21 -0700
committerAlex Gaynor <alex.gaynor@gmail.com>2014-03-27 11:04:21 -0700
commit3d5d6471b10e5f46eb8b40a9a41eb16e657d25b8 (patch)
tree8285f420269fd636e63c9152143750922e48e869 /tests/test_utils.py
parent844c14a15884fb60871640576e30a61e6c4c2db1 (diff)
parent85a791f0fa061ec644f5bfca41ee6038eeef38eb (diff)
downloadcryptography-3d5d6471b10e5f46eb8b40a9a41eb16e657d25b8.tar.gz
cryptography-3d5d6471b10e5f46eb8b40a9a41eb16e657d25b8.tar.bz2
cryptography-3d5d6471b10e5f46eb8b40a9a41eb16e657d25b8.zip
Merge pull request #849 from public/changeup-exceptions-2-electric-boogaloo
Use a single tagged exception instead of a hierarchy
Diffstat (limited to 'tests/test_utils.py')
-rw-r--r--tests/test_utils.py41
1 files changed, 40 insertions, 1 deletions
diff --git a/tests/test_utils.py b/tests/test_utils.py
index b63f1bab..d0b70663 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,40 @@ de61329a78d526f65245380ce877e979c5b50de66c9c30d66382c8f254653d25a1eb1d3a4897d7\
def test_vector_version():
assert cryptography.__version__ == cryptography_vectors.__version__
+
+
+def test_raises_unsupported_algorithm_wrong_type():
+ # 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
+
+
+def test_raises_unsupported_algorithm_wrong_reason():
+ # Check that it fails 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_no_exc():
+ # 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_info:
+ raise UnsupportedAlgorithm("An error.",
+ _Reasons.BACKEND_MISSING_INTERFACE)
+ assert exc_info.type is UnsupportedAlgorithm