b026172cb589e582056dd62ed84dc13bf6b791cf
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
=False)
19 """Mock RPi.GPIO module."""
20 GPIO
= mock
.MagicMock()
21 # Fudge for Python < 37 (possibly earlier)
22 sys
.modules
['RPi'] = mock
.Mock()
23 sys
.modules
['RPi'].GPIO
= GPIO
24 sys
.modules
['RPi.GPIO'] = GPIO
26 del sys
.modules
['RPi']
27 del sys
.modules
['RPi.GPIO']
30 @pytest.fixture(scope
='function', autouse
=False)
32 """Mock spidev module."""
33 spidev
= mock
.MagicMock()
34 sys
.modules
['spidev'] = spidev
36 del sys
.modules
['spidev']
39 @pytest.fixture(scope
='function', autouse
=False)
41 """Mock smbus module."""
42 smbus
= mock
.MagicMock()
43 smbus
.SMBus
= SMBusFakeDevice
44 sys
.modules
['smbus'] = smbus
46 del sys
.modules
['smbus']
49 @pytest.fixture(scope
='function', autouse
=False)
51 """Mock atexit module."""
52 atexit
= mock
.MagicMock()
53 sys
.modules
['atexit'] = atexit
55 del sys
.modules
['atexit']
58 @pytest.fixture(scope
='function', autouse
=False)
60 """Mock sounddevice module."""
61 sounddevice
= mock
.MagicMock()
62 sys
.modules
['sounddevice'] = sounddevice
64 del sys
.modules
['sounddevice']
67 @pytest.fixture(scope
='function', autouse
=False)
69 """Mock numpy module."""
70 numpy
= mock
.MagicMock()
71 sys
.modules
['numpy'] = numpy
73 del sys
.modules
['numpy']