1
0
mirror of https://github.com/undera/pylgbst.git synced 2020-11-18 19:37:26 -08:00

Better test coverage

This commit is contained in:
Andrey Pohilko 2017-09-13 21:17:27 +03:00
parent 4dec2bb882
commit 8c85d249ed
2 changed files with 7 additions and 6 deletions

View File

@ -32,9 +32,9 @@ class MoveHub(object):
self.connection.set_notify_handler(self._notify) self.connection.set_notify_handler(self._notify)
self.connection.write(ENABLE_NOTIFICATIONS_HANDLE, ENABLE_NOTIFICATIONS_VALUE) self.connection.write(ENABLE_NOTIFICATIONS_HANDLE, ENABLE_NOTIFICATIONS_VALUE)
# while not self.notified: while not self.devices:
# log.debug("Waiting to be notified") log.debug("Waiting to be notified about devices...")
# time.sleep(1) time.sleep(0.1)
self.port_C = None self.port_C = None
self.port_D = None self.port_D = None

View File

@ -53,6 +53,7 @@ class ConnectionMock(Connection):
class GeneralTest(unittest.TestCase): class GeneralTest(unittest.TestCase):
def test_led(self): def test_led(self):
conn = ConnectionMock() conn = ConnectionMock()
conn.notifications.append((14, '1b0e00 0900 04 39 0227003738'))
hub = MoveHub(conn) hub = MoveHub(conn)
led = LED(hub, PORT_LED) led = LED(hub, PORT_LED)
led.set_color(COLOR_RED) led.set_color(COLOR_RED)
@ -60,6 +61,7 @@ class GeneralTest(unittest.TestCase):
def test_motor(self): def test_motor(self):
conn = ConnectionMock() conn = ConnectionMock()
conn.notifications.append((14, '1b0e00 0900 04 39 0227003738'))
hub = MoveHub(conn) hub = MoveHub(conn)
motor = EncodedMotor(hub, PORT_AB) motor = EncodedMotor(hub, PORT_AB)
motor.timed(1.5) motor.timed(1.5)
@ -69,8 +71,6 @@ class GeneralTest(unittest.TestCase):
def test_capabilities(self): def test_capabilities(self):
conn = ConnectionMock() conn = ConnectionMock()
hub = MoveHub(conn)
time.sleep(1)
conn.notifications.append((14, '1b0e00 0f00 04 01 0125000000001000000010')) conn.notifications.append((14, '1b0e00 0f00 04 01 0125000000001000000010'))
conn.notifications.append((14, '1b0e00 0f00 04 02 0126000000001000000010')) conn.notifications.append((14, '1b0e00 0f00 04 02 0126000000001000000010'))
conn.notifications.append((14, '1b0e00 0f00 04 37 0127000100000001000000')) conn.notifications.append((14, '1b0e00 0f00 04 37 0127000100000001000000'))
@ -82,7 +82,8 @@ class GeneralTest(unittest.TestCase):
conn.notifications.append((14, '1b0e00 0f00 04 3c 0114000200000002000000')) conn.notifications.append((14, '1b0e00 0f00 04 3c 0114000200000002000000'))
conn.notifications.append((14, '1b0e00 0f00 8202 01')) conn.notifications.append((14, '1b0e00 0f00 8202 01'))
conn.notifications.append((14, '1b0e00 0f00 8202 0a')) conn.notifications.append((14, '1b0e00 0f00 8202 0a'))
time.sleep(1)
hub = MoveHub(conn)
# demo_all(hub) # demo_all(hub)
conn.running = False conn.running = False