From 9ec514ff92f1af2687eaa6c3218ed0af7f0f436d Mon Sep 17 00:00:00 2001 From: Simon Albinsson Date: Thu, 12 Apr 2018 19:49:43 +0000 Subject: [PATCH] adding basic tests for smbus --- tests/mock_smbus2.py | 24 ++++++++++++++++++++++++ tests/test_sgp.py | 11 +++++++++++ 2 files changed, 35 insertions(+) create mode 100644 tests/mock_smbus2.py create mode 100644 tests/test_sgp.py diff --git a/tests/mock_smbus2.py b/tests/mock_smbus2.py new file mode 100644 index 0000000..151000a --- /dev/null +++ b/tests/mock_smbus2.py @@ -0,0 +1,24 @@ +from smbus2 import i2c_msg + +from .context import sgp30 + +def add_crc(l): + return l + [sgp30.Crc8().hash(l)] + +answers = { + (0x36, 0x82): add_crc([0,0]) ,#GET_SERIAL + (0x20, 0x15): add_crc([0,0]) ,#GET_FEATURES + (0x20, 0x03): None ,#IAQ_INIT + (0x20, 0x08): [1, 144, 76, 0, 6, 39] ,#IAQ_MEASURE + (0x20, 0x32): add_crc([0xD4,0x00]),#IAQ_SELFTEST + (0x20, 0x15): add_crc([0x00,0x00])*2 ,#GET_BASELINE Invalid, should be more realistic data.. + (0x20, 0x1e): None,#SET_BASELINE +} +class MockSMBus: + def __init__(s): + s.status=None + + def i2c_rdwr(s,*msgs): + print(i2c_msg.read) + + diff --git a/tests/test_sgp.py b/tests/test_sgp.py new file mode 100644 index 0000000..d58d945 --- /dev/null +++ b/tests/test_sgp.py @@ -0,0 +1,11 @@ +from .context import sgp30 + +from mock_smbus2 import MockSMBus +import unittest +class BasicTestSuite(unittest.TestCase): + """Basic test cases.""" + def setUp(self): + self.bus = MockSMBus() + def test_init(self): + b=sgp30.sgp30.Sgp30(self.bus) + b.init_sgp()