예제 #1
0
    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!"))
예제 #2
0
파일: test_bus.py 프로젝트: robotika/osgar
    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!"))
예제 #3
0
파일: test_bus.py 프로젝트: robotika/osgar
    def test_publish(self):
        logger = MagicMock()
        bus = BusHandler(logger)
        with self.assertRaises(KeyError):
            bus.publish('raw', b'some binary data')

        logger = MagicMock()
        logger.register = MagicMock(return_value=1)
        bus = BusHandler(logger, out={'raw':[]})
        bus.publish('raw', b'some binary data 2nd try')
        logger.write.assert_called_once_with(1, b'\xc4\x18some binary data 2nd try')
예제 #4
0
    def test_publish(self):
        logger = MagicMock()
        bus = BusHandler(logger)
        with self.assertRaises(KeyError):
            bus.publish('raw', b'some binary data')

        logger = MagicMock()
        logger.register = MagicMock(return_value=1)
        bus = BusHandler(logger, out={'raw': []})
        bus.publish('raw', b'some binary data 2nd try')
        logger.write.assert_called_once_with(
            1, b'\xc4\x18some binary data 2nd try')
예제 #5
0
 def test_compression(self):
     logger = MagicMock()
     logger.register = MagicMock(return_value=1)
     bus = BusHandler(logger, out={'raw': []}, name='tcp_point_data')
     # TODO proper definition what should be compressed - now hardcoded to name "tcp_point_data"
     self.assertTrue(bus.compressed_output)
     bus.publish('raw', b'\00' * 10000)
     logger.write.assert_called_once_with(
         1,
         b'x\x9c\xed\xc1\x01\r\x00\x00\x08\x03 #\xbc\x85\xfdC\xd8\xcb\x1e\x1fp\x9b'
         +
         b'\x01\x00\x00\x00\x00\x00\x00\x00\x00\x80\x02\x0f\x9f\xba\x00\xfd'
     )
예제 #6
0
 def test_named_publish(self):
     logger = MagicMock()
     logger.register = MagicMock(return_value=1)
     bus = BusHandler(logger, name='gps_serial', out={'raw': []})
     bus.publish('raw', b'bin data')
     logger.write.assert_called_once_with(1, b'\xc4\x08bin data')
예제 #7
0
 def test_publish_serialization(self):
     logger = MagicMock()
     logger.register = MagicMock(return_value=1)
     bus = BusHandler(logger, out={'position': []})
     bus.publish('position', (-123, 456))
     logger.write.assert_called_once_with(1, b'\x92\xd0\x85\xcd\x01\xc8')
예제 #8
0
 def test_publish_time(self):
     logger = MagicMock()
     logger.register = MagicMock(return_value=1)
     logger.write = MagicMock(return_value=timedelta(123))
     bus = BusHandler(logger, out={'stdout': []})
     self.assertEqual(bus.publish('stdout', 'hello world!'), timedelta(123))
예제 #9
0
파일: test_bus.py 프로젝트: robotika/osgar
 def test_named_publish(self):
     logger = MagicMock()
     logger.register = MagicMock(return_value=1)
     bus = BusHandler(logger, name='gps_serial', out={'raw':[]})
     bus.publish('raw', b'bin data')
     logger.write.assert_called_once_with(1, b'\xc4\x08bin data')
예제 #10
0
파일: test_bus.py 프로젝트: robotika/osgar
 def test_publish_serialization(self):
     logger = MagicMock()
     logger.register = MagicMock(return_value=1)
     bus = BusHandler(logger, out={'position':[]})
     bus.publish('position', (-123, 456))
     logger.write.assert_called_once_with(1, b'\x92\xd0\x85\xcd\x01\xc8')
예제 #11
0
파일: test_bus.py 프로젝트: robotika/osgar
 def test_publish_time(self):
     logger = MagicMock()
     logger.register = MagicMock(return_value=1)
     logger.write = MagicMock(return_value=timedelta(123))
     bus = BusHandler(logger, out={'stdout':[]})
     self.assertEqual(bus.publish('stdout', 'hello world!'), timedelta(123))