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
24 def test_gas_read_all():
25 sys
.modules
['RPi'] = mock
.Mock()
26 sys
.modules
['RPi.GPIO'] = mock
.Mock()
28 smbus
.SMBus
= SMBusFakeDevice
29 sys
.modules
['smbus'] = smbus
30 from enviroplus
import gas
32 result
= gas
.read_all()
34 assert type(result
.oxidising
) == float
35 assert int(result
.oxidising
) == 16641
37 assert type(result
.reducing
) == float
38 assert int(result
.reducing
) == 16727
40 assert type(result
.nh3
) == float
41 assert int(result
.nh3
) == 16813
43 assert "Oxidising" in str(result
)
46 def test_gas_read_each():
47 sys
.modules
['RPi'] = mock
.Mock()
48 sys
.modules
['RPi.GPIO'] = mock
.Mock()
50 smbus
.SMBus
= SMBusFakeDevice
51 sys
.modules
['smbus'] = smbus
52 from enviroplus
import gas
55 assert int(gas
.read_oxidising()) == 16641
56 assert int(gas
.read_reducing()) == 16727
57 assert int(gas
.read_nh3()) == 16813
60 def test_gas_read_adc():
61 sys
.modules
['RPi'] = mock
.Mock()
62 sys
.modules
['RPi.GPIO'] = mock
.Mock()
64 smbus
.SMBus
= SMBusFakeDevice
65 sys
.modules
['smbus'] = smbus
66 from enviroplus
import gas
70 gas
.set_adc_gain(2.048)
71 assert gas
.read_adc() == 0.255
74 def test_gas_read_adc_default_gain():
75 sys
.modules
['RPi'] = mock
.Mock()
76 sys
.modules
['RPi.GPIO'] = mock
.Mock()
78 smbus
.SMBus
= SMBusFakeDevice
79 sys
.modules
['smbus'] = smbus
80 from enviroplus
import gas
84 assert gas
.read_adc() == 0.255
87 def test_gas_read_adc_str():
88 sys
.modules
['RPi'] = mock
.Mock()
89 sys
.modules
['RPi.GPIO'] = mock
.Mock()
91 smbus
.SMBus
= SMBusFakeDevice
92 sys
.modules
['smbus'] = smbus
93 from enviroplus
import gas
97 gas
.set_adc_gain(2.048)
98 assert 'ADC' in str(gas
.read_all())