-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_sf_conditional_import.py
44 lines (30 loc) · 1.2 KB
/
test_sf_conditional_import.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from unittest.mock import patch
import pytest
@pytest.fixture
def mock_snowflurry_device():
with patch("pennylane_calculquebec.snowflurry_device.SnowflurryQubitDevice") as mock:
yield mock
@pytest.fixture
def mock_find_spec():
with patch("importlib.util.find_spec") as mock:
yield mock
def test_snowflurry_device(mock_find_spec):
mock_find_spec.return_value = None
with pytest.raises(Exception):
import pennylane_calculquebec.snowflurry_device
old_call_count = mock_find_spec.call_count
mock_find_spec.return_value = "not null"
import pennylane_calculquebec.snowflurry_device
def test_pennylane_converter(mock_find_spec):
mock_find_spec.return_value = None
with pytest.raises(Exception):
import pennylane_calculquebec.pennylane_converter
old_call_count = mock_find_spec.call_count
mock_find_spec.return_value = "not null"
import pennylane_calculquebec.pennylane_converter
def test_pennylane_calculquebec_none_lib(mock_find_spec):
import sys
mock_find_spec.return_value = None
import pennylane_calculquebec
modules = sorted([k for k in sys.modules.keys() if "snowflurry_device" in k])
assert len(modules) == 0