microsoft/qdk

Public

mirrored fromhttps://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
7421e7dd1015dcbd940bf843d33583470de580ea

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

source/qdk_package/tests/test_extras.py

43lines · modecode

1# Copyright (c) Microsoft Corporation.
2# Licensed under the MIT License.
3
4import pytest, importlib
5
6from mocks import (
7 mock_widgets,
8 mock_azure,
9 mock_qiskit,
10 cleanup_modules,
11)
12
13
14# Standard contract description for each extra we test.
15EXTRAS = {
16 "widgets": {
17 "mock": mock_widgets,
18 "module": "qdk.widgets",
19 "post_assert": lambda mod: hasattr(mod, "__doc__"),
20 },
21 "azure": {
22 "mock": mock_azure,
23 "module": "qdk.azure",
24 "post_assert": lambda mod: all(
25 hasattr(mod, name) for name in ("target", "argument_types", "job")
26 ),
27 },
28 "qiskit": {
29 "mock": mock_qiskit,
30 "module": "qdk.qiskit",
31 "post_assert": lambda mod: hasattr(mod, "__doc__"),
32 },
33}
34
35
36@pytest.mark.parametrize("name,spec", EXTRAS.items())
37def test_direct_import_with_mock(name, spec):
38 created = spec["mock"]()
39 try:
40 imported = importlib.import_module(spec["module"])
41 assert spec["post_assert"](imported)
42 finally:
43 cleanup_modules(created)
44