Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ccie18643 committed Sep 4, 2024
1 parent 2252ac8 commit 9e4e87a
Show file tree
Hide file tree
Showing 23 changed files with 267 additions and 138 deletions.
11 changes: 7 additions & 4 deletions tests/unit/protocols/arp/test__arp__assembler__operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
[
{
"_description": "ARP Request.",
"_args": {
"_args": [],
"_kwargs": {
"arp__oper": ArpOperation.REQUEST,
"arp__sha": MacAddress("01:02:03:04:05:06"),
"arp__spa": Ip4Address("11.22.33.44"),
Expand Down Expand Up @@ -98,7 +99,8 @@
},
{
"_description": "ARP Reply.",
"_args": {
"_args": [],
"_kwargs": {
"arp__oper": ArpOperation.REPLY,
"arp__sha": MacAddress("a1:b2:c3:d4:e5:f6"),
"arp__spa": Ip4Address("5.5.5.5"),
Expand Down Expand Up @@ -147,15 +149,16 @@ class TestArpAssemblerPackets(TestCase):
"""

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

def setUp(self) -> None:
"""
Initialize the ARP packet assembler object with testcase arguments.
"""

self._arp__assembler = ArpAssembler(**self._args)
self._arp__assembler = ArpAssembler(*self._args, **self._kwargs)

def test__arp__assembler__len(self) -> None:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
[
{
"_description": "Ethernet packet with Raw payload (I).",
"_args": {
"_args": [],
"_kwargs": {
"ethernet__src": MacAddress("77:88:99:aa:bb:cc"),
"ethernet__dst": MacAddress("11:22:33:44:55:66"),
"ethernet__payload": RawAssembler(
Expand Down Expand Up @@ -83,7 +84,8 @@
},
{
"_description": "Ethernet packet with Raw payload (II).",
"_args": {
"_args": [],
"_kwargs": {
"ethernet__dst": MacAddress("a1:b2:c3:d4:e5:f6"),
"ethernet__src": MacAddress("11:12:13:14:15:16"),
"ethernet__payload": RawAssembler(raw__payload=b"X" * 1500),
Expand Down Expand Up @@ -121,15 +123,18 @@ class TestEthernetAssemblerOperation(TestCase):
"""

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

def setUp(self) -> None:
"""
Initialize the Ethernet packet assembler object with testcase arguments.
"""

self._ethernet__assembler = EthernetAssembler(**self._args)
self._ethernet__assembler = EthernetAssembler(
*self._args, **self._kwargs
)

def test__ehternet__assembler__len(self) -> None:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
[
{
"_description": "Ethernet 802.3 packet (I).",
"_args": {
"_args": [],
"_kwargs": {
"ethernet_802_3__src": MacAddress("77:88:99:aa:bb:cc"),
"ethernet_802_3__dst": MacAddress("11:22:33:44:55:66"),
"ethernet_802_3__payload": RawAssembler(
Expand Down Expand Up @@ -90,7 +91,8 @@
},
{
"_description": "Ethernet 802.3 packet (II).",
"_args": {
"_args": [],
"_kwargs": {
"ethernet_802_3__dst": MacAddress("a1:b2:c3:d4:e5:f6"),
"ethernet_802_3__src": MacAddress("11:12:13:14:15:16"),
"ethernet_802_3__payload": RawAssembler(
Expand Down Expand Up @@ -135,15 +137,18 @@ class TestEthernet8023AssemblerOperation(TestCase):
"""

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

def setUp(self) -> None:
"""
Set up the test environment.
"""

self._ethernet_802_3__assembler = Ethernet8023Assembler(**self._args)
self._ethernet_802_3__assembler = Ethernet8023Assembler(
*self._args, **self._kwargs
)

def test__ehternet_802_3__assembler__len(self) -> None:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
[
{
"_description": "ICMPv4 Destination Unreachable (Network) message.",
"_args": {
"_args": [],
"_kwargs": {
"code": Icmp4DestinationUnreachableCode.NETWORK,
"data": b"",
},
Expand All @@ -70,7 +71,8 @@
},
{
"_description": "ICMPv4 Destination Unreachable (Host) message.",
"_args": {
"_args": [],
"_kwargs": {
"code": Icmp4DestinationUnreachableCode.HOST,
"data": b"",
},
Expand All @@ -90,7 +92,8 @@
},
{
"_description": "ICMPv4 Destination Unreachable (Protocol) message.",
"_args": {
"_args": [],
"_kwargs": {
"code": Icmp4DestinationUnreachableCode.PROTOCOL,
"data": b"",
},
Expand All @@ -110,7 +113,8 @@
},
{
"_description": "ICMPv4 Destination Unreachable - (Port) message.",
"_args": {
"_args": [],
"_kwargs": {
"code": Icmp4DestinationUnreachableCode.PORT,
"data": b"",
},
Expand All @@ -130,7 +134,8 @@
},
{
"_description": "ICMPv4 Destination Unreachable (Fragmentation Needed) message.",
"_args": {
"_args": [],
"_kwargs": {
"code": Icmp4DestinationUnreachableCode.FRAGMENTATION_NEEDED,
"mtu": 1200,
"data": b"",
Expand All @@ -155,7 +160,8 @@
},
{
"_description": "ICMPv4 Destination Unreachable (Source Route Failed) message.",
"_args": {
"_args": [],
"_kwargs": {
"code": Icmp4DestinationUnreachableCode.SOURCE_ROUTE_FAILED,
"data": b"",
},
Expand All @@ -175,7 +181,8 @@
},
{
"_description": "ICMPv4 Destination Unreachable (Network Unknown) message.",
"_args": {
"_args": [],
"_kwargs": {
"code": Icmp4DestinationUnreachableCode.NETWORK_UNKNOWN,
"data": b"",
},
Expand All @@ -195,7 +202,8 @@
},
{
"_description": "ICMPv4 Destination Unreachable (Host Unknown) message.",
"_args": {
"_args": [],
"_kwargs": {
"code": Icmp4DestinationUnreachableCode.HOST_UNKNOWN,
"data": b"",
},
Expand All @@ -215,7 +223,8 @@
},
{
"_description": "ICMPv4 Destination Unreachable (Source Host Isolated) message.",
"_args": {
"_args": [],
"_kwargs": {
"code": Icmp4DestinationUnreachableCode.SOURCE_HOST_ISOLATED,
"data": b"",
},
Expand All @@ -235,7 +244,8 @@
},
{
"_description": "ICMPv4 Destination Unreachable (Network Prohibited) message'.",
"_args": {
"_args": [],
"_kwargs": {
"code": Icmp4DestinationUnreachableCode.NETWORK_PROHIBITED,
"data": b"",
},
Expand All @@ -255,7 +265,8 @@
},
{
"_description": "ICMPv4 Destination Unreachable (Host Prohibited) message.",
"_args": {
"_args": [],
"_kwargs": {
"code": Icmp4DestinationUnreachableCode.HOST_PROHIBITED,
"data": b"",
},
Expand All @@ -275,7 +286,8 @@
},
{
"_description": "ICMPv4 Destination Unreachable (Network TOS) message.",
"_args": {
"_args": [],
"_kwargs": {
"code": Icmp4DestinationUnreachableCode.NETWORK_TOS,
"data": b"",
},
Expand All @@ -295,7 +307,8 @@
},
{
"_description": "ICMPv4 Destination Unreachable (Host TOS) message.",
"_args": {
"_args": [],
"_kwargs": {
"code": Icmp4DestinationUnreachableCode.HOST_TOS,
"data": b"",
},
Expand All @@ -315,7 +328,8 @@
},
{
"_description": "ICMPv4 Destination Unreachable (Communication Prohibited) message.",
"_args": {
"_args": [],
"_kwargs": {
"code": Icmp4DestinationUnreachableCode.COMMUNICATION_PROHIBITED,
"data": b"",
},
Expand All @@ -337,7 +351,8 @@
},
{
"_description": "ICMPv4 Destination Unreachable (Host Precedence) message.",
"_args": {
"_args": [],
"_kwargs": {
"code": Icmp4DestinationUnreachableCode.HOST_PRECEDENCE,
"data": b"",
},
Expand All @@ -357,7 +372,8 @@
},
{
"_description": "ICMPv4 Destination Unreachable (Precedence Cutoff) message.",
"_args": {
"_args": [],
"_kwargs": {
"code": Icmp4DestinationUnreachableCode.PRECEDENCE_CUTOFF,
"data": b"",
},
Expand All @@ -377,7 +393,8 @@
},
{
"_description": "ICMPv4 Destination Unreachable message, non-empty payload.",
"_args": {
"_args": [],
"_kwargs": {
"code": Icmp4DestinationUnreachableCode.PORT,
"data": b"0123456789ABCDEF",
},
Expand All @@ -400,7 +417,8 @@
},
{
"_description": "ICMPv4 Destination Unreachable message, maximum length payload.",
"_args": {
"_args": [],
"_kwargs": {
"code": Icmp4DestinationUnreachableCode.PORT,
"data": b"X" * 65507,
},
Expand All @@ -426,7 +444,8 @@ class TestIcmp4DestinationUnreachableAssembler(TestCase):
"""

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

def setUp(self) -> None:
Expand All @@ -436,7 +455,9 @@ def setUp(self) -> None:
"""

self._icmp4__assembler = Icmp4Assembler(
icmp4__message=Icmp4DestinationUnreachableMessage(**self._args)
icmp4__message=Icmp4DestinationUnreachableMessage(
*self._args, **self._kwargs
)
)

def test__icmp4__message__destination_unreachable__assembler__len(
Expand Down
14 changes: 9 additions & 5 deletions tests/unit/protocols/icmp4/test__icmp4__echo_reply__assembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
[
{
"_description": "ICMPv4 Echo Reply message, empty data.",
"_args": {
"_args": [],
"_kwargs": {
"id": 12345,
"seq": 54321,
"data": b"",
Expand All @@ -73,7 +74,8 @@
},
{
"_description": "ICMPv4 Echo Reply message, non-empty data.",
"_args": {
"_args": [],
"_kwargs": {
"id": 12345,
"seq": 54321,
"data": b"0123456789ABCDEF",
Expand All @@ -99,7 +101,8 @@
},
{
"_description": "ICMPv4 Echo Reply message, maximum length of data.",
"_args": {
"_args": [],
"_kwargs": {
"id": 11111,
"seq": 22222,
"data": b"X" * 65507,
Expand Down Expand Up @@ -132,7 +135,8 @@ class TestIcmp4EchoReplyAssembler(TestCase):
"""

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

def setUp(self) -> None:
Expand All @@ -142,7 +146,7 @@ def setUp(self) -> None:
"""

self._icmp4__assembler = Icmp4Assembler(
icmp4__message=Icmp4EchoReplyMessage(**self._args)
icmp4__message=Icmp4EchoReplyMessage(*self._args, **self._kwargs)
)

def test__icmp4__echo_reply__assembler__len(self) -> None:
Expand Down
Loading

0 comments on commit 9e4e87a

Please sign in to comment.