Skip to content

Commit

Permalink
Merging the unit/integration type checking from PyTCP_2_7 (#22)
Browse files Browse the repository at this point in the history
* 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 <ccie18643@gmail.com>
  • Loading branch information
ccie18643 and ccie18643 authored Nov 27, 2022
1 parent 4587605 commit 38a7049
Show file tree
Hide file tree
Showing 18 changed files with 147 additions and 96 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }]
Expand Down
18 changes: 9 additions & 9 deletions tests/integration/packet_flows_rx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand All @@ -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
]
Expand All @@ -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.
"""
Expand All @@ -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.
Expand All @@ -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.
"""
Expand All @@ -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.
"""
Expand All @@ -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.
"""
Expand All @@ -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.
"""
Expand All @@ -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.
Expand Down
78 changes: 46 additions & 32 deletions tests/integration/packet_flows_rx_tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class TestPacketHandlerRxTx(TestCase):
The RX-TX packet flow integration test class.
"""

def setUp(self):
def setUp(self) -> None:
"""
Setup tests.
"""
Expand All @@ -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(
Expand Down Expand Up @@ -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",
Expand All @@ -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
]
Expand All @@ -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.
"""
Expand All @@ -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.
"""
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
"""
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
"""
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
"""
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 38a7049

Please sign in to comment.