aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2013-10-16 14:27:52 -0700
committerAlex Gaynor <alex.gaynor@gmail.com>2013-10-16 14:27:52 -0700
commit512dd6925202c5dc6680dd7157a132a9ffc4855f (patch)
tree825f91b14d8bf539bde5e4f3b7ec670f078e8a68 /tests
parenta20631d332d47903a85b61c4b68c5398125a3ebe (diff)
downloadcryptography-512dd6925202c5dc6680dd7157a132a9ffc4855f.tar.gz
cryptography-512dd6925202c5dc6680dd7157a132a9ffc4855f.tar.bz2
cryptography-512dd6925202c5dc6680dd7157a132a9ffc4855f.zip
Move around the skip logic
Diffstat (limited to 'tests')
-rw-r--r--tests/primitives/test_cryptrec.py5
-rw-r--r--tests/primitives/test_openssl_vectors.py13
-rw-r--r--tests/primitives/utils.py29
3 files changed, 26 insertions, 21 deletions
diff --git a/tests/primitives/test_cryptrec.py b/tests/primitives/test_cryptrec.py
index 59d8b24b..4d16ce03 100644
--- a/tests/primitives/test_cryptrec.py
+++ b/tests/primitives/test_cryptrec.py
@@ -30,8 +30,9 @@ class TestCamelliaECB(object):
test_NTT = generate_encrypt_test(
load_cryptrec_vectors_from_file,
os.path.join("Camellia", "NTT"),
- ["camellia-128-ecb", "camellia-192-ecb", "camellia-256"],
+ ["camellia-128-ecb.txt", "camellia-192-ecb.txt", "camellia-256-ecb.txt"],
lambda key: ciphers.Camellia(binascii.unhexlify((key))),
lambda key: modes.EBC(),
- only_if=lambda api: api.supports_cipher("camellia-128-ecb")
+ only_if=lambda api: api.supports_cipher("camellia-128-ecb"),
+ skip_message="Does not support Camellia ECB",
)
diff --git a/tests/primitives/test_openssl_vectors.py b/tests/primitives/test_openssl_vectors.py
index f9c4e1fa..6e32eca6 100644
--- a/tests/primitives/test_openssl_vectors.py
+++ b/tests/primitives/test_openssl_vectors.py
@@ -18,10 +18,6 @@ Test using the OpenSSL Test Vectors
from __future__ import absolute_import, division, print_function
import binascii
-import itertools
-import os
-
-import pytest
from cryptography.primitives.block import ciphers, modes
@@ -36,7 +32,8 @@ class TestCamelliaCBC(object):
["camellia-cbc.txt"],
lambda key, iv: ciphers.Camellia(binascii.unhexlify(key)),
lambda key, iv: modes.CBC(binascii.unhexlify(iv)),
- only_if=lambda api: api.supports_cipher("camellia-128-cbc")
+ only_if=lambda api: api.supports_cipher("camellia-128-cbc"),
+ skip_message="Does not support Camellia CBC",
)
@@ -47,7 +44,8 @@ class TestCamelliaOFB(object):
["camellia-ofb.txt"],
lambda key, iv: ciphers.Camellia(binascii.unhexlify(key)),
lambda key, iv: modes.OFB(binascii.unhexlify(iv)),
- only_if=lambda api: api.supports_cipher("camellia-128-ofb")
+ only_if=lambda api: api.supports_cipher("camellia-128-ofb"),
+ skip_message="Does not support Camellia OFB",
)
@@ -58,5 +56,6 @@ class TestCamelliaCFB(object):
["camellia-cfb.txt"],
lambda key, iv: ciphers.Camellia(binascii.unhexlify(key)),
lambda key, iv: modes.CFB(binascii.unhexlify(iv)),
- only_if=lambda api: api.supports_cipher("camellia-128-cfb")
+ only_if=lambda api: api.supports_cipher("camellia-128-cfb"),
+ skip_message="Does not support Camellia CFB",
)
diff --git a/tests/primitives/utils.py b/tests/primitives/utils.py
index addd7123..e4cb8da7 100644
--- a/tests/primitives/utils.py
+++ b/tests/primitives/utils.py
@@ -8,19 +8,28 @@ from cryptography.primitives.block import BlockCipher
def generate_encrypt_test(param_loader, path, file_names, cipher_factory,
- mode_factory, only_if=lambda api: True):
+ mode_factory, only_if=lambda api: True,
+ skip_message=None):
def test_encryption(self):
for api in _ALL_APIS:
- if not only_if(api):
- yield encrypt_skipped
- else:
- for file_name in file_names:
- for params in param_loader(os.path.join(path, file_name)):
- yield encrypt_test, api, cipher_factory, mode_factory, params
+ for file_name in file_names:
+ for params in param_loader(os.path.join(path, file_name)):
+ yield (
+ encrypt_test,
+ api,
+ cipher_factory,
+ mode_factory,
+ params,
+ only_if,
+ skip_message
+ )
return test_encryption
-def encrypt_test(api, cipher_factory, mode_factory, params):
+def encrypt_test(api, cipher_factory, mode_factory, params, only_if,
+ skip_message):
+ if not only_if(api):
+ pytest.skip(skip_message)
plaintext = params.pop("plaintext")
ciphertext = params.pop("ciphertext")
cipher = BlockCipher(
@@ -31,7 +40,3 @@ def encrypt_test(api, cipher_factory, mode_factory, params):
actual_ciphertext = cipher.encrypt(binascii.unhexlify(plaintext))
actual_ciphertext += cipher.finalize()
assert binascii.hexlify(actual_ciphertext) == ciphertext
-
-
-def encrypt_skipped():
- pytest.skip("because reasons")