blob: b1326dc83597ae342515c1721a9518aa898151ea [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 (
Ayrx3f695112014-04-21 19:12:03 +080020 CMACBackend, CipherBackend, DSABackend, HMACBackend, HashBackend,
Alex Stapleton00c580c2014-05-23 21:42:24 +010021 PBKDF2HMACBackend, PKCS8SerializationBackend, RSABackend,
22 TraditionalOpenSSLSerializationBackend
Paul Kehrer7e4bc6d2013-12-24 22:23:53 -060023)
Paul Kehrerafc1ccd2014-03-19 11:49:32 -040024from .utils import check_backend_support, check_for_iface, select_backends
Paul Kehrer34c075e2014-01-13 21:52:08 -050025
26
27def pytest_generate_tests(metafunc):
Paul Kehrerc421e632014-01-18 09:22:21 -060028 names = metafunc.config.getoption("--backend")
Alex Stapleton01de3ef2014-03-16 16:42:47 +000029 selected_backends = select_backends(names, _available_backends())
Paul Kehrer7e4bc6d2013-12-24 22:23:53 -060030
Paul Kehreraed9e172014-01-19 12:09:27 -060031 if "backend" in metafunc.fixturenames:
32 metafunc.parametrize("backend", selected_backends)
Paul Kehrer7e4bc6d2013-12-24 22:23:53 -060033
34
35@pytest.mark.trylast
36def pytest_runtest_setup(item):
Alex Gaynor2b3f9422013-12-24 21:55:24 -080037 check_for_iface("hmac", HMACBackend, item)
38 check_for_iface("cipher", CipherBackend, item)
Ayrxb5bb0652014-04-16 21:42:11 +080039 check_for_iface("cmac", CMACBackend, item)
Alex Gaynor2b3f9422013-12-24 21:55:24 -080040 check_for_iface("hash", HashBackend, item)
Paul Kehrer1277bc72014-01-28 17:09:59 -060041 check_for_iface("pbkdf2hmac", PBKDF2HMACBackend, item)
Mohammed Attia97c27c62014-04-02 03:46:57 +020042 check_for_iface("dsa", DSABackend, item)
Paul Kehrere4f78742014-02-08 09:21:21 -060043 check_for_iface("rsa", RSABackend, item)
Alex Stapleton458c09b2014-04-23 20:58:37 +010044 check_for_iface(
45 "traditional_openssl_serialization",
46 TraditionalOpenSSLSerializationBackend,
47 item
48 )
Alex Stapleton00c580c2014-05-23 21:42:24 +010049 check_for_iface(
50 "pkcs8_serialization",
51 PKCS8SerializationBackend,
52 item
53 )
Paul Kehrer60fc8da2013-12-26 20:19:34 -060054 check_backend_support(item)
Paul Kehrer34c075e2014-01-13 21:52:08 -050055
56
57def pytest_addoption(parser):
58 parser.addoption(
59 "--backend", action="store", metavar="NAME",
60 help="Only run tests matching the backend NAME."
61 )