blob: 1ee2a9930142651b5984bc9b1913700af493c0a0 [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 (
Mohammed Attia97c27c62014-04-02 03:46:57 +020020 CipherBackend, DSABackend, HMACBackend, HashBackend, PBKDF2HMACBackend,
21 RSABackend
Paul Kehrer7e4bc6d2013-12-24 22:23:53 -060022)
23
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)
39 check_for_iface("hash", HashBackend, item)
Paul Kehrer1277bc72014-01-28 17:09:59 -060040 check_for_iface("pbkdf2hmac", PBKDF2HMACBackend, item)
Mohammed Attia97c27c62014-04-02 03:46:57 +020041 check_for_iface("dsa", DSABackend, item)
Paul Kehrere4f78742014-02-08 09:21:21 -060042 check_for_iface("rsa", RSABackend, item)
Paul Kehrer60fc8da2013-12-26 20:19:34 -060043 check_backend_support(item)
Paul Kehrer34c075e2014-01-13 21:52:08 -050044
45
46def pytest_addoption(parser):
47 parser.addoption(
48 "--backend", action="store", metavar="NAME",
49 help="Only run tests matching the backend NAME."
50 )