Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update test_packets_sub9.py #1100

Merged
merged 4 commits into from
Nov 10, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions mil_common/drivers/mil_usb_to_can/test/test_packets_sub9.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we need this comment. This is clear if you're using the library.

@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
Expand All @@ -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)
Expand All @@ -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)
Expand Down
Loading