blob: 6ba8ae0a965b6c5ea578ab4046638c95f7d49a1a [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 (
Ayrxb5bb0652014-04-16 21:42:11 +080020 CipherBackend, CMACBackend, DSABackend, HMACBackend, HashBackend,
21 PBKDF2HMACBackend, RSABackend
Paul Kehrer7e4bc6d2013-12-24 22:23:53 -060022)
Paul Kehrerafc1ccd2014-03-19 11:49:32 -040023from .utils import check_backend_support, check_for_iface, 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)
Ayrxb5bb0652014-04-16 21:42:11 +080038 check_for_iface("cmac", CMACBackend, item)
Alex Gaynor2b3f9422013-12-24 21:55:24 -080039 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 )