def test_STATUS(self): data = bytes([0x82, 0xde, 0xad, 0xbe, 0xef]) # status msg type with contextlib.ExitStack() as stack: from_buf = stack.enter_context( unittest.mock.patch.object( sbx_protocol.StatusMessage, "from_buf", )) result = sbx_protocol.decode_message(data) from_buf.assert_called_once_with(sbx_protocol.MsgType.STATUS, data[1:]) self.assertEqual(from_buf(), result)
def test_SENSOR_STREAM_COMPASS_Z(self): data = bytes([0xfd, 0xde, 0xad, 0xbe, 0xef]) # compass z msg type with contextlib.ExitStack() as stack: from_buf = stack.enter_context( unittest.mock.patch.object( sbx_protocol.SensorStreamMessage, "from_buf", )) result = sbx_protocol.decode_message(data) from_buf.assert_called_once_with( sbx_protocol.MsgType.SENSOR_STREAM_COMPASS_Z, data[1:]) self.assertEqual(from_buf(), result)
def test_SENSOR_DS18B20(self): data = bytes([0xf1, 0xde, 0xad, 0xbe, 0xef]) # ds18b20 msg type with contextlib.ExitStack() as stack: from_buf = stack.enter_context( unittest.mock.patch.object( sbx_protocol.DS18B20Message, "from_buf", )) result = sbx_protocol.decode_message(data) from_buf.assert_called_once_with(sbx_protocol.MsgType.SENSOR_DS18B20, data[1:]) self.assertEqual(from_buf(), result)