def test_two_modules(self): logger = MagicMock() handler2 = BusHandler(logger) handler1 = BusHandler(logger, out={'raw':[(handler2.queue, 42)]}) logger.write = MagicMock(return_value=123) handler1.publish('raw', b"Hello!") self.assertEqual(handler2.listen(), (123, 42, b"Hello!"))
def test_two_modules(self): logger = MagicMock() handler2 = BusHandler(logger) handler1 = BusHandler(logger, out={'raw': [(handler2.queue, 42)]}) logger.write = MagicMock(return_value=123) handler1.publish('raw', b"Hello!") self.assertEqual(handler2.listen(), (123, 42, b"Hello!"))
def test_processing(self): config = {} logger = MagicMock() robot_bus = BusHandler(logger, out={}, name='robot') bus = BusHandler(logger, out={'orientation':[(robot_bus.queue, 'orientation')], 'rotation':[]}, name='imu') imu = IMU(config, bus=bus) imu.start() imu.bus.queue.put((123, 'raw', self.nmea_line)) data = robot_bus.listen() imu.request_stop() imu.join()
def test_processing(self): config = {} logger = MagicMock() robot_bus = BusHandler(logger, out={}, name='robot') bus = BusHandler(logger, out={ 'orientation': [(robot_bus.queue, 'orientation')], 'rotation': [] }, name='imu') imu = IMU(config, bus=bus) imu.start() imu.bus.queue.put((123, 'raw', self.nmea_line)) data = robot_bus.listen() imu.request_stop() imu.join()
def test_shutdown(self): logger = MagicMock() handler = BusHandler(logger) handler.shutdown() with self.assertRaises(BusShutdownException): handler.listen()
def test_listen(self): logger = MagicMock() handler = BusHandler(logger) handler.queue.put((1, 2, b"bin data")) self.assertEqual(handler.listen(), (1, 2, b"bin data"))