X-Git-Url: https://zdv2.bktei.com/gitweb/EVA-2020-02-2.git/blobdiff_plain/651e1c201721a5903d0136d937c234166232c8e3..c96f1398ca698205ad5506fc5cc9886f33dcaec2:/library/tests/test_setup.py?ds=sidebyside diff --git a/library/tests/test_setup.py b/library/tests/test_setup.py index e69de29..b912a37 100644 --- a/library/tests/test_setup.py +++ b/library/tests/test_setup.py @@ -0,0 +1,54 @@ +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 + from enviroplus import gas + 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 + from enviroplus import gas + result = gas.read_all() + + assert type(result.oxidising) == float + assert int(result.oxidising) == 16641 + + assert type(result.reducing) == float + assert int(result.reducing) == 16727 + + assert type(result.nh3) == float + assert int(result.nh3) == 16813 + + 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 + from enviroplus import gas + + assert int(gas.read_oxidising()) == 16641 + assert int(gas.read_reducing()) == 16727 + assert int(gas.read_nh3()) == 16813