def test_serialize_response_code(self): test_pcom_msg = PCOMMessage(msg_type="COMMAND", contents={"COMMAND": 2000}) self.assertEqual( 2000, serial_encoding.serialize_response_code(test_pcom_msg)) test_pcom_msg.msg_type = "RESPONSE" test_pcom_msg.contents = {"STATUS": 0} self.assertEqual( 0, serial_encoding.serialize_response_code(test_pcom_msg)) test_pcom_msg.msg_type = "STREAM" test_pcom_msg.contents = {"STREAM": 100} self.assertEqual( 100, serial_encoding.serialize_response_code(test_pcom_msg)) test_pcom_msg.msg_type = "INVALID" self.assertRaises( Exception, lambda: serial_encoding.serialize_response_code(test_pcom_msg)) test_pcom_msg.msg_type = "PROPERTY" test_pcom_msg.contents = {"PROPERTY": 1000} self.assertEqual( 1000, serial_encoding.serialize_response_code(test_pcom_msg)) test_pcom_msg.contents = {"COMMAND": 1000} self.assertRaises( Exception, lambda: serial_encoding.serialize_response_code(test_pcom_msg))
def test_serialize_msg_type(self): PROPERTY_GET = MessageCategory.Order << CATEGORY_SHIFT | OrderSubType.Property << SUB_TYPE_SHIFT \ | OrderPropertyOption.Get_Property << OPTION_SHIFT PROPERTY_SET = MessageCategory.Order << CATEGORY_SHIFT | OrderSubType.Property << SUB_TYPE_SHIFT \ | OrderPropertyOption.Set_Property << OPTION_SHIFT STREAM_ON = MessageCategory.Order << CATEGORY_SHIFT | OrderSubType.Property << SUB_TYPE_SHIFT \ | OrderPropertyOption.Stream_On << OPTION_SHIFT STREAM_OFF = MessageCategory.Order << CATEGORY_SHIFT | OrderSubType.Property << SUB_TYPE_SHIFT \ | OrderPropertyOption.Stream_Off << OPTION_SHIFT test_pcom_msg = PCOMMessage(msg_type="COMMAND", contents={"COMMAND": 2000}) self.assertEqual(0x00, serial_encoding.serialize_msg_type(test_pcom_msg)) test_pcom_msg.msg_type = "PROPERTY" test_pcom_msg.contents = {"ACTION": "GET", "PROPERTY": 1000} self.assertEqual(PROPERTY_GET, serial_encoding.serialize_msg_type(test_pcom_msg)) test_pcom_msg.contents = {"ACTION": "SET", "PROPERTY": 2000, "VALUE": 10} self.assertEqual(PROPERTY_SET, serial_encoding.serialize_msg_type(test_pcom_msg)) test_pcom_msg.msg_type = "STREAM" test_pcom_msg.contents = {"RATE": 1000, "STOP": False} self.assertEqual(STREAM_ON, serial_encoding.serialize_msg_type(test_pcom_msg)) test_pcom_msg.contents = {"RATE": 1000, "STOP": True} self.assertEqual(STREAM_OFF, serial_encoding.serialize_msg_type(test_pcom_msg))
def test_serialize_response_code(self): test_pcom_msg = PCOMMessage(msg_type="COMMAND", contents={"COMMAND": 2000}) self.assertEqual(2000, serial_encoding.serialize_response_code(test_pcom_msg)) test_pcom_msg.msg_type = "RESPONSE" test_pcom_msg.contents = {"STATUS": 0} self.assertEqual(0, serial_encoding.serialize_response_code(test_pcom_msg)) test_pcom_msg.msg_type = "STREAM" test_pcom_msg.contents = {"STREAM": 100} self.assertEqual(100, serial_encoding.serialize_response_code(test_pcom_msg)) test_pcom_msg.msg_type = "INVALID" self.assertRaises(Exception, lambda: serial_encoding.serialize_response_code(test_pcom_msg)) test_pcom_msg.msg_type = "PROPERTY" test_pcom_msg.contents = {"PROPERTY": 1000} self.assertEqual(1000, serial_encoding.serialize_response_code(test_pcom_msg)) test_pcom_msg.contents = {"COMMAND" : 1000} self.assertEqual(None, serial_encoding.serialize_response_code(test_pcom_msg))