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 ( |
Paul Kehrer | e4f7874 | 2014-02-08 09:21:21 -0600 | [diff] [blame^] | 5 | HMACBackend, CipherBackend, HashBackend, PBKDF2HMACBackend, RSABackend |
Paul Kehrer | 7e4bc6d | 2013-12-24 22:23:53 -0600 | [diff] [blame] | 6 | ) |
| 7 | |
Paul Kehrer | c421e63 | 2014-01-18 09:22:21 -0600 | [diff] [blame] | 8 | from .utils import check_for_iface, check_backend_support, select_backends |
Paul Kehrer | 34c075e | 2014-01-13 21:52:08 -0500 | [diff] [blame] | 9 | |
| 10 | |
| 11 | def pytest_generate_tests(metafunc): |
Paul Kehrer | c421e63 | 2014-01-18 09:22:21 -0600 | [diff] [blame] | 12 | names = metafunc.config.getoption("--backend") |
Paul Kehrer | aed9e17 | 2014-01-19 12:09:27 -0600 | [diff] [blame] | 13 | selected_backends = select_backends(names, _ALL_BACKENDS) |
Paul Kehrer | 7e4bc6d | 2013-12-24 22:23:53 -0600 | [diff] [blame] | 14 | |
Paul Kehrer | aed9e17 | 2014-01-19 12:09:27 -0600 | [diff] [blame] | 15 | if "backend" in metafunc.fixturenames: |
| 16 | metafunc.parametrize("backend", selected_backends) |
Paul Kehrer | 7e4bc6d | 2013-12-24 22:23:53 -0600 | [diff] [blame] | 17 | |
| 18 | |
| 19 | @pytest.mark.trylast |
| 20 | def pytest_runtest_setup(item): |
Alex Gaynor | 2b3f942 | 2013-12-24 21:55:24 -0800 | [diff] [blame] | 21 | check_for_iface("hmac", HMACBackend, item) |
| 22 | check_for_iface("cipher", CipherBackend, item) |
| 23 | check_for_iface("hash", HashBackend, item) |
Paul Kehrer | 1277bc7 | 2014-01-28 17:09:59 -0600 | [diff] [blame] | 24 | check_for_iface("pbkdf2hmac", PBKDF2HMACBackend, item) |
Paul Kehrer | e4f7874 | 2014-02-08 09:21:21 -0600 | [diff] [blame^] | 25 | check_for_iface("rsa", RSABackend, item) |
Paul Kehrer | 60fc8da | 2013-12-26 20:19:34 -0600 | [diff] [blame] | 26 | check_backend_support(item) |
Paul Kehrer | 34c075e | 2014-01-13 21:52:08 -0500 | [diff] [blame] | 27 | |
| 28 | |
| 29 | def pytest_addoption(parser): |
| 30 | parser.addoption( |
| 31 | "--backend", action="store", metavar="NAME", |
| 32 | help="Only run tests matching the backend NAME." |
| 33 | ) |