2 These allow the mocking of various Python modules
3 that might otherwise have runtime side-effects.
8 from i2cdevice
import MockSMBus
11 class SMBusFakeDevice(MockSMBus
):
12 def __init__(self
, i2c_bus
):
13 MockSMBus
.__init
__(self
, i2c_bus
)
14 self
.regs
[0x00:0x01] = 0x0f, 0x00
17 @pytest.fixture(scope
='function', autouse
=True)
21 del sys
.modules
['enviroplus']
25 del sys
.modules
['enviroplus.noise']
29 del sys
.modules
['enviroplus.gas']
34 @pytest.fixture(scope
='function', autouse
=False)
36 """Mock RPi.GPIO module."""
37 GPIO
= mock
.MagicMock()
38 # Fudge for Python < 37 (possibly earlier)
39 sys
.modules
['RPi'] = mock
.Mock()
40 sys
.modules
['RPi'].GPIO
= GPIO
41 sys
.modules
['RPi.GPIO'] = GPIO
43 del sys
.modules
['RPi']
44 del sys
.modules
['RPi.GPIO']
47 @pytest.fixture(scope
='function', autouse
=False)
49 """Mock spidev module."""
50 spidev
= mock
.MagicMock()
51 sys
.modules
['spidev'] = spidev
53 del sys
.modules
['spidev']
56 @pytest.fixture(scope
='function', autouse
=False)
58 """Mock smbus module."""
59 smbus
= mock
.MagicMock()
60 smbus
.SMBus
= SMBusFakeDevice
61 sys
.modules
['smbus'] = smbus
63 del sys
.modules
['smbus']
66 @pytest.fixture(scope
='function', autouse
=False)
68 """Mock atexit module."""
69 atexit
= mock
.MagicMock()
70 sys
.modules
['atexit'] = atexit
72 del sys
.modules
['atexit']
75 @pytest.fixture(scope
='function', autouse
=False)
77 """Mock sounddevice module."""
78 sounddevice
= mock
.MagicMock()
79 sys
.modules
['sounddevice'] = sounddevice
81 del sys
.modules
['sounddevice']
84 @pytest.fixture(scope
='function', autouse
=False)
86 """Mock numpy module."""
87 numpy
= mock
.MagicMock()
88 sys
.modules
['numpy'] = numpy
90 del sys
.modules
['numpy']