b912a3764ee7bcf414c3856aded295ce719af1e0
3 from i2cdevice
import MockSMBus
6 class SMBusFakeDevice(MockSMBus
):
7 def __init__(self
, i2c_bus
):
8 MockSMBus
.__init
__(self
, i2c_bus
)
9 self
.regs
[0x00:0x01] = 0x0f, 0x00
13 sys
.modules
['RPi'] = mock
.Mock()
14 sys
.modules
['RPi.GPIO'] = mock
.Mock()
16 smbus
.SMBus
= SMBusFakeDevice
17 sys
.modules
['smbus'] = smbus
18 from enviroplus
import gas
23 def test_gas_read_all():
24 sys
.modules
['RPi'] = mock
.Mock()
25 sys
.modules
['RPi.GPIO'] = mock
.Mock()
27 smbus
.SMBus
= SMBusFakeDevice
28 sys
.modules
['smbus'] = smbus
29 from enviroplus
import gas
30 result
= gas
.read_all()
32 assert type(result
.oxidising
) == float
33 assert int(result
.oxidising
) == 16641
35 assert type(result
.reducing
) == float
36 assert int(result
.reducing
) == 16727
38 assert type(result
.nh3
) == float
39 assert int(result
.nh3
) == 16813
41 assert "Oxidising" in str(result
)
44 def test_gas_read_each():
45 sys
.modules
['RPi'] = mock
.Mock()
46 sys
.modules
['RPi.GPIO'] = mock
.Mock()
48 smbus
.SMBus
= SMBusFakeDevice
49 sys
.modules
['smbus'] = smbus
50 from enviroplus
import gas
52 assert int(gas
.read_oxidising()) == 16641
53 assert int(gas
.read_reducing()) == 16727
54 assert int(gas
.read_nh3()) == 16813