Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ccie18643 committed Sep 8, 2024
1 parent f5c1446 commit 2b26602
Show file tree
Hide file tree
Showing 31 changed files with 126 additions and 3 deletions.
4 changes: 3 additions & 1 deletion tests/lib/testcase__packet_rx.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ class TestCasePacketRx(TestCase):
"""

_args: list[Any] = []
_kwargs: dict[str, Any] = {}

_packet_rx: PacketRx

def setUp(self) -> None:
"""
Set up the PacketRx object.
"""

self._packet_rx = PacketRx(self._args[0])
self._packet_rx = PacketRx(*self._args, **self._kwargs)
3 changes: 2 additions & 1 deletion tests/lib/testcase__packet_rx__ip4.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class TestCasePacketRxIp4(TestCase):
"""

_args: list[Any] = []
_kwargs: dict[str, Any] = {}
_mocked_values: dict[str, Any] = {}
_packet_rx: PacketRx

Expand All @@ -57,7 +58,7 @@ def setUp(self) -> None:
Set up the mocked values for the IPv4 related fields.
"""

self._packet_rx = PacketRx(self._args[0])
self._packet_rx = PacketRx(*self._args, **self._kwargs)

self._packet_rx.ip = self._packet_rx.ip4 = cast(
Ip4Parser, StrictMock(template=Ip4Parser)
Expand Down
3 changes: 2 additions & 1 deletion tests/lib/testcase__packet_rx__ip6.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class TestCasePacketRxIp6(TestCase):
"""

_args: list[Any] = []
_kwargs: dict[str, Any] = {}
_mocked_values: dict[str, Any] = {}
_packet_rx: PacketRx

