forked from pimoroni/enviroplus-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
90 lines (74 loc) · 2.16 KB
/
conftest.py
File metadata and controls
90 lines (74 loc) · 2.16 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
"""Test configuration.
These allow the mocking of various Python modules
that might otherwise have runtime side-effects.
"""
import sys
import mock
import pytest
from i2cdevice import MockSMBus
class SMBusFakeDevice(MockSMBus):
def __init__(self, i2c_bus):
MockSMBus.__init__(self, i2c_bus)
self.regs[0x00:0x01] = 0x0f, 0x00
@pytest.fixture(scope='function', autouse=True)
def cleanup():
yield None
try:
del sys.modules['enviroplus']
except KeyError:
pass
try:
del sys.modules['enviroplus.noise']
except KeyError:
pass
try:
del sys.modules['enviroplus.gas']
except KeyError:
pass
@pytest.fixture(scope='function', autouse=False)
def GPIO():
"""Mock RPi.GPIO module."""
GPIO = mock.MagicMock()
# Fudge for Python < 37 (possibly earlier)
sys.modules['RPi'] = mock.Mock()
sys.modules['RPi'].GPIO = GPIO
sys.modules['RPi.GPIO'] = GPIO
yield GPIO
del sys.modules['RPi']
del sys.modules['RPi.GPIO']
@pytest.fixture(scope='function', autouse=False)
def spidev():
"""Mock spidev module."""
spidev = mock.MagicMock()
sys.modules['spidev'] = spidev
yield spidev
del sys.modules['spidev']
@pytest.fixture(scope='function', autouse=False)
def smbus():
"""Mock smbus module."""
smbus = mock.MagicMock()
smbus.SMBus = SMBusFakeDevice
sys.modules['smbus'] = smbus
yield smbus
del sys.modules['smbus']
@pytest.fixture(scope='function', autouse=False)
def atexit():
"""Mock atexit module."""
atexit = mock.MagicMock()
sys.modules['atexit'] = atexit
yield atexit
del sys.modules['atexit']
@pytest.fixture(scope='function', autouse=False)
def sounddevice():
"""Mock sounddevice module."""
sounddevice = mock.MagicMock()
sys.modules['sounddevice'] = sounddevice
yield sounddevice
del sys.modules['sounddevice']
@pytest.fixture(scope='function', autouse=False)
def numpy():
"""Mock numpy module."""
numpy = mock.MagicMock()
sys.modules['numpy'] = numpy
yield numpy
del sys.modules['numpy']