Decode fix for #3
[EVA-2020-02-2.git] / library / tests / test_setup.py
1 import sys
2 import mock
3 from i2cdevice import MockSMBus
4
5
6 class SMBusFakeDevice(MockSMBus):
7 def __init__(self, i2c_bus):
8 MockSMBus.__init__(self, i2c_bus)
9 self.regs[0x00:0x01] = 0x0f, 0x00
10
11
12 def test_gas_setup():
13 sys.modules['RPi'] = mock.Mock()
14 sys.modules['RPi.GPIO'] = mock.Mock()
15 smbus = mock.Mock()
16 smbus.SMBus = SMBusFakeDevice
17 sys.modules['smbus'] = smbus
18 from enviroplus import gas
19 gas.setup()
20 gas.setup()
21
22
23 def test_gas_read_all():
24 sys.modules['RPi'] = mock.Mock()
25 sys.modules['RPi.GPIO'] = mock.Mock()
26 smbus = mock.Mock()
27 smbus.SMBus = SMBusFakeDevice
28 sys.modules['smbus'] = smbus
29 from enviroplus import gas
30 result = gas.read_all()
31
32 assert type(result.oxidising) == float
33 assert int(result.oxidising) == 16641
34
35 assert type(result.reducing) == float
36 assert int(result.reducing) == 16727
37
38 assert type(result.nh3) == float
39 assert int(result.nh3) == 16813
40
41 assert "Oxidising" in str(result)
42
43
44 def test_gas_read_each():
45 sys.modules['RPi'] = mock.Mock()
46 sys.modules['RPi.GPIO'] = mock.Mock()
47 smbus = mock.Mock()
48 smbus.SMBus = SMBusFakeDevice
49 sys.modules['smbus'] = smbus
50 from enviroplus import gas
51
52 assert int(gas.read_oxidising()) == 16641
53 assert int(gas.read_reducing()) == 16727
54 assert int(gas.read_nh3()) == 16813