Skip to content

Commit 8c9d061

Browse files
committed
Expand test coverage, bugfix
1 parent 250a3ec commit 8c9d061

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

library/enviroplus/gas.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import RPi.GPIO as GPIO
77

88
MICS6814_HEATER_PIN = 24
9-
MICS6814_GAIN = 6.148
9+
MICS6814_GAIN = 6.144
1010

1111
ads1015.I2C_ADDRESS_DEFAULT = ads1015.I2C_ADDRESS_ALTERNATE
1212
_is_setup = False
@@ -132,3 +132,9 @@ def read_nh3():
132132
"""Return gas resistance for nh3/ammonia"""
133133
setup()
134134
return read_all().nh3
135+
136+
137+
def read_adc():
138+
"""Return spare ADC channel value"""
139+
setup()
140+
return read_all().adc

library/tests/test_setup.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def test_gas_setup():
1616
smbus.SMBus = SMBusFakeDevice
1717
sys.modules['smbus'] = smbus
1818
from enviroplus import gas
19+
gas._is_setup = False
1920
gas.setup()
2021
gas.setup()
2122

@@ -27,6 +28,7 @@ def test_gas_read_all():
2728
smbus.SMBus = SMBusFakeDevice
2829
sys.modules['smbus'] = smbus
2930
from enviroplus import gas
31+
gas._is_setup = False
3032
result = gas.read_all()
3133

3234
assert type(result.oxidising) == float
@@ -48,7 +50,49 @@ def test_gas_read_each():
4850
smbus.SMBus = SMBusFakeDevice
4951
sys.modules['smbus'] = smbus
5052
from enviroplus import gas
53+
gas._is_setup = False
5154

5255
assert int(gas.read_oxidising()) == 16641
5356
assert int(gas.read_reducing()) == 16727
5457
assert int(gas.read_nh3()) == 16813
58+
59+
60+
def test_gas_read_adc():
61+
sys.modules['RPi'] = mock.Mock()
62+
sys.modules['RPi.GPIO'] = mock.Mock()
63+
smbus = mock.Mock()
64+
smbus.SMBus = SMBusFakeDevice
65+
sys.modules['smbus'] = smbus
66+
from enviroplus import gas
67+
gas._is_setup = False
68+
69+
gas.enable_adc(True)
70+
gas.set_adc_gain(2.048)
71+
assert gas.read_adc() == 0.255
72+
73+
74+
def test_gas_read_adc_default_gain():
75+
sys.modules['RPi'] = mock.Mock()
76+
sys.modules['RPi.GPIO'] = mock.Mock()
77+
smbus = mock.Mock()
78+
smbus.SMBus = SMBusFakeDevice
79+
sys.modules['smbus'] = smbus
80+
from enviroplus import gas
81+
gas._is_setup = False
82+
83+
gas.enable_adc(True)
84+
assert gas.read_adc() == 0.255
85+
86+
87+
def test_gas_read_adc_str():
88+
sys.modules['RPi'] = mock.Mock()
89+
sys.modules['RPi.GPIO'] = mock.Mock()
90+
smbus = mock.Mock()
91+
smbus.SMBus = SMBusFakeDevice
92+
sys.modules['smbus'] = smbus
93+
from enviroplus import gas
94+
gas._is_setup = False
95+
96+
gas.enable_adc(True)
97+
gas.set_adc_gain(2.048)
98+
assert 'ADC' in str(gas.read_all())

0 commit comments

Comments
 (0)