Skip to content

Commit

Permalink
Expand test coverage, bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Jul 17, 2019
1 parent 250a3ec commit 8c9d061
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
8 changes: 7 additions & 1 deletion library/enviroplus/gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import RPi.GPIO as GPIO

MICS6814_HEATER_PIN = 24
MICS6814_GAIN = 6.148
MICS6814_GAIN = 6.144

ads1015.I2C_ADDRESS_DEFAULT = ads1015.I2C_ADDRESS_ALTERNATE
_is_setup = False
Expand Down Expand Up @@ -132,3 +132,9 @@ def read_nh3():
"""Return gas resistance for nh3/ammonia"""
setup()
return read_all().nh3


def read_adc():
"""Return spare ADC channel value"""
setup()
return read_all().adc
44 changes: 44 additions & 0 deletions library/tests/test_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def test_gas_setup():
smbus.SMBus = SMBusFakeDevice
sys.modules['smbus'] = smbus
from enviroplus import gas
gas._is_setup = False
gas.setup()
gas.setup()

Expand All @@ -27,6 +28,7 @@ def test_gas_read_all():
smbus.SMBus = SMBusFakeDevice
sys.modules['smbus'] = smbus
from enviroplus import gas
gas._is_setup = False
result = gas.read_all()

assert type(result.oxidising) == float
Expand All @@ -48,7 +50,49 @@ def test_gas_read_each():
smbus.SMBus = SMBusFakeDevice
sys.modules['smbus'] = 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():
sys.modules['RPi'] = mock.Mock()
sys.modules['RPi.GPIO'] = mock.Mock()
smbus = mock.Mock()
smbus.SMBus = SMBusFakeDevice
sys.modules['smbus'] = 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():
sys.modules['RPi'] = mock.Mock()
sys.modules['RPi.GPIO'] = mock.Mock()
smbus = mock.Mock()
smbus.SMBus = SMBusFakeDevice
sys.modules['smbus'] = smbus
from enviroplus import gas
gas._is_setup = False

gas.enable_adc(True)
assert gas.read_adc() == 0.255


def test_gas_read_adc_str():
sys.modules['RPi'] = mock.Mock()
sys.modules['RPi.GPIO'] = mock.Mock()
smbus = mock.Mock()
smbus.SMBus = SMBusFakeDevice
sys.modules['smbus'] = 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())

0 comments on commit 8c9d061

Please sign in to comment.