Expand All @@ -57,7 +58,7 @@ def setUp(self) -> None:
Set up the mocked values for the IPv6 related fields.
"""

self._packet_rx = PacketRx(self._args[0])
self._packet_rx = PacketRx(*self._args, **self._kwargs)

self._packet_rx.ip = self._packet_rx.ip6 = cast(
Ip6Parser, StrictMock(template=Ip6Parser)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
b"\x00\x01\x08\x00\x06\x04\x00\x01\x01\x02\x03\x04\x05\x06\x0b\x16"
b"\x21\x2c\x0a\x0b\x0c\x0d\x0e\x0f\x65\x66\x67"
],
"_kwargs": {},
"_results": {
"error_message": (
f"The minimum packet length must be {ARP__HEADER__LEN} "
Expand All @@ -67,6 +68,7 @@
b"\x00\x00\x08\x00\x06\x04\x00\x01\x01\x02\x03\x04\x05\x06\x0b\x16"
b"\x21\x2c\x0a\x0b\x0c\x0d\x0e\x0f\x65\x66\x67\x68"
],
"_kwargs": {},
"_results": {
"error_message": "The 'hrtype' field value must be one of [1], got 0.",
},
Expand All @@ -77,6 +79,7 @@
b"\x00\x01\x00\x00\x06\x04\x00\x01\x01\x02\x03\x04\x05\x06\x0b\x16"
b"\x21\x2c\x0a\x0b\x0c\x0d\x0e\x0f\x65\x66\x67\x68"
],
"_kwargs": {},
"_results": {
"error_message": "The 'prtype' field value must be one of [2048], got 0.",
},
Expand All @@ -87,6 +90,7 @@
b"\x00\x01\x08\x00\x00\x04\x00\x01\x01\x02\x03\x04\x05\x06\x0b\x16"
b"\x21\x2c\x0a\x0b\x0c\x0d\x0e\x0f\x65\x66\x67\x68"
],
"_kwargs": {},
"_results": {
"error_message": "The 'hrlen' field value must be 6, got 0.",
},
Expand All @@ -97,6 +101,7 @@
b"\x00\x01\x08\x00\x06\x00\x00\x01\x01\x02\x03\x04\x05\x06\x0b\x16"
b"\x21\x2c\x0a\x0b\x0c\x0d\x0e\x0f\x65\x66\x67\x68"
],
"_kwargs": {},
"_results": {
"error_message": "The 'prlen' field value must be 4, got 0.",
},
Expand All @@ -110,6 +115,7 @@ class TestArpParserIntegrityChecks(TestCasePacketRx):

_description: str
_args: list[Any]
_kwargs: dict[str, Any]
_results: dict[str, Any]

_packet_rx: PacketRx
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/protocols/arp/test__arp__parser__operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
b"\x00\x01\x08\x00\x06\x04\x00\x01\x01\x02\x03\x04\x05\x06\x0b\x16"
b"\x21\x2c\x0a\x0b\x0c\x0d\x0e\x0f\x65\x66\x67\x68"
],
"_kwargs": {},
"_results": {
"header": ArpHeader(
oper=ArpOperation.REQUEST,
Expand All @@ -69,6 +70,7 @@
b"\x00\x01\x08\x00\x06\x04\x00\x02\xa1\xb2\xc3\xd4\xe5\xf6\x05\x05"
b"\x05\x05\x7a\x7b\x7c\x7d\x7e\x7f\x07\x07\x07\x07"
],
"_kwargs": {},
"_results": {
"header": ArpHeader(
oper=ArpOperation.REPLY,
Expand All @@ -88,6 +90,7 @@ class TestArpHeaderParserOperation(TestCasePacketRx):

_description: str
_args: list[Any]
_kwargs: dict[str, Any]
_results: dict[str, Any]

_packet_rx: PacketRx
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/protocols/arp/test__arp__parser__sanity_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
b"\x00\x01\x08\x00\x06\x04\x00\x00\x01\x02\x03\x04\x05\x06\x0b\x16"
b"\x21\x2c\x0a\x0b\x0c\x0d\x0e\x0f\x65\x66\x67\x68"
],
"_kwargs": {},
"_results": {
"error_message": "The 'oper' field value must be one of [1, 2], got 0.",
},
Expand All @@ -64,6 +65,7 @@ class TestArpParserSanityChecks(TestCasePacketRx):

_description: str
_args: list[Any]
_kwargs: dict[str, Any]
_results: dict[str, Any]

_packet_rx: PacketRx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"The frame length is less than the value of the 'ETHERNET__HEADER__LEN' constant."
),
"_args": [b"\xa1\xb2\xc3\xd4\xe5\xf6\x11\x12\x13\x14\x15\x16\xff"],
"_kwargs": {},
"_results": {
"error_message": (
f"The minimum packet length must be {ETHERNET__HEADER__LEN} "
Expand All @@ -67,6 +68,7 @@ class TestEthernetParserIntegrityChecks(TestCasePacketRx):

_description: str
_args: list[Any]
_kwargs: dict[str, Any]
_results: dict[str, Any]

_packet_rx: PacketRx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
b"\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xff\xff\x30\x31"
b"\x32\x33\x34\x35\x36\x37\x38\x39\x41\x42\x43\x44\x45\x46"
],
"_kwargs": {},
"_results": {
"header": EthernetHeader(
dst=MacAddress("11:22:33:44:55:66"),
Expand All @@ -68,6 +69,7 @@
b"\xa1\xb2\xc3\xd4\xe5\xf6\x11\x12\x13\x14\x15\x16\xff\xff"
+ b"X" * 1500
],
"_kwargs": {},
"_results": {
"header": EthernetHeader(
dst=MacAddress("a1:b2:c3:d4:e5:f6"),
Expand All @@ -86,6 +88,7 @@ class TestEthernetHeaderParserOperation(TestCasePacketRx):

_description: str
_args: list[Any]
_kwargs: dict[str, Any]
_results: dict[str, Any]

_packet_rx: PacketRx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"_args": [
b"\xa1\xb2\xc3\xd4\xe5\xf6\x11\x12\x13\x14\x15\x16\x05\xff"
],
"_kwargs": {},
"_results": {
"error_message": (
"The minimum 'type' field value must be 0x0600, got 0x05ff."
Expand All @@ -67,6 +68,7 @@ class TestEthernetParserSanityChecks(TestCasePacketRx):

_description: str
_args: list[Any]
_kwargs: dict[str, Any]
_results: dict[str, Any]

_packet_rx: PacketRx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"constant."
),
"_args": [b"\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\x00"],
"_kwargs": {},
"_results": {
"error_message": (
f"The minimum packet length must be {ETHERNET_802_3__HEADER__LEN} "
Expand All @@ -74,6 +75,7 @@
b"\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\x00\x10\x30\x31"
b"\x32\x33\x34\x35\x36\x37\x38\x39\x41\x42\x43\x44\x45\x46\x47"
],
"_kwargs": {},
"_results": {
"error_message": (
f"Inconsistent payload length (16 bytes) in the Ethernet 802.3 header. "
Expand All @@ -87,6 +89,7 @@
b"\xa1\xb2\xc3\xd4\xe5\xf6\x11\x12\x13\x14\x15\x16\x05\xdd"
+ b"X" * (ETHERNET_802_3__PAYLOAD__MAX_LEN + 1)
],
"_kwargs": {},
"_results": {
"error_message": (
f"Payload length ({ETHERNET_802_3__PAYLOAD__MAX_LEN + 1} bytes) exceeds the "
Expand All @@ -103,6 +106,7 @@ class TestEthernet8023ParserIntegrityChecks(TestCasePacketRx):

_description: str
_args: list[Any]
_kwargs: dict[str, Any]
_results: dict[str, Any]

_packet_rx: PacketRx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
b"\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\x00\x10\x30\x31"
b"\x32\x33\x34\x35\x36\x37\x38\x39\x41\x42\x43\x44\x45\x46"
],
"_kwargs": {},
"_results": {
"header": Ethernet8023Header(
dst=MacAddress("11:22:33:44:55:66"),
Expand All @@ -72,6 +73,7 @@
b"\xa1\xb2\xc3\xd4\xe5\xf6\x11\x12\x13\x14\x15\x16\x05\xdc"
+ b"X" * ETHERNET_802_3__PAYLOAD__MAX_LEN
],
"_kwargs": {},
"_results": {
"header": Ethernet8023Header(
dst=MacAddress("a1:b2:c3:d4:e5:f6"),
Expand All @@ -90,6 +92,7 @@ class TestEthernet8023ParserOperation(TestCasePacketRx):

_description: str
_args: list[Any]
_kwargs: dict[str, Any]
_results: dict[str, Any]

_packet_rx: PacketRx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class TestEthernet8023ParserSanityChecks(TestCasePacketRx):

_description: str
_args: list[Any]
_kwargs: dict[str, Any]
_results: dict[str, Any]

_packet_rx: PacketRx
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/protocols/icmp4/test__icmp4__unknown__parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
b"\xff\xff\x31\x29\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x41\x42"
b"\x43\x44\x45\x46"
],
"_kwargs": {},
"_results": {
"message": Icmp4UnknownMessage(
type=Icmp4Type.from_int(255),
Expand All @@ -72,6 +73,7 @@ class TestIcmp4MessageUnknownParser(TestCasePacketRxIp4):

_description: str
_args: list[Any]
_kwargs: dict[str, Any]
_results: dict[str, Any]

_packet_rx: PacketRx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"the 'ICMP4_HEADER_LEN <= self._ip4_payload_len' condition not met."
),
"_args": [b"\xff\x00\xfb"],
"_kwargs": {},
"_mocked_values": {
"ip4__payload_len": 3,
},
Expand All @@ -68,6 +69,7 @@
"the 'self._ip4_payload_len <= len(self._frame)' condition not met."
),
"_args": [b"\xff\x00\xfb\x94\x30\x39\xd4"],
"_kwargs": {},
"_mocked_values": {
"ip4__payload_len": 8,
},
Expand All @@ -82,6 +84,7 @@
{
"_description": "ICMPv4 unknown message, invalid checksum.",
"_args": [b"\xff\x00\x00\x00\x30\x39\xd4\x31"],
"_kwargs": {},
"_mocked_values": {},
"_results": {
"error_message": "The packet checksum must be valid.",
Expand All @@ -96,6 +99,7 @@ class TestIcmp4UnknownParserIntegrityChecks(TestCasePacketRxIp4):

_description: str
_args: list[Any]
_kwargs: dict[str, Any]
_mocked_values: dict[str, Any]
_results: dict[str, Any]

Expand Down
2 changes: 2 additions & 0 deletions tests/unit/protocols/icmp6/test__icmp6__unknown__parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
b"\xff\xff\x31\x29\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x41\x42"
b"\x43\x44\x45\x46"
],
"_kwargs": {},
"mocked_values": {},
"_results": {
"message": Icmp6UnknownMessage(
Expand All @@ -73,6 +74,7 @@ class TestIcmp6UnknownParser(TestCasePacketRxIp6):

_description: str
_args: list[Any]
_kwargs: dict[str, Any]
_results: dict[str, Any]

_packet_rx: PacketRx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"the 'ICMP6_HEADER_LEN <= self._ip6_payload_len' condition not met."
),
"_args": [b"\x81\x00\xfb"],
"_kwargs": {},
"_mocked_values": {
"ip6__dlen": 3,
},
Expand All @@ -69,6 +70,7 @@
"the 'self._ip6__dlen <= len(self._frame)' condition not met."
),
"_args": [b"\x81\x00\xfb\x94\x30\x39\xd4"],
"_kwargs": {},
"_mocked_values": {
"ip6__dlen": 8,
},
Expand All @@ -83,6 +85,7 @@
{
"_description": "ICMPv6 Destination Unreachable message, invalid checksum.",
"_args": [b"\x81\x00\x00\x00\x30\x39\xd4\x31"],
"_kwargs": {},
"_mocked_values": {},
"_results": {
"error_message": "The packet checksum must be valid.",
Expand All @@ -97,6 +100,7 @@ class TestIcmp6UnknownParserIntegrityChecks(TestCasePacketRxIp6):

_description: str
_args: list[Any]
_kwargs: dict[str, Any]
_mocked_values: dict[str, Any]
_results: dict[str, Any]

Expand Down
Loading

0 comments on commit 2b26602

Please sign in to comment.