X-Git-Url: https://zdv2.bktei.com/gitweb/EVA-2020-02-2.git/blobdiff_plain/a73ee7811dc8302651b4a2eb324431ff5dd4ea1e..be4d0fc9022240b5047654523aab877cbaa8a73d:/library/tests/test_setup.py diff --git a/library/tests/test_setup.py b/library/tests/test_setup.py index 7c25d94..95080b6 100644 --- a/library/tests/test_setup.py +++ b/library/tests/test_setup.py @@ -1,32 +1,15 @@ import sys import mock -from i2cdevice import MockSMBus -class SMBusFakeDevice(MockSMBus): - def __init__(self, i2c_bus): - MockSMBus.__init__(self, i2c_bus) - self.regs[0x00:0x01] = 0x0f, 0x00 - - -def test_gas_setup(): - sys.modules['RPi'] = mock.Mock() - sys.modules['RPi.GPIO'] = mock.Mock() - smbus = mock.Mock() - smbus.SMBus = SMBusFakeDevice - sys.modules['smbus'] = smbus +def test_gas_setup(GPIO, smbus): from enviroplus import gas gas._is_setup = False gas.setup() gas.setup() -def test_gas_read_all(): - sys.modules['RPi'] = mock.Mock() - sys.modules['RPi.GPIO'] = mock.Mock() - smbus = mock.Mock() - smbus.SMBus = SMBusFakeDevice - sys.modules['smbus'] = smbus +def test_gas_read_all(GPIO, smbus): from enviroplus import gas gas._is_setup = False result = gas.read_all() @@ -43,12 +26,7 @@ def test_gas_read_all(): assert "Oxidising" in str(result) -def test_gas_read_each(): - sys.modules['RPi'] = mock.Mock() - sys.modules['RPi.GPIO'] = mock.Mock() - smbus = mock.Mock() - smbus.SMBus = SMBusFakeDevice - sys.modules['smbus'] = smbus +def test_gas_read_each(GPIO, smbus): from enviroplus import gas gas._is_setup = False @@ -57,12 +35,7 @@ def test_gas_read_each(): 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 +def test_gas_read_adc(GPIO, smbus): from enviroplus import gas gas._is_setup = False @@ -71,12 +44,7 @@ def test_gas_read_adc(): 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 +def test_gas_read_adc_default_gain(GPIO, smbus): from enviroplus import gas gas._is_setup = False @@ -84,12 +52,7 @@ def test_gas_read_adc_default_gain(): 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 +def test_gas_read_adc_str(GPIO, smbus): from enviroplus import gas gas._is_setup = False