Paul Kehrer | 7e4bc6d | 2013-12-24 22:23:53 -0600 | [diff] [blame] | 1 | import pytest |
| 2 | |
Alex Stapleton | 0d58373 | 2014-01-10 22:39:12 +0000 | [diff] [blame] | 3 | from cryptography.hazmat.backends import _ALL_BACKENDS |
Paul Kehrer | 7e4bc6d | 2013-12-24 22:23:53 -0600 | [diff] [blame] | 4 | from cryptography.hazmat.backends.interfaces import ( |
| 5 | HMACBackend, CipherBackend, HashBackend |
| 6 | ) |
| 7 | |
Paul Kehrer | 34c075e | 2014-01-13 21:52:08 -0500 | [diff] [blame] | 8 | from .utils import check_for_iface, check_backend_support, modify_backend_list |
| 9 | |
| 10 | |
Paul Kehrer | 098579e | 2014-01-14 10:26:44 -0500 | [diff] [blame^] | 11 | # copy all backends so we can mutate it.This variable is used in generate |
| 12 | # tests to allow us to target a single backend without changing _ALL_BACKENDS |
| 13 | |
| 14 | _UPDATED_BACKENDS = list(_ALL_BACKENDS) |
| 15 | |
| 16 | |
Paul Kehrer | 34c075e | 2014-01-13 21:52:08 -0500 | [diff] [blame] | 17 | def pytest_generate_tests(metafunc): |
Paul Kehrer | 098579e | 2014-01-14 10:26:44 -0500 | [diff] [blame^] | 18 | global _UPDATED_BACKENDS |
Paul Kehrer | 34c075e | 2014-01-13 21:52:08 -0500 | [diff] [blame] | 19 | name = metafunc.config.getoption("--backend") |
Paul Kehrer | 098579e | 2014-01-14 10:26:44 -0500 | [diff] [blame^] | 20 | modify_backend_list(name, _UPDATED_BACKENDS) |
Paul Kehrer | 7e4bc6d | 2013-12-24 22:23:53 -0600 | [diff] [blame] | 21 | |
| 22 | |
Paul Kehrer | 098579e | 2014-01-14 10:26:44 -0500 | [diff] [blame^] | 23 | @pytest.fixture(params=_UPDATED_BACKENDS) |
Alex Stapleton | 0d58373 | 2014-01-10 22:39:12 +0000 | [diff] [blame] | 24 | def backend(request): |
| 25 | return request.param |
Paul Kehrer | 7e4bc6d | 2013-12-24 22:23:53 -0600 | [diff] [blame] | 26 | |
| 27 | |
| 28 | @pytest.mark.trylast |
| 29 | def pytest_runtest_setup(item): |
Alex Gaynor | 2b3f942 | 2013-12-24 21:55:24 -0800 | [diff] [blame] | 30 | check_for_iface("hmac", HMACBackend, item) |
| 31 | check_for_iface("cipher", CipherBackend, item) |
| 32 | check_for_iface("hash", HashBackend, item) |
Paul Kehrer | 60fc8da | 2013-12-26 20:19:34 -0600 | [diff] [blame] | 33 | check_backend_support(item) |
Paul Kehrer | 34c075e | 2014-01-13 21:52:08 -0500 | [diff] [blame] | 34 | |
| 35 | |
| 36 | def pytest_addoption(parser): |
| 37 | parser.addoption( |
| 38 | "--backend", action="store", metavar="NAME", |
| 39 | help="Only run tests matching the backend NAME." |
| 40 | ) |