aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2014-01-18 09:22:21 -0600
committerPaul Kehrer <paul.l.kehrer@gmail.com>2014-01-18 09:22:21 -0600
commitc421e636b15768e1adaf8bf681ecdd12b96c8669 (patch)
tree0022ea86435e579a071f34db0221e0e545b7b86a /tests
parent681e7a5587e78918fd15af5255204216d0ea7237 (diff)
downloadcryptography-c421e636b15768e1adaf8bf681ecdd12b96c8669.tar.gz
cryptography-c421e636b15768e1adaf8bf681ecdd12b96c8669.tar.bz2
cryptography-c421e636b15768e1adaf8bf681ecdd12b96c8669.zip
modify backend selection to allow multiple backends via comma delimiter
Diffstat (limited to 'tests')
-rw-r--r--tests/conftest.py12
-rw-r--r--tests/test_utils.py31
-rw-r--r--tests/utils.py25
3 files changed, 49 insertions, 19 deletions
diff --git a/tests/conftest.py b/tests/conftest.py
index 49e178bc..b9879f86 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -5,21 +5,21 @@ from cryptography.hazmat.backends.interfaces import (
HMACBackend, CipherBackend, HashBackend
)
-from .utils import check_for_iface, check_backend_support, modify_backend_list
+from .utils import check_for_iface, check_backend_support, select_backends
# copy all backends so we can mutate it.This variable is used in generate
# tests to allow us to target a single backend without changing _ALL_BACKENDS
-_DESIRED_BACKENDS = list(_ALL_BACKENDS)
+_SELECTED_BACKENDS = list(_ALL_BACKENDS)
def pytest_generate_tests(metafunc):
- global _DESIRED_BACKENDS
- name = metafunc.config.getoption("--backend")
- modify_backend_list(name, _DESIRED_BACKENDS)
+ global _SELECTED_BACKENDS
+ names = metafunc.config.getoption("--backend")
+ _SELECTED_BACKENDS = select_backends(names, _SELECTED_BACKENDS)
-@pytest.fixture(params=_DESIRED_BACKENDS)
+@pytest.fixture(params=_SELECTED_BACKENDS)
def backend(request):
return request.param
diff --git a/tests/test_utils.py b/tests/test_utils.py
index e8037c1d..a7da4906 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -21,7 +21,7 @@ import pytest
from .utils import (
load_nist_vectors, load_vectors_from_file, load_cryptrec_vectors,
load_openssl_vectors, load_hash_vectors, check_for_iface,
- check_backend_support, modify_backend_list
+ check_backend_support, select_backends
)
@@ -29,25 +29,46 @@ class FakeInterface(object):
pass
-def test_modify_backend_list_leave_one():
+def test_select_one_backend():
b1 = pretend.stub(name="b1")
b2 = pretend.stub(name="b2")
b3 = pretend.stub(name="b3")
backends = [b1, b2, b3]
name = "b2"
- modify_backend_list(name, backends)
+ select_backends(name, backends)
assert len(backends) == 1
assert backends[0] == b2
-def test_modify_backend_list_error_none():
+def test_select_no_backend():
b1 = pretend.stub(name="b1")
b2 = pretend.stub(name="b2")
b3 = pretend.stub(name="b3")
backends = [b1, b2, b3]
name = "back!"
with pytest.raises(ValueError):
- modify_backend_list(name, backends)
+ select_backends(name, backends)
+
+
+def test_select_backends_none():
+ b1 = pretend.stub(name="b1")
+ b2 = pretend.stub(name="b2")
+ b3 = pretend.stub(name="b3")
+ backends = [b1, b2, b3]
+ name = None
+ select_backends(name, backends)
+ assert len(backends) == 3
+
+
+def test_select_two_backends():
+ b1 = pretend.stub(name="b1")
+ b2 = pretend.stub(name="b2")
+ b3 = pretend.stub(name="b3")
+ backends = [b1, b2, b3]
+ name = "b2 ,b1 "
+ select_backends(name, backends)
+ assert len(backends) == 2
+ assert backends == [b1, b2]
def test_check_for_iface():
diff --git a/tests/utils.py b/tests/utils.py
index 343f3efe..ee1675e8 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -16,14 +16,23 @@ import os
import pytest
-def modify_backend_list(name, all_backends):
- if name is not None:
- backends = list(all_backends)
- for backend in backends:
- if backend.name != name:
- all_backends.remove(backend)
- if len(all_backends) == 0:
- raise ValueError("No backends selected for testing")
+def select_backends(names, backend_list):
+ if names is None:
+ return backend_list
+ split_names = [x.strip() for x in names.split(',')]
+ # this must be duplicated and then removed to preserve the metadata
+ # pytest associates. Appending backends to a new list doesn't seem to work
+ backends = list(backend_list)
+ for backend in backends:
+ if backend.name not in split_names:
+ backend_list.remove(backend)
+
+ if len(backend_list) > 0:
+ return backend_list
+ else:
+ raise ValueError(
+ "No backend selected. Tried to select: {0}".format(split_names)
+ )
def check_for_iface(name, iface, item):