forked from pimoroni/enviroplus-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_setup.py
More file actions
86 lines (57 loc) · 1.98 KB
/
test_setup.py
File metadata and controls
86 lines (57 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import pytest
def test_gas_setup(gpiod, gpiodevice, smbus):
from enviroplus import gas
gas._is_setup = False
gas.setup()
gas.setup()
def test_gas_unavailable(gpiod, gpiodevice, mocksmbus):
from enviroplus import gas
mocksmbus.SMBus(1).read_i2c_block_data.side_effect = IOError("Oh no!")
gas._is_setup = False
assert gas.available() is False
with pytest.raises(RuntimeError):
gas.read_all()
def test_gas_available(gpiod, gpiodevice, smbus_notimeout):
from enviroplus import gas
gas._is_setup = False
assert gas.available() is True
def test_gas_read_all(gpiod, gpiodevice, smbus):
from enviroplus import gas
gas._is_setup = False
result = gas.read_all()
assert isinstance(result.oxidising, float)
assert int(result.oxidising) == 16641
assert isinstance(result.reducing, float)
assert int(result.reducing) == 16727
assert isinstance(result.nh3, float)
assert int(result.nh3) == 16813
assert "Oxidising" in str(result)
def test_gas_read_each(gpiod, gpiodevice, smbus):
from enviroplus import gas
gas._is_setup = False
assert int(gas.read_oxidising()) == 16641
assert int(gas.read_reducing()) == 16727
assert int(gas.read_nh3()) == 16813
def test_gas_read_adc(gpiod, gpiodevice, smbus):
from enviroplus import gas
gas._is_setup = False
gas.enable_adc(True)
gas.set_adc_gain(2.048)
assert gas.read_adc() == 0.255
def test_gas_read_adc_default_gain(gpiod, gpiodevice, smbus):
from enviroplus import gas
gas._is_setup = False
gas.enable_adc(True)
gas.set_adc_gain(gas.MICS6814_GAIN)
assert gas.read_adc() == 0.765
def test_gas_read_adc_str(gpiod, gpiodevice, smbus):
from enviroplus import gas
gas._is_setup = False
gas.enable_adc(True)
gas.set_adc_gain(2.048)
assert "ADC" in str(gas.read_all())
def test_gas_cleanup(gpiod, gpiodevice, smbus):
from enviroplus import gas
gas.cleanup()
gas.setup()
gas.cleanup()