Skip to content

Commit 38a7049

Browse files
authored
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 <[email protected]>
1 parent 4587605 commit 38a7049

18 files changed

+147
-96
lines changed

.github/workflows/ci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ jobs:
4141
run: |
4242
mypy -p pytcp
4343
mypy -p examples
44+
mypy -p tests
4445
- name: Test unit
4546
run: testslide tests/unit/*.py
4647
- name: Test integration

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ lint: venv
3737
@echo '<<< MYPY'
3838
@PYTHONPATH=$(ROOT_PATH) ./$(VENV)/bin/mypy -p ${PYTCP_PATH}
3939
@PYTHONPATH=$(ROOT_PATH) ./$(VENV)/bin/mypy -p ${EXAMPLES_PATH}
40+
@PYTHONPATH=$(ROOT_PATH) ./$(VENV)/bin/mypy -p ${TESTS_PATH}
4041

4142
test_unit: venv
4243
@echo '<<< TESTSLIDE UNIT'

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "PyTCP"
7-
version = "2.7.4"
7+
version = "2.7.5"
88
description = "TCP/IP stack written in Python."
99
readme = "README.md"
1010
authors = [{ name = "Sebastian Majewski", email = "[email protected]" }]

tests/integration/packet_flows_rx.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class TestPacketHandlerRx(TestCase):
9090
The RX packet flow integration test class.
9191
"""
9292

93-
def setUp(self):
93+
def setUp(self) -> None:
9494
"""
9595
Set up the test environment.
9696
"""
@@ -102,7 +102,7 @@ def setUp(self):
102102
# Initialize packet handler and manually set all the variables that
103103
# normally would require network connectivity
104104
self.packet_handler = PacketHandler()
105-
self.packet_handler.mac_address = STACK_MAC_ADDRESS
105+
self.packet_handler.mac_unicast = STACK_MAC_ADDRESS
106106
self.packet_handler.mac_multicast = [
107107
STACK_IP6_HOST.address.solicited_node_multicast.multicast_mac
108108
]
@@ -115,7 +115,7 @@ def setUp(self):
115115

116116
self.packet_tx = memoryview(bytearray(2048))
117117

118-
def _patch_config(self):
118+
def _patch_config(self) -> None:
119119
"""
120120
Patch critical config setting for all packet handler modules.
121121
"""
@@ -131,7 +131,7 @@ def _patch_config(self):
131131
# Test name format:
132132
# 'test_name__protocol_tested__test_description__optional_condition'
133133

134-
def test_packet_flow_rx__ether__ether_unknown_dst(self):
134+
def test_packet_flow_rx__ether__ether_unknown_dst(self) -> None:
135135
"""
136136
[Ethernet] Receive Ethernet packet with unknown destination
137137
MAC address, drop.
@@ -153,7 +153,7 @@ def test_packet_flow_rx__ether__ether_unknown_dst(self):
153153
PacketStatsTx(),
154154
)
155155

156-
def test_packet_flow_rx__ether__ether_malformed_header(self):
156+
def test_packet_flow_rx__ether__ether_malformed_header(self) -> None:
157157
"""
158158
[Ethernet] Receive Ethernet packet with malformed header, drop.
159159
"""
@@ -174,7 +174,7 @@ def test_packet_flow_rx__ether__ether_malformed_header(self):
174174
PacketStatsTx(),
175175
)
176176

177-
def test_packet_flow_rx__ip4__ip4_unknown_dst(self):
177+
def test_packet_flow_rx__ip4__ip4_unknown_dst(self) -> None:
178178
"""
179179
[IPv4] Receive IPv4 packet for unknown destination, drop.
180180
"""
@@ -197,7 +197,7 @@ def test_packet_flow_rx__ip4__ip4_unknown_dst(self):
197197
PacketStatsTx(),
198198
)
199199

200-
def test_packet_flow_rx__ip6__ip6_unknown_dst(self):
200+
def test_packet_flow_rx__ip6__ip6_unknown_dst(self) -> None:
201201
"""
202202
[IPv6] Receive IPv6 packet for unknown destination, drop.
203203
"""
@@ -220,7 +220,7 @@ def test_packet_flow_rx__ip6__ip6_unknown_dst(self):
220220
PacketStatsTx(),
221221
)
222222

223-
def test_packet_flow_rx__arp__arp_unknown_tpa(self):
223+
def test_packet_flow_rx__arp__arp_unknown_tpa(self) -> None:
224224
"""
225225
[ARP] Receive ARP Request packet for unknown IPv4 address, drop.
226226
"""
@@ -244,7 +244,7 @@ def test_packet_flow_rx__arp__arp_unknown_tpa(self):
244244
PacketStatsTx(),
245245
)
246246

247-
def test_packet_flow_rx_tx__icmp6_nd__nd_ns__dad(self):
247+
def test_packet_flow_rx_tx__icmp6_nd__nd_ns__dad(self) -> None:
248248
"""
249249
[ICMPv6 ND] Receive ICMPv6 Neighbor Solicitation DAD packet,
250250
respond with Neighbor Advertisement.

tests/integration/packet_flows_rx_tx.py

+46-32
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class TestPacketHandlerRxTx(TestCase):
9595
The RX-TX packet flow integration test class.
9696
"""
9797

98-
def setUp(self):
98+
def setUp(self) -> None:
9999
"""
100100
Setup tests.
101101
"""
@@ -107,7 +107,7 @@ def setUp(self):
107107
# Assembled packet result is usually taken from 'self.packet_tx',
108108
# below list is used only for tx fragmentation test where multiple
109109
# packets are being generated by single packet assembler run.
110-
self.packets_tx = []
110+
self.packets_tx: list[memoryview] = []
111111

112112
self.mock_ArpCache = StrictMock(template=ArpCache)
113113
self.mock_callable(
@@ -139,7 +139,9 @@ def setUp(self):
139139
method="enqueue",
140140
).with_implementation(
141141
lambda _: _.assemble(self.packet_tx)
142-
or self.packets_tx.append(self.packet_tx)
142+
or self.packets_tx.append(
143+
self.packet_tx
144+
) # type: ignore[func-returns-value]
143145
)
144146
self.patch_attribute(
145147
target="pytcp.lib.stack",
@@ -151,7 +153,7 @@ def setUp(self):
151153
# Initialize packet handler and manually set all the variables
152154
# that normally would require network connectivity.
153155
self.packet_handler = PacketHandler()
154-
self.packet_handler.mac_address = STACK_MAC_ADDRESS
156+
self.packet_handler.mac_unicast = STACK_MAC_ADDRESS
155157
self.packet_handler.mac_multicast = [
156158
STACK_IP6_HOST.address.solicited_node_multicast.multicast_mac
157159
]
@@ -164,7 +166,7 @@ def setUp(self):
164166

165167
self.packet_tx = memoryview(bytearray(2048))
166168

167-
def _patch_config(self):
169+
def _patch_config(self) -> None:
168170
"""
169171
Patch critical config setting for all packet handler modules.
170172
"""
@@ -182,7 +184,7 @@ def _patch_config(self):
182184
# Test name format:
183185
# 'test_name__protocol_tested__test_description__optional_condition'
184186

185-
def test_packet_flow_rx_tx__icmp4__ip4_ping(self):
187+
def test_packet_flow_rx_tx__icmp4__ip4_ping(self) -> None:
186188
"""
187189
[ICMPv4] Receive ICMPv4 echo-request packet, respond with echo-reply.
188190
"""
@@ -217,7 +219,7 @@ def test_packet_flow_rx_tx__icmp4__ip4_ping(self):
217219
)
218220
self.assertEqual(self.packet_tx[: len(packet_tx)], packet_tx)
219221

220-
def test_packet_flow_rx_tx__udp__ip4_udp_to_closed_port(self):
222+
def test_packet_flow_rx_tx__udp__ip4_udp_to_closed_port(self) -> None:
221223
"""
222224
[UDP] Receive IPv4/UDP packet for closed port,
223225
respond with ICMPv4 unreachable packet.
@@ -259,7 +261,7 @@ def test_packet_flow_rx_tx__udp__ip4_udp_to_closed_port(self):
259261
)
260262
self.assertEqual(self.packet_tx[: len(packet_tx)], packet_tx)
261263

262-
def test_packet_flow_rx_tx__udp__ip4_udp_echo(self):
264+
def test_packet_flow_rx_tx__udp__ip4_udp_echo(self) -> None:
263265
"""
264266
[UDP] Receive IPv4/UDP packet and echo it back to the sender.
265267
"""
@@ -299,8 +301,8 @@ def test_packet_flow_rx_tx__udp__ip4_udp_echo(self):
299301
self.assertEqual(self.packet_tx[: len(packet_tx)], packet_tx)
300302

301303
def _test_packet_flow_rx_tx__ip4_frag__ip4_udp_echo_rx_frag(
302-
self, order: list(int)
303-
):
304+
self, order: list[int]
305+
) -> None:
304306
"""
305307
[IPv4 frag] Receive fragmented IPv4/UDP packets and echo them
306308
back to the sender in specified order.
@@ -346,7 +348,9 @@ def _test_packet_flow_rx_tx__ip4_frag__ip4_udp_echo_rx_frag(
346348
)
347349
self.assertEqual(self.packet_tx[: len(packet_tx)], packet_tx)
348350

349-
def test_packet_flow_rx_tx__ip4_frag__ip4_udp_echo_rx_frag_01234(self):
351+
def test_packet_flow_rx_tx__ip4_frag__ip4_udp_echo_rx_frag_01234(
352+
self,
353+
) -> None:
350354
"""
351355
[IPv4 frag] Receive fragmented IPv4/UDP packets and echo them
352356
back to the sender.
@@ -355,7 +359,9 @@ def test_packet_flow_rx_tx__ip4_frag__ip4_udp_echo_rx_frag_01234(self):
355359
[0, 1, 2, 3, 4]
356360
)
357361

358-
def test_packet_flow_rx_tx__ip4_frag__ip4_udp_echo_rx_frag_43210(self):
362+
def test_packet_flow_rx_tx__ip4_frag__ip4_udp_echo_rx_frag_43210(
363+
self,
364+
) -> None:
359365
"""
360366
[IPv4 frag] Receive fragmented IPv4/UDP packets and echo them
361367
back to the sender.
@@ -364,7 +370,9 @@ def test_packet_flow_rx_tx__ip4_frag__ip4_udp_echo_rx_frag_43210(self):
364370
[4, 3, 2, 1, 0]
365371
)
366372

367-
def test_packet_flow_rx_tx__ip4_frag__ip4_udp_echo_rx_frag_12043(self):
373+
def test_packet_flow_rx_tx__ip4_frag__ip4_udp_echo_rx_frag_12043(
374+
self,
375+
) -> None:
368376
"""
369377
[IPv4 frag] Receive fragmented IPv4/UDP packets and echo them
370378
back to the sender.
@@ -376,7 +384,7 @@ def test_packet_flow_rx_tx__ip4_frag__ip4_udp_echo_rx_frag_12043(self):
376384

377385
def test_packet_flow_rx_tx__ip4_frag__ip4_udp_echo_rx_frag_1202103341(
378386
self,
379-
):
387+
) -> None:
380388
"""
381389
[IPv4 frag] Receive fragmented IPv4/UDP packets and echo them
382390
back to the sender.
@@ -385,7 +393,7 @@ def test_packet_flow_rx_tx__ip4_frag__ip4_udp_echo_rx_frag_1202103341(
385393
[1, 2, 0, 2, 1, 0, 3, 3, 4, 1]
386394
)
387395

388-
def test_packet_flow_rx_tx__ip4_frag__ip4_udp_echo_tx_frag(self):
396+
def test_packet_flow_rx_tx__ip4_frag__ip4_udp_echo_tx_frag(self) -> None:
389397
"""
390398
[IPv4 frag] Receive IPv4/UDP packet and echo it back to the sender
391399
in fragments.
@@ -432,7 +440,7 @@ def test_packet_flow_rx_tx__ip4_frag__ip4_udp_echo_tx_frag(self):
432440
self.packets_tx[index][: len(frags[index])], frags[index]
433441
)
434442

435-
def test_packet_flow_rx_tx__tcp__ip4_tcp_syn_to_closed_port(self):
443+
def test_packet_flow_rx_tx__tcp__ip4_tcp_syn_to_closed_port(self) -> None:
436444
"""
437445
[TCP] Receive IPv4/TCP SYN packet to closed port, respond with
438446
IPv4/TCP RST/ACK packet.
@@ -476,7 +484,7 @@ def test_packet_flow_rx_tx__tcp__ip4_tcp_syn_to_closed_port(self):
476484
)
477485
self.assertEqual(self.packet_tx[: len(packet_tx)], packet_tx)
478486

479-
def test_packet_flow_rx_tx__icmp6__ip6_ping(self):
487+
def test_packet_flow_rx_tx__icmp6__ip6_ping(self) -> None:
480488
"""
481489
[ICMPv6] Receive ICMPv6 echo-request packet, respond with echo-reply.
482490
"""
@@ -511,7 +519,7 @@ def test_packet_flow_rx_tx__icmp6__ip6_ping(self):
511519
)
512520
self.assertEqual(self.packet_tx[: len(packet_tx)], packet_tx)
513521

514-
def test_packet_flow_rx_tx__udp__ip6_udp_to_closed_port(self):
522+
def test_packet_flow_rx_tx__udp__ip6_udp_to_closed_port(self) -> None:
515523
"""
516524
[UDP] Receive IPv6/UDP packet for closed port, respond with
517525
ICMPv6 unreachable packet.
@@ -553,7 +561,7 @@ def test_packet_flow_rx_tx__udp__ip6_udp_to_closed_port(self):
553561
)
554562
self.assertEqual(self.packet_tx[: len(packet_tx)], packet_tx)
555563

556-
def test_packet_flow_rx_tx__udp__ip6_udp_echo(self):
564+
def test_packet_flow_rx_tx__udp__ip6_udp_echo(self) -> None:
557565
"""
558566
[UDP] Receive IPv4/UDP packet and echo it back to the sender.
559567
"""
@@ -593,8 +601,8 @@ def test_packet_flow_rx_tx__udp__ip6_udp_echo(self):
593601
self.assertEqual(self.packet_tx[: len(packet_tx)], packet_tx)
594602

595603
def _test_packet_flow_rx_tx__ip6_frag__ip6_udp_echo_rx_frag(
596-
self, order: list(int)
597-
):
604+
self, order: list[int]
605+
) -> None:
598606
"""
599607
[IPv6 frag] Receive fragmented IPv6/UDP packets and echo them back
600608
to the sender in specified order.
@@ -642,7 +650,9 @@ def _test_packet_flow_rx_tx__ip6_frag__ip6_udp_echo_rx_frag(
642650
)
643651
self.assertEqual(self.packet_tx[: len(packet_tx)], packet_tx)
644652

645-
def test_packet_flow_rx_tx__ip6_frag__ip6_udp_echo_rx_frag_01234(self):
653+
def test_packet_flow_rx_tx__ip6_frag__ip6_udp_echo_rx_frag_01234(
654+
self,
655+
) -> None:
646656
"""
647657
[IPv6 frag] Receive fragmented IPv6/UDP packets and echo them back
648658
to the sender.
@@ -651,7 +661,9 @@ def test_packet_flow_rx_tx__ip6_frag__ip6_udp_echo_rx_frag_01234(self):
651661
[0, 1, 2, 3, 4]
652662
)
653663

654-
def test_packet_flow_rx_tx__ip6_frag__ip6_udp_echo_rx_frag_43210(self):
664+
def test_packet_flow_rx_tx__ip6_frag__ip6_udp_echo_rx_frag_43210(
665+
self,
666+
) -> None:
655667
"""
656668
[IPv6 frag] Receive fragmented IPv6/UDP packets and echo them back
657669
to the sender.
@@ -660,7 +672,9 @@ def test_packet_flow_rx_tx__ip6_frag__ip6_udp_echo_rx_frag_43210(self):
660672
[4, 3, 2, 1, 0]
661673
)
662674

663-
def test_packet_flow_rx_tx__ip6_frag__ip6_udp_echo_rx_frag_12043(self):
675+
def test_packet_flow_rx_tx__ip6_frag__ip6_udp_echo_rx_frag_12043(
676+
self,
677+
) -> None:
664678
"""
665679
[IPv6 frag] Receive fragmented IPv6/UDP packets and echo them back
666680
to the sender.
@@ -671,7 +685,7 @@ def test_packet_flow_rx_tx__ip6_frag__ip6_udp_echo_rx_frag_12043(self):
671685

672686
def test_packet_flow_rx_tx__ip6_frag__ip6_udp_echo_rx_frag_1202103341(
673687
self,
674-
):
688+
) -> None:
675689
"""
676690
[IPv6 frag] Receive fragmented IPv6/UDP packets and echo them back
677691
to the sender.
@@ -680,7 +694,7 @@ def test_packet_flow_rx_tx__ip6_frag__ip6_udp_echo_rx_frag_1202103341(
680694
[1, 2, 0, 2, 1, 0, 3, 3, 4, 1]
681695
)
682696

683-
def test_packet_flow_rx_tx__ip6_frag__ip6_udp_echo_tx_frag(self):
697+
def test_packet_flow_rx_tx__ip6_frag__ip6_udp_echo_tx_frag(self) -> None:
684698
"""
685699
[IPv6 frag] Receive IPv4/UDP packet and echo it back to the sender
686700
in fragments.
@@ -730,7 +744,7 @@ def test_packet_flow_rx_tx__ip6_frag__ip6_udp_echo_tx_frag(self):
730744
self.packets_tx[index][: len(frags[index])], frags[index]
731745
)
732746

733-
def test_packet_flow_rx_tx__tcp__ip6_tcp_syn_to_closed_port(self):
747+
def test_packet_flow_rx_tx__tcp__ip6_tcp_syn_to_closed_port(self) -> None:
734748
"""
735749
[TCP] Receive IPv6/TCP SYN packet to closed port, respond with
736750
IPv6/TCP RST/ACK packet.
@@ -774,7 +788,7 @@ def test_packet_flow_rx_tx__tcp__ip6_tcp_syn_to_closed_port(self):
774788
)
775789
self.assertEqual(self.packet_tx[: len(packet_tx)], packet_tx)
776790

777-
def test_packet_flow_rx_tx__arp__arp_request(self):
791+
def test_packet_flow_rx_tx__arp__arp_request(self) -> None:
778792
"""
779793
[ARP] Receive ARP Request packet for stack IPv4 address,
780794
respond with ARP Reply.
@@ -814,7 +828,7 @@ def test_packet_flow_rx_tx__arp__arp_request(self):
814828
)
815829
self.assertEqual(self.packet_tx[: len(packet_tx)], packet_tx)
816830

817-
def test_packet_flow_rx_tx__icmp6_nd__nd_ns__unicast_dst(self):
831+
def test_packet_flow_rx_tx__icmp6_nd__nd_ns__unicast_dst(self) -> None:
818832
"""
819833
[ICMPv6 ND] Receive ICMPv6 Neighbor Solicitation packet for stack
820834
IPv6 address, respond with Neighbor Advertisement.
@@ -858,7 +872,7 @@ def test_packet_flow_rx_tx__icmp6_nd__nd_ns__unicast_dst(self):
858872
)
859873
self.assertEqual(self.packet_tx[: len(packet_tx)], packet_tx)
860874

861-
def test_packet_flow_rx_tx__icmp6_nd__nd_ns__no_slla(self):
875+
def test_packet_flow_rx_tx__icmp6_nd__nd_ns__no_slla(self) -> None:
862876
"""
863877
[ICMPv6 ND] Receive ICMPv6 Neighbor Solicitation packet,
864878
respond with Neighbor Advertisement.
@@ -901,7 +915,7 @@ def test_packet_flow_rx_tx__icmp6_nd__nd_ns__no_slla(self):
901915
)
902916
self.assertEqual(self.packet_tx[: len(packet_tx)], packet_tx)
903917

904-
def test_packet_flow_rx_tx__icmp6_nd__nd_ns(self):
918+
def test_packet_flow_rx_tx__icmp6_nd__nd_ns(self) -> None:
905919
"""
906920
[ICMPv6 ND] Receive ICMPv6 Neighbor Solicitation packet,
907921
respond with Neighbor Advertisement.
@@ -943,7 +957,7 @@ def test_packet_flow_rx_tx__icmp6_nd__nd_ns(self):
943957
)
944958
self.assertEqual(self.packet_tx[: len(packet_tx)], packet_tx)
945959

946-
def test_packet_flow_rx_tx__icmp6_nd__nd_ns__dad(self):
960+
def test_packet_flow_rx_tx__icmp6_nd__nd_ns__dad(self) -> None:
947961
"""
948962
[ICMPv6 ND] Receive ICMPv6 Neighbor Solicitation DAD packet,
949963
respond with Neighbor Advertisement

0 commit comments

Comments
 (0)