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 ( |
Mohammed Attia | 97c27c6 | 2014-04-02 03:46:57 +0200 | [diff] [blame^] | 20 | CipherBackend, DSABackend, HMACBackend, HashBackend, PBKDF2HMACBackend, |
| 21 | RSABackend |
Paul Kehrer | 7e4bc6d | 2013-12-24 22:23:53 -0600 | [diff] [blame] | 22 | ) |
| 23 | |
Paul Kehrer | afc1ccd | 2014-03-19 11:49:32 -0400 | [diff] [blame] | 24 | from .utils import check_backend_support, check_for_iface, select_backends |
Paul Kehrer | 34c075e | 2014-01-13 21:52:08 -0500 | [diff] [blame] | 25 | |
| 26 | |
| 27 | def pytest_generate_tests(metafunc): |
Paul Kehrer | c421e63 | 2014-01-18 09:22:21 -0600 | [diff] [blame] | 28 | names = metafunc.config.getoption("--backend") |
Alex Stapleton | 01de3ef | 2014-03-16 16:42:47 +0000 | [diff] [blame] | 29 | selected_backends = select_backends(names, _available_backends()) |
Paul Kehrer | 7e4bc6d | 2013-12-24 22:23:53 -0600 | [diff] [blame] | 30 | |
Paul Kehrer | aed9e17 | 2014-01-19 12:09:27 -0600 | [diff] [blame] | 31 | if "backend" in metafunc.fixturenames: |
| 32 | metafunc.parametrize("backend", selected_backends) |
Paul Kehrer | 7e4bc6d | 2013-12-24 22:23:53 -0600 | [diff] [blame] | 33 | |
| 34 | |
| 35 | @pytest.mark.trylast |
| 36 | def pytest_runtest_setup(item): |
Alex Gaynor | 2b3f942 | 2013-12-24 21:55:24 -0800 | [diff] [blame] | 37 | check_for_iface("hmac", HMACBackend, item) |
| 38 | check_for_iface("cipher", CipherBackend, item) |
| 39 | check_for_iface("hash", HashBackend, item) |
Paul Kehrer | 1277bc7 | 2014-01-28 17:09:59 -0600 | [diff] [blame] | 40 | check_for_iface("pbkdf2hmac", PBKDF2HMACBackend, item) |
Mohammed Attia | 97c27c6 | 2014-04-02 03:46:57 +0200 | [diff] [blame^] | 41 | check_for_iface("dsa", DSABackend, item) |
Paul Kehrer | e4f7874 | 2014-02-08 09:21:21 -0600 | [diff] [blame] | 42 | check_for_iface("rsa", RSABackend, item) |
Paul Kehrer | 60fc8da | 2013-12-26 20:19:34 -0600 | [diff] [blame] | 43 | check_backend_support(item) |
Paul Kehrer | 34c075e | 2014-01-13 21:52:08 -0500 | [diff] [blame] | 44 | |
| 45 | |
| 46 | def pytest_addoption(parser): |
| 47 | parser.addoption( |
| 48 | "--backend", action="store", metavar="NAME", |
| 49 | help="Only run tests matching the backend NAME." |
| 50 | ) |