Alex Gaynor | c37feed | 2014-03-08 08:32:56 -0800 | [diff] [blame] | 1 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 2 | # you may not use this file except in compliance with the License. |
| 3 | # You may obtain a copy of the License at |
| 4 | # |
| 5 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | # |
| 7 | # Unless required by applicable law or agreed to in writing, software |
| 8 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| 10 | # implied. |
| 11 | # See the License for the specific language governing permissions and |
| 12 | # limitations under the License. |
| 13 | |
| 14 | from __future__ import absolute_import, division, print_function |
| 15 | |
Paul Kehrer | 7e4bc6d | 2013-12-24 22:23:53 -0600 | [diff] [blame] | 16 | import pytest |
| 17 | |
Alex Stapleton | 01de3ef | 2014-03-16 16:42:47 +0000 | [diff] [blame^] | 18 | from cryptography.hazmat.backends import _available_backends |
Paul Kehrer | 7e4bc6d | 2013-12-24 22:23:53 -0600 | [diff] [blame] | 19 | from cryptography.hazmat.backends.interfaces import ( |
Paul Kehrer | e4f7874 | 2014-02-08 09:21:21 -0600 | [diff] [blame] | 20 | HMACBackend, CipherBackend, HashBackend, PBKDF2HMACBackend, RSABackend |
Paul Kehrer | 7e4bc6d | 2013-12-24 22:23:53 -0600 | [diff] [blame] | 21 | ) |
| 22 | |
Paul Kehrer | c421e63 | 2014-01-18 09:22:21 -0600 | [diff] [blame] | 23 | from .utils import check_for_iface, check_backend_support, select_backends |
Paul Kehrer | 34c075e | 2014-01-13 21:52:08 -0500 | [diff] [blame] | 24 | |
| 25 | |
| 26 | def pytest_generate_tests(metafunc): |
Paul Kehrer | c421e63 | 2014-01-18 09:22:21 -0600 | [diff] [blame] | 27 | names = metafunc.config.getoption("--backend") |
Alex Stapleton | 01de3ef | 2014-03-16 16:42:47 +0000 | [diff] [blame^] | 28 | selected_backends = select_backends(names, _available_backends()) |
Paul Kehrer | 7e4bc6d | 2013-12-24 22:23:53 -0600 | [diff] [blame] | 29 | |
Paul Kehrer | aed9e17 | 2014-01-19 12:09:27 -0600 | [diff] [blame] | 30 | if "backend" in metafunc.fixturenames: |
| 31 | metafunc.parametrize("backend", selected_backends) |
Paul Kehrer | 7e4bc6d | 2013-12-24 22:23:53 -0600 | [diff] [blame] | 32 | |
| 33 | |
| 34 | @pytest.mark.trylast |
| 35 | def pytest_runtest_setup(item): |
Alex Gaynor | 2b3f942 | 2013-12-24 21:55:24 -0800 | [diff] [blame] | 36 | check_for_iface("hmac", HMACBackend, item) |
| 37 | check_for_iface("cipher", CipherBackend, item) |
| 38 | check_for_iface("hash", HashBackend, item) |
Paul Kehrer | 1277bc7 | 2014-01-28 17:09:59 -0600 | [diff] [blame] | 39 | check_for_iface("pbkdf2hmac", PBKDF2HMACBackend, item) |
Paul Kehrer | e4f7874 | 2014-02-08 09:21:21 -0600 | [diff] [blame] | 40 | check_for_iface("rsa", RSABackend, item) |
Paul Kehrer | 60fc8da | 2013-12-26 20:19:34 -0600 | [diff] [blame] | 41 | check_backend_support(item) |
Paul Kehrer | 34c075e | 2014-01-13 21:52:08 -0500 | [diff] [blame] | 42 | |
| 43 | |
| 44 | def pytest_addoption(parser): |
| 45 | parser.addoption( |
| 46 | "--backend", action="store", metavar="NAME", |
| 47 | help="Only run tests matching the backend NAME." |
| 48 | ) |