From 38a7049de843beafbfd710d3deceb45f460758d9 Mon Sep 17 00:00:00 2001 From: Sebastian Majewski <49081304+ccie18643@users.noreply.github.com> Date: Sat, 26 Nov 2022 22:04:50 -0600 Subject: [PATCH] Merging the unit/integration type checking from PyTCP_2_7 (#22) * Working on docs * Working on docs * Update README.md * Update README.md * Working on docs * Working on docs * Working on docs * Working on docs * Working on docs * Working on docs * Working on docs * Working on docs * Working on docs * Working on docs * Working on docs * Working on docs * Working on docs * Adding CI workflow * Updated workflow name * Testing workflows * Working on docs * Working on docs * Working on docs * Working on docs * Working on docs * Working on docs * Working on docs * Working on docs * Working on docs * Working on docs * Working on docs * Working on docs * Working on docs * Working on docs * Working on docs * Working on docs * Working on docs * Working on docs * Working on docs * Working on docs * Update ci.yml * Update ci.yml * Update ci.yml * Create publish.yml * Update pyproject.toml * Working on workflows * Working on workflows * Working on docs * Changed version to 2.7.3 * Playing with CI * Playing with CI * Playing with CI * Working on proper typing unit test so MyPy is happy. * Enabled MyPy check for unit and integration tests * Version 2.7.4 -> 2.7.5 Co-authored-by: Sebastian Majewski --- .github/workflows/ci.yml | 1 + Makefile | 1 + pyproject.toml | 2 +- tests/integration/packet_flows_rx.py | 18 +++--- tests/integration/packet_flows_rx_tx.py | 78 +++++++++++++++---------- tests/unit/mock_network.py | 13 ++++- tests/unit/protocols__arp__phtx.py | 3 + tests/unit/protocols__ether__fpa.py | 4 +- tests/unit/protocols__ether__phtx.py | 21 ++++--- tests/unit/protocols__icmp4__phtx.py | 3 + tests/unit/protocols__icmp6__fpa.py | 46 ++++++++------- tests/unit/protocols__icmp6__phtx.py | 3 + tests/unit/protocols__ip4__fpa.py | 2 +- tests/unit/protocols__ip4__phtx.py | 22 ++++--- tests/unit/protocols__ip6__fpa.py | 4 +- tests/unit/protocols__ip6__phtx.py | 16 +++-- tests/unit/protocols__tcp__phtx.py | 3 + tests/unit/protocols__udp__phtx.py | 3 + 18 files changed, 147 insertions(+), 96 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1d985962..787deffa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,6 +41,7 @@ jobs: run: | mypy -p pytcp mypy -p examples + mypy -p tests - name: Test unit run: testslide tests/unit/*.py - name: Test integration diff --git a/Makefile b/Makefile index a261df81..6ea7f3f0 100644 --- a/Makefile +++ b/Makefile @@ -37,6 +37,7 @@ lint: venv @echo '<<< MYPY' @PYTHONPATH=$(ROOT_PATH) ./$(VENV)/bin/mypy -p ${PYTCP_PATH} @PYTHONPATH=$(ROOT_PATH) ./$(VENV)/bin/mypy -p ${EXAMPLES_PATH} + @PYTHONPATH=$(ROOT_PATH) ./$(VENV)/bin/mypy -p ${TESTS_PATH} test_unit: venv @echo '<<< TESTSLIDE UNIT' diff --git a/pyproject.toml b/pyproject.toml index c8d2897b..5591789e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "PyTCP" -version = "2.7.4" +version = "2.7.5" description = "TCP/IP stack written in Python." readme = "README.md" authors = [{ name = "Sebastian Majewski", email = "ccie18643@gmail.com" }] diff --git a/tests/integration/packet_flows_rx.py b/tests/integration/packet_flows_rx.py index effa479b..41d0e6e6 100755 --- a/tests/integration/packet_flows_rx.py +++ b/tests/integration/packet_flows_rx.py @@ -90,7 +90,7 @@ class TestPacketHandlerRx(TestCase): The RX packet flow integration test class. """ - def setUp(self): + def setUp(self) -> None: """ Set up the test environment. """ @@ -102,7 +102,7 @@ def setUp(self): # Initialize packet handler and manually set all the variables that # normally would require network connectivity self.packet_handler = PacketHandler() - self.packet_handler.mac_address = STACK_MAC_ADDRESS + self.packet_handler.mac_unicast = STACK_MAC_ADDRESS self.packet_handler.mac_multicast = [ STACK_IP6_HOST.address.solicited_node_multicast.multicast_mac ] @@ -115,7 +115,7 @@ def setUp(self): self.packet_tx = memoryview(bytearray(2048)) - def _patch_config(self): + def _patch_config(self) -> None: """ Patch critical config setting for all packet handler modules. """ @@ -131,7 +131,7 @@ def _patch_config(self): # Test name format: # 'test_name__protocol_tested__test_description__optional_condition' - def test_packet_flow_rx__ether__ether_unknown_dst(self): + def test_packet_flow_rx__ether__ether_unknown_dst(self) -> None: """ [Ethernet] Receive Ethernet packet with unknown destination MAC address, drop. @@ -153,7 +153,7 @@ def test_packet_flow_rx__ether__ether_unknown_dst(self): PacketStatsTx(), ) - def test_packet_flow_rx__ether__ether_malformed_header(self): + def test_packet_flow_rx__ether__ether_malformed_header(self) -> None: """ [Ethernet] Receive Ethernet packet with malformed header, drop. """ @@ -174,7 +174,7 @@ def test_packet_flow_rx__ether__ether_malformed_header(self): PacketStatsTx(), ) - def test_packet_flow_rx__ip4__ip4_unknown_dst(self): + def test_packet_flow_rx__ip4__ip4_unknown_dst(self) -> None: """ [IPv4] Receive IPv4 packet for unknown destination, drop. """ @@ -197,7 +197,7 @@ def test_packet_flow_rx__ip4__ip4_unknown_dst(self): PacketStatsTx(), ) - def test_packet_flow_rx__ip6__ip6_unknown_dst(self): + def test_packet_flow_rx__ip6__ip6_unknown_dst(self) -> None: """ [IPv6] Receive IPv6 packet for unknown destination, drop. """ @@ -220,7 +220,7 @@ def test_packet_flow_rx__ip6__ip6_unknown_dst(self): PacketStatsTx(), ) - def test_packet_flow_rx__arp__arp_unknown_tpa(self): + def test_packet_flow_rx__arp__arp_unknown_tpa(self) -> None: """ [ARP] Receive ARP Request packet for unknown IPv4 address, drop. """ @@ -244,7 +244,7 @@ def test_packet_flow_rx__arp__arp_unknown_tpa(self): PacketStatsTx(), ) - def test_packet_flow_rx_tx__icmp6_nd__nd_ns__dad(self): + def test_packet_flow_rx_tx__icmp6_nd__nd_ns__dad(self) -> None: """ [ICMPv6 ND] Receive ICMPv6 Neighbor Solicitation DAD packet, respond with Neighbor Advertisement. diff --git a/tests/integration/packet_flows_rx_tx.py b/tests/integration/packet_flows_rx_tx.py index cc3ac75d..253498b2 100755 --- a/tests/integration/packet_flows_rx_tx.py +++ b/tests/integration/packet_flows_rx_tx.py @@ -95,7 +95,7 @@ class TestPacketHandlerRxTx(TestCase): The RX-TX packet flow integration test class. """ - def setUp(self): + def setUp(self) -> None: """ Setup tests. """ @@ -107,7 +107,7 @@ def setUp(self): # Assembled packet result is usually taken from 'self.packet_tx', # below list is used only for tx fragmentation test where multiple # packets are being generated by single packet assembler run. - self.packets_tx = [] + self.packets_tx: list[memoryview] = [] self.mock_ArpCache = StrictMock(template=ArpCache) self.mock_callable( @@ -139,7 +139,9 @@ def setUp(self): method="enqueue", ).with_implementation( lambda _: _.assemble(self.packet_tx) - or self.packets_tx.append(self.packet_tx) + or self.packets_tx.append( + self.packet_tx + ) # type: ignore[func-returns-value] ) self.patch_attribute( target="pytcp.lib.stack", @@ -151,7 +153,7 @@ def setUp(self): # Initialize packet handler and manually set all the variables # that normally would require network connectivity. self.packet_handler = PacketHandler() - self.packet_handler.mac_address = STACK_MAC_ADDRESS + self.packet_handler.mac_unicast = STACK_MAC_ADDRESS self.packet_handler.mac_multicast = [ STACK_IP6_HOST.address.solicited_node_multicast.multicast_mac ] @@ -164,7 +166,7 @@ def setUp(self): self.packet_tx = memoryview(bytearray(2048)) - def _patch_config(self): + def _patch_config(self) -> None: """ Patch critical config setting for all packet handler modules. """ @@ -182,7 +184,7 @@ def _patch_config(self): # Test name format: # 'test_name__protocol_tested__test_description__optional_condition' - def test_packet_flow_rx_tx__icmp4__ip4_ping(self): + def test_packet_flow_rx_tx__icmp4__ip4_ping(self) -> None: """ [ICMPv4] Receive ICMPv4 echo-request packet, respond with echo-reply. """ @@ -217,7 +219,7 @@ def test_packet_flow_rx_tx__icmp4__ip4_ping(self): ) self.assertEqual(self.packet_tx[: len(packet_tx)], packet_tx) - def test_packet_flow_rx_tx__udp__ip4_udp_to_closed_port(self): + def test_packet_flow_rx_tx__udp__ip4_udp_to_closed_port(self) -> None: """ [UDP] Receive IPv4/UDP packet for closed port, respond with ICMPv4 unreachable packet. @@ -259,7 +261,7 @@ def test_packet_flow_rx_tx__udp__ip4_udp_to_closed_port(self): ) self.assertEqual(self.packet_tx[: len(packet_tx)], packet_tx) - def test_packet_flow_rx_tx__udp__ip4_udp_echo(self): + def test_packet_flow_rx_tx__udp__ip4_udp_echo(self) -> None: """ [UDP] Receive IPv4/UDP packet and echo it back to the sender. """ @@ -299,8 +301,8 @@ def test_packet_flow_rx_tx__udp__ip4_udp_echo(self): self.assertEqual(self.packet_tx[: len(packet_tx)], packet_tx) def _test_packet_flow_rx_tx__ip4_frag__ip4_udp_echo_rx_frag( - self, order: list(int) - ): + self, order: list[int] + ) -> None: """ [IPv4 frag] Receive fragmented IPv4/UDP packets and echo them back to the sender in specified order. @@ -346,7 +348,9 @@ def _test_packet_flow_rx_tx__ip4_frag__ip4_udp_echo_rx_frag( ) self.assertEqual(self.packet_tx[: len(packet_tx)], packet_tx) - def test_packet_flow_rx_tx__ip4_frag__ip4_udp_echo_rx_frag_01234(self): + def test_packet_flow_rx_tx__ip4_frag__ip4_udp_echo_rx_frag_01234( + self, + ) -> None: """ [IPv4 frag] Receive fragmented IPv4/UDP packets and echo them back to the sender. @@ -355,7 +359,9 @@ def test_packet_flow_rx_tx__ip4_frag__ip4_udp_echo_rx_frag_01234(self): [0, 1, 2, 3, 4] ) - def test_packet_flow_rx_tx__ip4_frag__ip4_udp_echo_rx_frag_43210(self): + def test_packet_flow_rx_tx__ip4_frag__ip4_udp_echo_rx_frag_43210( + self, + ) -> None: """ [IPv4 frag] Receive fragmented IPv4/UDP packets and echo them back to the sender. @@ -364,7 +370,9 @@ def test_packet_flow_rx_tx__ip4_frag__ip4_udp_echo_rx_frag_43210(self): [4, 3, 2, 1, 0] ) - def test_packet_flow_rx_tx__ip4_frag__ip4_udp_echo_rx_frag_12043(self): + def test_packet_flow_rx_tx__ip4_frag__ip4_udp_echo_rx_frag_12043( + self, + ) -> None: """ [IPv4 frag] Receive fragmented IPv4/UDP packets and echo them back to the sender. @@ -376,7 +384,7 @@ def test_packet_flow_rx_tx__ip4_frag__ip4_udp_echo_rx_frag_12043(self): def test_packet_flow_rx_tx__ip4_frag__ip4_udp_echo_rx_frag_1202103341( self, - ): + ) -> None: """ [IPv4 frag] Receive fragmented IPv4/UDP packets and echo them back to the sender. @@ -385,7 +393,7 @@ def test_packet_flow_rx_tx__ip4_frag__ip4_udp_echo_rx_frag_1202103341( [1, 2, 0, 2, 1, 0, 3, 3, 4, 1] ) - def test_packet_flow_rx_tx__ip4_frag__ip4_udp_echo_tx_frag(self): + def test_packet_flow_rx_tx__ip4_frag__ip4_udp_echo_tx_frag(self) -> None: """ [IPv4 frag] Receive IPv4/UDP packet and echo it back to the sender in fragments. @@ -432,7 +440,7 @@ def test_packet_flow_rx_tx__ip4_frag__ip4_udp_echo_tx_frag(self): self.packets_tx[index][: len(frags[index])], frags[index] ) - def test_packet_flow_rx_tx__tcp__ip4_tcp_syn_to_closed_port(self): + def test_packet_flow_rx_tx__tcp__ip4_tcp_syn_to_closed_port(self) -> None: """ [TCP] Receive IPv4/TCP SYN packet to closed port, respond with IPv4/TCP RST/ACK packet. @@ -476,7 +484,7 @@ def test_packet_flow_rx_tx__tcp__ip4_tcp_syn_to_closed_port(self): ) self.assertEqual(self.packet_tx[: len(packet_tx)], packet_tx) - def test_packet_flow_rx_tx__icmp6__ip6_ping(self): + def test_packet_flow_rx_tx__icmp6__ip6_ping(self) -> None: """ [ICMPv6] Receive ICMPv6 echo-request packet, respond with echo-reply. """ @@ -511,7 +519,7 @@ def test_packet_flow_rx_tx__icmp6__ip6_ping(self): ) self.assertEqual(self.packet_tx[: len(packet_tx)], packet_tx) - def test_packet_flow_rx_tx__udp__ip6_udp_to_closed_port(self): + def test_packet_flow_rx_tx__udp__ip6_udp_to_closed_port(self) -> None: """ [UDP] Receive IPv6/UDP packet for closed port, respond with ICMPv6 unreachable packet. @@ -553,7 +561,7 @@ def test_packet_flow_rx_tx__udp__ip6_udp_to_closed_port(self): ) self.assertEqual(self.packet_tx[: len(packet_tx)], packet_tx) - def test_packet_flow_rx_tx__udp__ip6_udp_echo(self): + def test_packet_flow_rx_tx__udp__ip6_udp_echo(self) -> None: """ [UDP] Receive IPv4/UDP packet and echo it back to the sender. """ @@ -593,8 +601,8 @@ def test_packet_flow_rx_tx__udp__ip6_udp_echo(self): self.assertEqual(self.packet_tx[: len(packet_tx)], packet_tx) def _test_packet_flow_rx_tx__ip6_frag__ip6_udp_echo_rx_frag( - self, order: list(int) - ): + self, order: list[int] + ) -> None: """ [IPv6 frag] Receive fragmented IPv6/UDP packets and echo them back to the sender in specified order. @@ -642,7 +650,9 @@ def _test_packet_flow_rx_tx__ip6_frag__ip6_udp_echo_rx_frag( ) self.assertEqual(self.packet_tx[: len(packet_tx)], packet_tx) - def test_packet_flow_rx_tx__ip6_frag__ip6_udp_echo_rx_frag_01234(self): + def test_packet_flow_rx_tx__ip6_frag__ip6_udp_echo_rx_frag_01234( + self, + ) -> None: """ [IPv6 frag] Receive fragmented IPv6/UDP packets and echo them back to the sender. @@ -651,7 +661,9 @@ def test_packet_flow_rx_tx__ip6_frag__ip6_udp_echo_rx_frag_01234(self): [0, 1, 2, 3, 4] ) - def test_packet_flow_rx_tx__ip6_frag__ip6_udp_echo_rx_frag_43210(self): + def test_packet_flow_rx_tx__ip6_frag__ip6_udp_echo_rx_frag_43210( + self, + ) -> None: """ [IPv6 frag] Receive fragmented IPv6/UDP packets and echo them back to the sender. @@ -660,7 +672,9 @@ def test_packet_flow_rx_tx__ip6_frag__ip6_udp_echo_rx_frag_43210(self): [4, 3, 2, 1, 0] ) - def test_packet_flow_rx_tx__ip6_frag__ip6_udp_echo_rx_frag_12043(self): + def test_packet_flow_rx_tx__ip6_frag__ip6_udp_echo_rx_frag_12043( + self, + ) -> None: """ [IPv6 frag] Receive fragmented IPv6/UDP packets and echo them back to the sender. @@ -671,7 +685,7 @@ def test_packet_flow_rx_tx__ip6_frag__ip6_udp_echo_rx_frag_12043(self): def test_packet_flow_rx_tx__ip6_frag__ip6_udp_echo_rx_frag_1202103341( self, - ): + ) -> None: """ [IPv6 frag] Receive fragmented IPv6/UDP packets and echo them back to the sender. @@ -680,7 +694,7 @@ def test_packet_flow_rx_tx__ip6_frag__ip6_udp_echo_rx_frag_1202103341( [1, 2, 0, 2, 1, 0, 3, 3, 4, 1] ) - def test_packet_flow_rx_tx__ip6_frag__ip6_udp_echo_tx_frag(self): + def test_packet_flow_rx_tx__ip6_frag__ip6_udp_echo_tx_frag(self) -> None: """ [IPv6 frag] Receive IPv4/UDP packet and echo it back to the sender in fragments. @@ -730,7 +744,7 @@ def test_packet_flow_rx_tx__ip6_frag__ip6_udp_echo_tx_frag(self): self.packets_tx[index][: len(frags[index])], frags[index] ) - def test_packet_flow_rx_tx__tcp__ip6_tcp_syn_to_closed_port(self): + def test_packet_flow_rx_tx__tcp__ip6_tcp_syn_to_closed_port(self) -> None: """ [TCP] Receive IPv6/TCP SYN packet to closed port, respond with IPv6/TCP RST/ACK packet. @@ -774,7 +788,7 @@ def test_packet_flow_rx_tx__tcp__ip6_tcp_syn_to_closed_port(self): ) self.assertEqual(self.packet_tx[: len(packet_tx)], packet_tx) - def test_packet_flow_rx_tx__arp__arp_request(self): + def test_packet_flow_rx_tx__arp__arp_request(self) -> None: """ [ARP] Receive ARP Request packet for stack IPv4 address, respond with ARP Reply. @@ -814,7 +828,7 @@ def test_packet_flow_rx_tx__arp__arp_request(self): ) self.assertEqual(self.packet_tx[: len(packet_tx)], packet_tx) - def test_packet_flow_rx_tx__icmp6_nd__nd_ns__unicast_dst(self): + def test_packet_flow_rx_tx__icmp6_nd__nd_ns__unicast_dst(self) -> None: """ [ICMPv6 ND] Receive ICMPv6 Neighbor Solicitation packet for stack IPv6 address, respond with Neighbor Advertisement. @@ -858,7 +872,7 @@ def test_packet_flow_rx_tx__icmp6_nd__nd_ns__unicast_dst(self): ) self.assertEqual(self.packet_tx[: len(packet_tx)], packet_tx) - def test_packet_flow_rx_tx__icmp6_nd__nd_ns__no_slla(self): + def test_packet_flow_rx_tx__icmp6_nd__nd_ns__no_slla(self) -> None: """ [ICMPv6 ND] Receive ICMPv6 Neighbor Solicitation packet, respond with Neighbor Advertisement. @@ -901,7 +915,7 @@ def test_packet_flow_rx_tx__icmp6_nd__nd_ns__no_slla(self): ) self.assertEqual(self.packet_tx[: len(packet_tx)], packet_tx) - def test_packet_flow_rx_tx__icmp6_nd__nd_ns(self): + def test_packet_flow_rx_tx__icmp6_nd__nd_ns(self) -> None: """ [ICMPv6 ND] Receive ICMPv6 Neighbor Solicitation packet, respond with Neighbor Advertisement. @@ -943,7 +957,7 @@ def test_packet_flow_rx_tx__icmp6_nd__nd_ns(self): ) self.assertEqual(self.packet_tx[: len(packet_tx)], packet_tx) - def test_packet_flow_rx_tx__icmp6_nd__nd_ns__dad(self): + def test_packet_flow_rx_tx__icmp6_nd__nd_ns__dad(self) -> None: """ [ICMPv6 ND] Receive ICMPv6 Neighbor Solicitation DAD packet, respond with Neighbor Advertisement diff --git a/tests/unit/mock_network.py b/tests/unit/mock_network.py index 7278c889..9abc7c1c 100755 --- a/tests/unit/mock_network.py +++ b/tests/unit/mock_network.py @@ -32,7 +32,9 @@ # -from testslide import StrictMock +from typing import no_type_check + +from testslide import StrictMock, TestCase from pytcp.lib.ip4_address import Ip4Address, Ip4Host from pytcp.lib.ip6_address import Ip6Address, Ip6Host @@ -149,7 +151,7 @@ def __init__(self) -> None: } -def patch_config(self, *, enable_log=False): +def patch_config(self: TestCase, *, enable_log: bool = False) -> None: """ Patch critical config setting for all packet handler modules. """ @@ -176,7 +178,12 @@ def patch_config(self, *, enable_log=False): continue -def setup_mock_packet_handler(self) -> None: +# Had to disable type checking in this function because it modifies variables +# pulled from the TestCase. +# This whole design is retarded and needs to be replaced with custom TestCase +# class. +@no_type_check +def setup_mock_packet_handler(self: TestCase) -> None: """ Prepare packet handler so it can pass packets without need of being physically connected to the network. diff --git a/tests/unit/protocols__arp__phtx.py b/tests/unit/protocols__arp__phtx.py index 32afb7e1..d2c7d487 100755 --- a/tests/unit/protocols__arp__phtx.py +++ b/tests/unit/protocols__arp__phtx.py @@ -37,6 +37,7 @@ from pytcp.lib.packet_stats import PacketStatsTx from pytcp.lib.tx_status import TxStatus from pytcp.protocols.arp.ps import ARP_OP_REPLY, ARP_OP_REQUEST +from pytcp.subsystems.packet_handler import PacketHandler from tests.unit.mock_network import ( MockNetworkSettings, patch_config, @@ -59,6 +60,8 @@ def setUp(self) -> None: self.mns = MockNetworkSettings() patch_config(self) setup_mock_packet_handler(self) + self.frame_tx: bytearray + self.packet_handler: PacketHandler # Test name format: 'test_name__test_description__optional_condition' diff --git a/tests/unit/protocols__ether__fpa.py b/tests/unit/protocols__ether__fpa.py index 0a545981..3208e2f2 100755 --- a/tests/unit/protocols__ether__fpa.py +++ b/tests/unit/protocols__ether__fpa.py @@ -106,7 +106,7 @@ def test_ether_fpa____init____assert_ethertype_unknown(self) -> None: carried_packet_mock = StrictMock() carried_packet_mock.ether_type = -1 carried_packet_mock.tracker = StrictMock(Tracker) - EtherAssembler(carried_packet=carried_packet_mock) + EtherAssembler(carried_packet=carried_packet_mock) # type: ignore[arg-type] def test_ether_fpa____len__(self) -> None: """ @@ -142,7 +142,7 @@ def test_ether_fpa__tracker_getter(self) -> None: carried_packet_mock.ether_type = ETHER_TYPE_RAW carried_packet_mock.tracker = StrictMock(Tracker) - packet = EtherAssembler(carried_packet=carried_packet_mock) + packet = EtherAssembler(carried_packet=carried_packet_mock) # type: ignore[arg-type] self.assertEqual(packet.tracker, carried_packet_mock.tracker) diff --git a/tests/unit/protocols__ether__phtx.py b/tests/unit/protocols__ether__phtx.py index 634feac5..a6ecdf85 100755 --- a/tests/unit/protocols__ether__phtx.py +++ b/tests/unit/protocols__ether__phtx.py @@ -42,6 +42,7 @@ from pytcp.lib.packet_stats import PacketStatsTx from pytcp.lib.tx_status import TxStatus +from pytcp.subsystems.packet_handler import PacketHandler from tests.unit.mock_network import ( MockNetworkSettings, patch_config, @@ -64,6 +65,8 @@ def setUp(self) -> None: self.mns = MockNetworkSettings() patch_config(self) setup_mock_packet_handler(self) + self.frame_tx: bytearray + self.packet_handler: PacketHandler # Test name format: 'test_name__test_description__optional_condition' @@ -213,7 +216,7 @@ def test_ether_phtx__ip4_packet_to_local_network_network_address( def test_ether_phtx__ip4_packet_to_unicast_address_on_local_network__arp_cache_miss( self, - ): + ) -> None: """ Test sending IPv4 packet to unicast address on local network / arp cache miss. @@ -237,7 +240,7 @@ def test_ether_phtx__ip4_packet_to_unicast_address_on_local_network__arp_cache_m def test_ether_phtx__ip4_packet_to_unicast_address_on_external_network( self, - ): + ) -> None: """ Test sending IPv4 packet to unicast address on external network. """ @@ -267,7 +270,7 @@ def test_ether_phtx__ip4_packet_to_unicast_address_on_external_network( def test_ether_phtx__ip4_packet_to_unicast_address_on_external_network__no_gateway( self, - ): + ) -> None: """ Test sending IPv4 packet to unicast address on external network / no gateway set. @@ -293,7 +296,7 @@ def test_ether_phtx__ip4_packet_to_unicast_address_on_external_network__no_gatew def test_ether_phtx__ip4_packet_to_unicast_address_on_external_network__gateway_arp_cache_miss( self, - ): + ) -> None: """ Test sending IPv4 packet to unicast address on external network / gateway ARP cache miss. @@ -381,7 +384,7 @@ def test_ether_phtx__ip6_packet_to_multicast_address(self) -> None: def test_ether_phtx__ip6_packet_to_unicast_address_on_local_network__nd_cache_miss( self, - ): + ) -> None: """ Test sending IPv6 packet to unicast address on local network / ND cache miss. @@ -405,7 +408,7 @@ def test_ether_phtx__ip6_packet_to_unicast_address_on_local_network__nd_cache_mi def test_ether_phtx__ip6_packet_to_unicast_address_on_external_network( self, - ): + ) -> None: """ Test sending IPv6 packet to unicast address on external network. """ @@ -435,7 +438,7 @@ def test_ether_phtx__ip6_packet_to_unicast_address_on_external_network( def test_ether_phtx__ip6_packet_to_unicast_address_on_external_network__no_gateway( self, - ): + ) -> None: """ Test sending IPv6 packet to unicast address on external network / no gateway set. @@ -460,7 +463,7 @@ def test_ether_phtx__ip6_packet_to_unicast_address_on_external_network__no_gatew def test_ether_phtx__ip6_packet_to_unicast_address_on_external_network__gateway_nd_cache_miss( self, - ): + ) -> None: """ Test sending IPv6 packet to unicast address on external network / gateway ND cache miss. @@ -541,7 +544,7 @@ def test_ether_phtx__ether_packet_with_unspecified_source_mac_address( def test_ether_phtx__ether_packet_with_unspecified_destination_mac_address( self, - ): + ) -> None: """ Send Ethernet packet with unspecified destination MAC address. """ diff --git a/tests/unit/protocols__icmp4__phtx.py b/tests/unit/protocols__icmp4__phtx.py index 435890d8..06792888 100755 --- a/tests/unit/protocols__icmp4__phtx.py +++ b/tests/unit/protocols__icmp4__phtx.py @@ -42,6 +42,7 @@ ICMP4_UNREACHABLE, ICMP4_UNREACHABLE__PORT, ) +from pytcp.subsystems.packet_handler import PacketHandler from tests.unit.mock_network import ( MockNetworkSettings, patch_config, @@ -64,6 +65,8 @@ def setUp(self) -> None: self.mns = MockNetworkSettings() patch_config(self) setup_mock_packet_handler(self) + self.frame_tx: bytearray + self.packet_handler: PacketHandler # Test name format: 'test_name__test_description__optional_condition' diff --git a/tests/unit/protocols__icmp6__fpa.py b/tests/unit/protocols__icmp6__fpa.py index 43267fff..21c36369 100755 --- a/tests/unit/protocols__icmp6__fpa.py +++ b/tests/unit/protocols__icmp6__fpa.py @@ -342,7 +342,7 @@ def test_icmp6_fpa____init____nd_router_solicitation(self) -> None: def test_icmp6_fpa____init____nd_router_solicitation__assert_code__under( self, - ): + ) -> None: """ Test packet constructor for the 'ND Router Solicitation' message. """ @@ -354,7 +354,7 @@ def test_icmp6_fpa____init____nd_router_solicitation__assert_code__under( def test_icmp6_fpa____init____nd_router_solicitation__assert_code__over( self, - ): + ) -> None: """ Test packet constructor for the 'ND Router Solicitation' message. """ @@ -368,6 +368,7 @@ def test_icmp6_fpa____init____nd_router_advertisement(self) -> None: """ Test packet constructor for the 'ND Router Advertisement' message. """ + packet = Icmp6Assembler( type=ICMP6_ND_ROUTER_ADVERTISEMENT, code=0, @@ -383,12 +384,13 @@ def test_icmp6_fpa____init____nd_router_advertisement(self) -> None: ], echo_tracker=Tracker(prefix="TX"), ) - self.assertEqual(packet._ra_hop, 255), - self.assertEqual(packet._ra_flag_m, True), - self.assertEqual(packet._ra_flag_o, True), - self.assertEqual(packet._ra_router_lifetime, 12345), - self.assertEqual(packet._ra_reachable_time, 12345678), - self.assertEqual(packet._ra_retrans_timer, 87654321), + + self.assertEqual(packet._ra_hop, 255) + self.assertEqual(packet._ra_flag_m, True) + self.assertEqual(packet._ra_flag_o, True) + self.assertEqual(packet._ra_router_lifetime, 12345) + self.assertEqual(packet._ra_reachable_time, 12345678) + self.assertEqual(packet._ra_retrans_timer, 87654321) self.assertEqual( packet._nd_options, [ @@ -404,7 +406,7 @@ def test_icmp6_fpa____init____nd_router_advertisement(self) -> None: def test_icmp6_fpa____init____nd_router_advertisement__assert_code__under( self, - ): + ) -> None: """ Test packet constructor for the 'ND Router Advertisement' message. """ @@ -416,7 +418,7 @@ def test_icmp6_fpa____init____nd_router_advertisement__assert_code__under( def test_icmp6_fpa____init____nd_router_advertisement__assert_code__over( self, - ): + ) -> None: """ Test packet constructor for the 'ND Router Advertisement' message. """ @@ -428,7 +430,7 @@ def test_icmp6_fpa____init____nd_router_advertisement__assert_code__over( def test_icmp6_fpa____init____nd_router_advertisement__assert_hop__under( self, - ): + ) -> None: """ Test packet constructor for the 'ND Router Advertisement' message. """ @@ -440,7 +442,7 @@ def test_icmp6_fpa____init____nd_router_advertisement__assert_hop__under( def test_icmp6_fpa____init____nd_router_advertisement__assert_hop__over( self, - ): + ) -> None: """ Test packet constructor for the 'ND Router Advertisement' message. """ @@ -452,7 +454,7 @@ def test_icmp6_fpa____init____nd_router_advertisement__assert_hop__over( def test_icmp6_fpa____init____nd_router_advertisement__assert_router_lifetime__under( self, - ): + ) -> None: """ Test packet constructor for the 'ND Router Advertisement' message. """ @@ -464,7 +466,7 @@ def test_icmp6_fpa____init____nd_router_advertisement__assert_router_lifetime__u def test_icmp6_fpa____init____nd_router_advertisement__assert_router_lifetime__over( self, - ): + ) -> None: """ Test packet constructor for the 'ND Router Advertisement' message. """ @@ -476,7 +478,7 @@ def test_icmp6_fpa____init____nd_router_advertisement__assert_router_lifetime__o def test_icmp6_fpa____init____nd_router_advertisement__assert_reachable_time__under( self, - ): + ) -> None: """ Test packet constructor for the 'ND Router Advertisement' message. """ @@ -488,7 +490,7 @@ def test_icmp6_fpa____init____nd_router_advertisement__assert_reachable_time__un def test_icmp6_fpa____init____nd_router_advertisement__assert_reachable_time__over( self, - ): + ) -> None: """ Test packet constructor for the 'ND Router Advertisement' message. """ @@ -500,7 +502,7 @@ def test_icmp6_fpa____init____nd_router_advertisement__assert_reachable_time__ov def test_icmp6_fpa____init____nd_router_advertisement__assert_retrans_timer__under( self, - ): + ) -> None: """ Test packet constructor for the 'ND Router Advertisement' message. """ @@ -512,7 +514,7 @@ def test_icmp6_fpa____init____nd_router_advertisement__assert_retrans_timer__und def test_icmp6_fpa____init____nd_router_advertisement__assert_retrans_timer__over( self, - ): + ) -> None: """ Test packet constructor for the 'ND Router Advertisement' message. """ @@ -554,7 +556,7 @@ def test_icmp6_fpa____init____nd_neighbor_solicitation(self) -> None: def test_icmp6_fpa____init____nd_neighbor_solicitation__assert_code__under( self, - ): + ) -> None: """ Test packet constructor for the 'ND Router Solicitation' message. """ @@ -566,7 +568,7 @@ def test_icmp6_fpa____init____nd_neighbor_solicitation__assert_code__under( def test_icmp6_fpa____init____nd_neighbor_solicitation__assert_code__over( self, - ): + ) -> None: """ Test packet constructor for the 'ND Router Solicitation' message. """ @@ -615,7 +617,7 @@ def test_icmp6_fpa____init____nd_neighbor_advertisement(self) -> None: def test_icmp6_fpa____init____nd_neighbor_advertisement__assert_code__under( self, - ): + ) -> None: """ Test packet constructor for the 'ND Router Advertisement' message. """ @@ -627,7 +629,7 @@ def test_icmp6_fpa____init____nd_neighbor_advertisement__assert_code__under( def test_icmp6_fpa____init____nd_neighbor_advertisement__assert_code__over( self, - ): + ) -> None: """ Test packet constructor for the 'ND Router Advertisement' message. """ diff --git a/tests/unit/protocols__icmp6__phtx.py b/tests/unit/protocols__icmp6__phtx.py index e7165fa7..37989a52 100755 --- a/tests/unit/protocols__icmp6__phtx.py +++ b/tests/unit/protocols__icmp6__phtx.py @@ -44,6 +44,7 @@ ICMP6_UNREACHABLE, ICMP6_UNREACHABLE__PORT, ) +from pytcp.subsystems.packet_handler import PacketHandler from tests.unit.mock_network import ( MockNetworkSettings, patch_config, @@ -66,6 +67,8 @@ def setUp(self) -> None: self.mns = MockNetworkSettings() patch_config(self) setup_mock_packet_handler(self) + self.frame_tx: bytearray + self.packet_handler: PacketHandler # Test name format: 'test_name__test_description__optional_condition' diff --git a/tests/unit/protocols__ip4__fpa.py b/tests/unit/protocols__ip4__fpa.py index eafee5f6..ceaaf275 100755 --- a/tests/unit/protocols__ip4__fpa.py +++ b/tests/unit/protocols__ip4__fpa.py @@ -219,7 +219,7 @@ def test_ip4_fpa____init____assert_proto_unknown(self) -> None: carried_packet_mock = StrictMock() carried_packet_mock.ip4_proto = -1 carried_packet_mock.tracker = StrictMock(Tracker) - Ip4Assembler(carried_packet=carried_packet_mock) + Ip4Assembler(carried_packet=carried_packet_mock) # type: ignore[arg-type] def test_ip4_fpa____len__(self) -> None: """ diff --git a/tests/unit/protocols__ip4__phtx.py b/tests/unit/protocols__ip4__phtx.py index fc15f1a5..6c3c9e50 100755 --- a/tests/unit/protocols__ip4__phtx.py +++ b/tests/unit/protocols__ip4__phtx.py @@ -37,6 +37,7 @@ from pytcp.lib.packet_stats import PacketStatsTx from pytcp.lib.tx_status import TxStatus from pytcp.protocols.raw.fpa import RawAssembler +from pytcp.subsystems.packet_handler import PacketHandler from tests.unit.mock_network import ( MockNetworkSettings, patch_config, @@ -59,6 +60,9 @@ def setUp(self) -> None: self.mns = MockNetworkSettings() patch_config(self) setup_mock_packet_handler(self) + self.frame_tx: bytearray + self.frames_tx: list[bytearray] + self.packet_handler: PacketHandler # Test name format: 'test_name__test_description__optional_condition' @@ -95,7 +99,7 @@ def test_ip4_phtx__ip4_to_unicast_address_on_local_network__src_valid( def test_ip4_phtx__ip4_to_unicast_address_on_local_network__src_not_owned_drop( self, - ): + ) -> None: """ Test sending IPv4 packet to unicast address on local network, src not owned. @@ -115,7 +119,7 @@ def test_ip4_phtx__ip4_to_unicast_address_on_local_network__src_not_owned_drop( def test_ip4_phtx__ip4_to_unicast_address_on_local_network__src_multicast_replace( self, - ): + ) -> None: """ Test sending IPv4 packet to unicast address on local network, multicast source, able to replace. @@ -147,7 +151,7 @@ def test_ip4_phtx__ip4_to_unicast_address_on_local_network__src_multicast_replac def test_ip4_phtx__ip4_to_unicast_address_on_local_network__src_multicast_drop( self, - ): + ) -> None: """ Test sending IPv4 packet to unicast address on local network, multicast source, not able to replace. @@ -169,7 +173,7 @@ def test_ip4_phtx__ip4_to_unicast_address_on_local_network__src_multicast_drop( def test_ip4_phtx__ip4_to_unicast_address_on_local_network__src_limited_broadcast_replace( self, - ): + ) -> None: """ Test sending IPv4 packet to unicast address on local network, limited broadcst source, able to replace. @@ -201,7 +205,7 @@ def test_ip4_phtx__ip4_to_unicast_address_on_local_network__src_limited_broadcas def test_ip4_phtx__ip4_to_unicast_address_on_local_network__src_limited_broadcast_drop( self, - ): + ) -> None: """ Test sending IPv4 packet to unicast address on local network, limited broadcast source, not able to replace. @@ -222,7 +226,7 @@ def test_ip4_phtx__ip4_to_unicast_address_on_local_network__src_limited_broadcas def test_ip4_phtx__ip4_to_unicast_address_on_local_network__src_network_broadcast_replace( self, - ): + ) -> None: """ Test sending IPv4 packet to unicast address on local network, network broadcst source, able to replace. @@ -254,7 +258,7 @@ def test_ip4_phtx__ip4_to_unicast_address_on_local_network__src_network_broadcas def test_ip4_phtx__ip4_to_unicast_address_on_local_network__src_unspecified_replace_local( self, - ): + ) -> None: """ Test sending IPv4 packet to unicast address on local network, uspecified source, able to replace. @@ -286,7 +290,7 @@ def test_ip4_phtx__ip4_to_unicast_address_on_local_network__src_unspecified_repl def test_ip4_phtx__ip4_to_unicast_address_on_local_network__src_unspecified_replace_external( self, - ): + ) -> None: """ Test sending IPv4 packet to unicast address on local network, uspecified source, able to replace with ip from subnet with gateway. @@ -318,7 +322,7 @@ def test_ip4_phtx__ip4_to_unicast_address_on_local_network__src_unspecified_repl def test_ip4_phtx__ip4_to_unicast_address_on_local_network__src_unspecified_drop( self, - ): + ) -> None: """ Test sending IPv4 packet to unicast address on local network, uspecified source, not able to replace. diff --git a/tests/unit/protocols__ip6__fpa.py b/tests/unit/protocols__ip6__fpa.py index 63daf6fd..2b7f482a 100755 --- a/tests/unit/protocols__ip6__fpa.py +++ b/tests/unit/protocols__ip6__fpa.py @@ -189,7 +189,7 @@ def test_ip6_fpa____init____assert_next_header_unknown(self) -> None: carried_packet_mock = StrictMock() carried_packet_mock.ip6_next = -1 carried_packet_mock.tracker = StrictMock(Tracker) - Ip6Assembler(carried_packet=carried_packet_mock) + Ip6Assembler(carried_packet=carried_packet_mock) # type: ignore[arg-type] def test_ip6_fpa____len__(self) -> None: """ @@ -276,7 +276,7 @@ def test_ip6_fpa__pshdr_sum(self) -> None: packet = Ip6Assembler( src=Ip6Address("0:1:2:3:4:5:6:7"), dst=Ip6Address("8:9:A:B:C:D:E:F"), - carried_packet=RawAssembler(data="0123456789ABCDEF"), + carried_packet=RawAssembler(data=b"0123456789ABCDEF"), ) self.assertEqual(packet.pshdr_sum, 6755588421714211) diff --git a/tests/unit/protocols__ip6__phtx.py b/tests/unit/protocols__ip6__phtx.py index 181f9bf8..8cd98499 100755 --- a/tests/unit/protocols__ip6__phtx.py +++ b/tests/unit/protocols__ip6__phtx.py @@ -37,6 +37,7 @@ from pytcp.lib.packet_stats import PacketStatsTx from pytcp.lib.tx_status import TxStatus from pytcp.protocols.raw.fpa import RawAssembler +from pytcp.subsystems.packet_handler import PacketHandler from tests.unit.mock_network import ( MockNetworkSettings, patch_config, @@ -59,6 +60,9 @@ def setUp(self) -> None: self.mns = MockNetworkSettings() patch_config(self) setup_mock_packet_handler(self) + self.frame_tx: bytearray + self.frames_tx: list[bytearray] + self.packet_handler: PacketHandler # Test name format: 'test_name__test_description__optional_condition' @@ -95,7 +99,7 @@ def test_ip6_phtx__ip6_to_unicast_address_on_local_network__src_valid( def test_ip6_phtx__ip6_to_unicast_address_on_local_network__src_not_owned_drop( self, - ): + ) -> None: """ Test sending IPv6 packet to unicast address on local network, src not owned. @@ -115,7 +119,7 @@ def test_ip6_phtx__ip6_to_unicast_address_on_local_network__src_not_owned_drop( def test_ip6_phtx__ip6_to_unicast_address_on_local_network__src_multicast_replace( self, - ): + ) -> None: """ Test sending IPv6 packet to unicast address on local network, multicast source, able to replace. @@ -147,7 +151,7 @@ def test_ip6_phtx__ip6_to_unicast_address_on_local_network__src_multicast_replac def test_ip6_phtx__ip6_to_unicast_address_on_local_network__src_multicast_drop( self, - ): + ) -> None: """ Test sending IPv6 packet to unicast address on local network, multicast source, not able to replace. @@ -169,7 +173,7 @@ def test_ip6_phtx__ip6_to_unicast_address_on_local_network__src_multicast_drop( def test_ip6_phtx__ip6_to_unicast_address_on_local_network__src_unspecified_replace_local( self, - ): + ) -> None: """ Test sending IPv6 packet to unicast address on local network, uspecified source, able to replace. @@ -201,7 +205,7 @@ def test_ip6_phtx__ip6_to_unicast_address_on_local_network__src_unspecified_repl def test_ip6_phtx__ip6_to_unicast_address_on_local_network__src_unspecified_replace_external( self, - ): + ) -> None: """ Test sending IPv6 packet to unicast address on local network, uspecified source, able to replace with ip from subnet with gateway. @@ -233,7 +237,7 @@ def test_ip6_phtx__ip6_to_unicast_address_on_local_network__src_unspecified_repl def test_ip6_phtx__ip6_to_unicast_address_on_local_network__src_unspecified_drop( self, - ): + ) -> None: """ Test sending IPv6 packet to unicast address on local network, uspecified source, not able to replace. diff --git a/tests/unit/protocols__tcp__phtx.py b/tests/unit/protocols__tcp__phtx.py index 076d6a71..8c7c8b15 100755 --- a/tests/unit/protocols__tcp__phtx.py +++ b/tests/unit/protocols__tcp__phtx.py @@ -36,6 +36,7 @@ from pytcp.lib.packet_stats import PacketStatsTx from pytcp.lib.tx_status import TxStatus +from pytcp.subsystems.packet_handler import PacketHandler from tests.unit.mock_network import ( MockNetworkSettings, patch_config, @@ -58,6 +59,8 @@ def setUp(self) -> None: self.mns = MockNetworkSettings() patch_config(self) setup_mock_packet_handler(self) + self.frame_tx: bytearray + self.packet_handler: PacketHandler # Test name format: 'test_name__test_description__optional_condition' diff --git a/tests/unit/protocols__udp__phtx.py b/tests/unit/protocols__udp__phtx.py index f6173e58..f634549f 100755 --- a/tests/unit/protocols__udp__phtx.py +++ b/tests/unit/protocols__udp__phtx.py @@ -36,6 +36,7 @@ from pytcp.lib.packet_stats import PacketStatsTx from pytcp.lib.tx_status import TxStatus +from pytcp.subsystems.packet_handler import PacketHandler from tests.unit.mock_network import ( MockNetworkSettings, patch_config, @@ -58,6 +59,8 @@ def setUp(self) -> None: self.mns = MockNetworkSettings() patch_config(self) setup_mock_packet_handler(self) + self.frame_tx: bytearray + self.packet_handler: PacketHandler # Test name format: 'test_name__test_description__optional_condition'