5 def force_reimport(module
):
6 """Force the module under test to be re-imported.
8 Because pytest runs all tests within the same scope (this makes me cry)
9 we have to do some manual housekeeping to avoid tests polluting each other.
11 Since conftest.py already does some sys.modules mangling I see no reason not to
12 do the same thing here.
15 steps
= module
.split(".")
19 for i
in range(len(steps
)):
20 module
= ".".join(steps
[0:i
+ 1])
22 del sys
.modules
[module
]
27 def test_gas_setup(GPIO
, smbus
):
28 from enviroplus
import gas
34 def test_gas_read_all(GPIO
, smbus
):
35 from enviroplus
import gas
37 result
= gas
.read_all()
39 assert type(result
.oxidising
) == float
40 assert int(result
.oxidising
) == 16641
42 assert type(result
.reducing
) == float
43 assert int(result
.reducing
) == 16727
45 assert type(result
.nh3
) == float
46 assert int(result
.nh3
) == 16813
48 assert "Oxidising" in str(result
)
51 def test_gas_read_each(GPIO
, 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(GPIO
, smbus
):
61 from enviroplus
import gas
65 gas
.set_adc_gain(2.048)
66 assert gas
.read_adc() == 0.255
69 def test_gas_read_adc_default_gain(GPIO
, smbus
):
70 from enviroplus
import gas
74 gas
.set_adc_gain(gas
.MICS6814_GAIN
)
75 assert gas
.read_adc() == 0.765
78 def test_gas_read_adc_str(GPIO
, smbus
):
79 from enviroplus
import gas
83 gas
.set_adc_gain(2.048)
84 assert 'ADC' in str(gas
.read_all())
87 def test_gas_cleanup(GPIO
, smbus
):
88 force_reimport('enviroplus.gas')
89 from enviroplus
import gas
93 GPIO
.output
.assert_called_with(gas
.MICS6814_HEATER_PIN
, 0)