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']