Test: adds support for testing i2c reads
This commit is contained in:
@@ -14,11 +14,22 @@ answers = {
|
|||||||
(0x20, 0x15): add_crc([0x00,0x00])*2 ,#GET_BASELINE Invalid, should be more realistic data..
|
(0x20, 0x15): add_crc([0x00,0x00])*2 ,#GET_BASELINE Invalid, should be more realistic data..
|
||||||
(0x20, 0x1e): None,#SET_BASELINE
|
(0x20, 0x1e): None,#SET_BASELINE
|
||||||
}
|
}
|
||||||
|
|
||||||
class MockSMBus:
|
class MockSMBus:
|
||||||
def __init__(s):
|
def __init__(s):
|
||||||
s.status=None
|
s.status=None
|
||||||
|
|
||||||
def i2c_rdwr(s,*msgs):
|
def i2c_rdwr(s,*msgs):
|
||||||
print(i2c_msg.read)
|
for m in msgs:
|
||||||
|
if m.flags == 1:
|
||||||
|
s._process_read(m)
|
||||||
|
else:
|
||||||
|
s._process_write(m)
|
||||||
|
def _process_read(s,msg):
|
||||||
|
if s.status == None:
|
||||||
|
raise AssertionError("tired to read before write")
|
||||||
|
for i in range(len(s.status)):
|
||||||
|
msg.buf[i]=chr(s.status[i])
|
||||||
|
def _process_write(s,msg):
|
||||||
|
s.status = answers[tuple(msg)]
|
||||||
|
|
||||||
|
@@ -2,10 +2,19 @@ from .context import sgp30
|
|||||||
|
|
||||||
from mock_smbus2 import MockSMBus
|
from mock_smbus2 import MockSMBus
|
||||||
import unittest
|
import unittest
|
||||||
class BasicTestSuite(unittest.TestCase):
|
|
||||||
|
class TestConstructor(unittest.TestCase):
|
||||||
"""Basic test cases."""
|
"""Basic test cases."""
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.bus = MockSMBus()
|
self.bus = MockSMBus()
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
b=sgp30.sgp30.Sgp30(self.bus)
|
b=sgp30.sgp30.Sgp30(self.bus)
|
||||||
b.init_sgp()
|
b.init_sgp()
|
||||||
|
|
||||||
|
class SimpleTest(unittest.TestCase):
|
||||||
|
"""Basic test cases."""
|
||||||
|
def setUp(self):
|
||||||
|
self.bus = MockSMBus()
|
||||||
|
self.sgp=sgp30.sgp30.Sgp30(self.bus)
|
||||||
|
def test_read(self):
|
||||||
|
self.sgp.read_measurements()
|
||||||
|
Reference in New Issue
Block a user