blob: 36183f46bf67adbd6cd76c3c56246b50b5fe9a9a [file] [log] [blame]
Alex Gaynorc37feed2014-03-08 08:32:56 -08001# 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
14from __future__ import absolute_import, division, print_function
15
Paul Kehrer7e4bc6d2013-12-24 22:23:53 -060016import pytest
17
Alex Stapleton01de3ef2014-03-16 16:42:47 +000018from cryptography.hazmat.backends import _available_backends
Paul Kehrer7e4bc6d2013-12-24 22:23:53 -060019from cryptography.hazmat.backends.interfaces import (
Paul Kehrere4f78742014-02-08 09:21:21 -060020 HMACBackend, CipherBackend, HashBackend, PBKDF2HMACBackend, RSABackend
Paul Kehrer7e4bc6d2013-12-24 22:23:53 -060021)
22
Paul Kehrerc421e632014-01-18 09:22:21 -060023from .utils import check_for_iface, check_backend_support, select_backends
Paul Kehrer34c075e2014-01-13 21:52:08 -050024
25
26def pytest_generate_tests(metafunc):
Paul Kehrerc421e632014-01-18 09:22:21 -060027 names = metafunc.config.getoption("--backend")
Alex Stapleton01de3ef2014-03-16 16:42:47 +000028 selected_backends = select_backends(names, _available_backends())
Paul Kehrer7e4bc6d2013-12-24 22:23:53 -060029
Paul Kehreraed9e172014-01-19 12:09:27 -060030 if "backend" in metafunc.fixturenames:
31 metafunc.parametrize("backend", selected_backends)
Paul Kehrer7e4bc6d2013-12-24 22:23:53 -060032
33
34@pytest.mark.trylast
35def pytest_runtest_setup(item):
Alex Gaynor2b3f9422013-12-24 21:55:24 -080036 check_for_iface("hmac", HMACBackend, item)
37 check_for_iface("cipher", CipherBackend, item)
38 check_for_iface("hash", HashBackend, item)
Paul Kehrer1277bc72014-01-28 17:09:59 -060039 check_for_iface("pbkdf2hmac", PBKDF2HMACBackend, item)
Paul Kehrere4f78742014-02-08 09:21:21 -060040 check_for_iface("rsa", RSABackend, item)
Paul Kehrer60fc8da2013-12-26 20:19:34 -060041 check_backend_support(item)
Paul Kehrer34c075e2014-01-13 21:52:08 -050042
43
44def pytest_addoption(parser):
45 parser.addoption(
46 "--backend", action="store", metavar="NAME",
47 help="Only run tests matching the backend NAME."
48 )