From 337e87c4b1e5c5373defc82707e3a2b9b5a2718d Mon Sep 17 00:00:00 2001 From: Mrinall Umasudhan Date: Wed, 25 Oct 2023 14:03:39 -0400 Subject: [PATCH 1/3] Update test_packets_sub9.py --- .../mil_usb_to_can/test/test_packets_sub9.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/mil_common/drivers/mil_usb_to_can/test/test_packets_sub9.py b/mil_common/drivers/mil_usb_to_can/test/test_packets_sub9.py index 01c1dc47a..a8234452e 100755 --- a/mil_common/drivers/mil_usb_to_can/test/test_packets_sub9.py +++ b/mil_common/drivers/mil_usb_to_can/test/test_packets_sub9.py @@ -6,9 +6,9 @@ from mil_usb_to_can.sub9 import Packet from mil_usb_to_can.sub9.packet import SYNC_CHAR_1, SYNC_CHAR_2 - +# payload_format must follow format characters listed here: https://docs.python.org/3/library/struct.html @dataclass -class TestPacket(Packet, msg_id=0x47, subclass_id=0x44, payload_format="BHf"): +class TestPacket(Packet, msg_id=0x47, subclass_id=0x44, payload_format="?Hd"): example_bool: bool example_int: int example_float: float @@ -23,7 +23,7 @@ def test_simple_packet(self): packet = TestPacket(False, 42, 3.14) self.assertEqual(packet.msg_id, 0x47) self.assertEqual(packet.subclass_id, 0x44) - self.assertEqual(packet.payload_format, "BHf") + self.assertEqual(packet.payload_format, "?Hd") self.assertEqual(packet.example_bool, False) self.assertEqual(packet.example_int, 42) self.assertEqual(packet.example_float, 3.14) @@ -35,6 +35,13 @@ def test_assembled_packet(self): self.assertEqual(assembled[1], SYNC_CHAR_2) self.assertEqual(assembled[2], packet.msg_id) self.assertEqual(assembled[3], packet.subclass_id) + + def test_format(self): + packet = TestPacket(False, 42, 3.14) + self.assertEqual( + TestPacket.from_bytes(TestPacket.__bytes__(packet)), + packet, + ) def test_comparisons(self): packet = TestPacket(False, 42, 3.14) From 995c7c1499237bf2604310fc9d4c95527fbd6c34 Mon Sep 17 00:00:00 2001 From: Mrinall Umasudhan Date: Thu, 26 Oct 2023 05:55:39 -0400 Subject: [PATCH 2/3] Update test_packets_sub9.py --- mil_common/drivers/mil_usb_to_can/test/test_packets_sub9.py | 1 - 1 file changed, 1 deletion(-) diff --git a/mil_common/drivers/mil_usb_to_can/test/test_packets_sub9.py b/mil_common/drivers/mil_usb_to_can/test/test_packets_sub9.py index a8234452e..0f4f58099 100755 --- a/mil_common/drivers/mil_usb_to_can/test/test_packets_sub9.py +++ b/mil_common/drivers/mil_usb_to_can/test/test_packets_sub9.py @@ -6,7 +6,6 @@ from mil_usb_to_can.sub9 import Packet from mil_usb_to_can.sub9.packet import SYNC_CHAR_1, SYNC_CHAR_2 -# payload_format must follow format characters listed here: https://docs.python.org/3/library/struct.html @dataclass class TestPacket(Packet, msg_id=0x47, subclass_id=0x44, payload_format="?Hd"): example_bool: bool From 5ed7ba6188e68ccb5a503c3a93fa1e55f2ea063a Mon Sep 17 00:00:00 2001 From: Cameron Brown Date: Thu, 26 Oct 2023 16:13:17 -0400 Subject: [PATCH 3/3] Reformatted sub9 usb_to_can test files with black --- mil_common/drivers/mil_usb_to_can/test/test_packets_sub9.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mil_common/drivers/mil_usb_to_can/test/test_packets_sub9.py b/mil_common/drivers/mil_usb_to_can/test/test_packets_sub9.py index 0f4f58099..c58a8c32c 100755 --- a/mil_common/drivers/mil_usb_to_can/test/test_packets_sub9.py +++ b/mil_common/drivers/mil_usb_to_can/test/test_packets_sub9.py @@ -6,6 +6,7 @@ from mil_usb_to_can.sub9 import Packet from mil_usb_to_can.sub9.packet import SYNC_CHAR_1, SYNC_CHAR_2 + @dataclass class TestPacket(Packet, msg_id=0x47, subclass_id=0x44, payload_format="?Hd"): example_bool: bool @@ -34,7 +35,7 @@ def test_assembled_packet(self): self.assertEqual(assembled[1], SYNC_CHAR_2) self.assertEqual(assembled[2], packet.msg_id) self.assertEqual(assembled[3], packet.subclass_id) - + def test_format(self): packet = TestPacket(False, 42, 3.14) self.assertEqual(