Skip to content

Commit f41ca6f

Browse files
authored
docs(tests): second pass over tests/protocols (#1103) (#1788)
Correct tests/protocols prose that no longer matches the code. Prose only: the AST guard finds all seven files identical. - test_layer_placement_unit: Link sets ten names of its own, not seven, and OSPF loses four of them, `_shipped_proto` included. - test_protocol_code_registration_unit: Engine's registry keyword is `engine=`, renamed from `name=` by #557. - test_http_unit: Command.get's case rule is RFC 959 section 5.3, not 4.1; TCP ports 80 and 8080 bind the version dispatcher, not httpv1.HTTP, so the "straight to this class" claim is dropped. - test_hip_unit: all three two_octet_prefix_list_len call sites take two-octet items, so none is a one-octet contrast. - test_ipv4_unit: the ProtocolBase descendant count is stated as a lower bound, and a test_schema_unit.py line is re-measured. - test_dispatch_reachability_unit: drop the stale count of 38 `__proto__` entries; the registry test pins the number. - test_hip_locator_set_length_unit: rewrap an over-long line. Refs #1103
1 parent e6e7bdf commit f41ca6f

7 files changed

Lines changed: 24 additions & 22 deletions

‎tests/protocols/application/test_http_unit.py‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,10 +1016,8 @@ def test_httpv1_read_raises_protocol_error_for_a_malformed_message(self) -> None
10161016
10171017
Asserted on ``httpv1.HTTP`` directly rather than through the proxy
10181018
because that is the difference between the two candidate fixes: the
1019-
contract now holds for every caller, including
1020-
``Transport._decode_next_layer``, which dispatches TCP ports 80 and 8080
1021-
straight to this class and never passes through ``_guess_version`` at
1022-
all.
1019+
contract now holds for every caller of ``httpv1.HTTP``, not only for
1020+
``_guess_version``'s first arm.
10231021
10241022
``__cause__`` is asserted because the chain is what keeps the underlying
10251023
unpacking error reportable, and what keeps
@@ -1643,8 +1641,8 @@ def test_method_get_is_now_case_sensitive(self) -> None:
16431641
"""``Method.get`` used to test the upper-cased key, so a mixed-case
16441642
method resolved to the same registered member regardless of its own
16451643
casing -- #583, item 1, at the time framed the same way as #582's fix
1646-
in :mod:`pcapkit.const.ftp.command` (`Command.get` stays that way; see
1647-
its own RFC 959 Section 4.1 rationale). GitHub issue #896 retired that
1644+
in :mod:`pcapkit.const.ftp.command` (``Command.get`` stays that way, per
1645+
RFC 959 Section 5.3). GitHub issue #896 retired that
16481646
for ``Method`` specifically: RFC 9110 Section 9.1 makes the HTTP
16491647
method *token* case-sensitive -- "standardized methods are defined in
16501648
all-uppercase US-ASCII letters" by convention, not by requirement --

‎tests/protocols/application/test_layer_placement_unit.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,12 @@ def test_dispatch_keys_did_not_move_with_the_modules(self) -> None:
197197
self.assertIs(getattr(importlib.import_module(entry.module), entry.name), cls)
198198

199199
def test_ospf_leaves_links_registry_behind_and_rarp_keeps_it(self) -> None:
200-
"""``Link`` sets seven names beyond ``ProtocolBase``; OSPF loses three of them.
200+
"""``Link`` sets ten names of its own; OSPF loses four of them.
201201
202-
``__proto__``, ``register`` and ``_read_protos`` are ``Link``'s EtherType
203-
machinery. The loss is inert because a ``-1`` lookup misses in either
202+
``__proto__``, its shipped copy ``_shipped_proto``, ``register`` and
203+
``_read_protos`` are ``Link``'s EtherType machinery, and OSPF takes all
204+
four from ``ProtocolBase`` instead. The first assertion pins seven of the
205+
ten. The loss is inert because a ``-1`` lookup misses in either
204206
registry and falls back to :class:`~pcapkit.protocols.misc.raw.Raw`.
205207
"""
206208
from pcapkit.protocols.application.ospf import OSPF

‎tests/protocols/internet/test_hip_locator_set_length_unit.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@
4646
=================== ============== ====== =========================
4747
4848
Four of the seven were not even multiples of eight. A sweep over n = 1..5 of
49-
plain locators passed by cancellation before the fix and would pass a half-fix too, so it
50-
discriminates nothing; the empty set, the SPI-bearing variant and a mixed set in
51-
both orders are the shapes that do.
49+
plain locators passed by cancellation before the fix and would pass a half-fix
50+
too, so it discriminates nothing; the empty set, the SPI-bearing variant and a
51+
mixed set in both orders are the shapes that do.
5252
5353
The reader consumed the same quantity
5454
-------------------------------------

‎tests/protocols/internet/test_hip_unit.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1999,9 +1999,9 @@ def test_hip_transport_format_list_parameter_parses_the_full_declared_length(sel
19991999
Each ``TF type`` entry is two octets, not one -- :rfc:`7401` Section
20002000
5.2.11 fixes it at "2x number of TF types" and the diagram shows two
20012001
16-bit ``TF type`` fields per 32-bit row, matching
2002-
:class:`HIPTransportModeParameter`'s ``mode`` field rather than the
2003-
one-octet items :func:`two_octet_prefix_list_len`'s other two call
2004-
sites use. So this test's four entries are four *two*-octet values
2002+
:class:`HIPTransportModeParameter`'s ``mode`` field and the items at
2003+
:func:`two_octet_prefix_list_len`'s other two call sites, all three
2004+
two-octet. So this test's four entries are four *two*-octet values
20052005
(``Length = 8``), and with both defects fixed --
20062006
:func:`~pcapkit.protocols.schema.internet.hip.
20072007
transport_format_list_len` returning ``Length`` unchanged, and

‎tests/protocols/internet/test_ipv4_unit.py‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def test_ipv4_make_accepts_a_protocol_instance_as_payload(self) -> None:
222222
# defect. Asserting the negative matters because the branch was not
223223
# uncovered before the fix -- it was covered by the only class in the
224224
# tree that satisfied it, ``DummyProtocol`` in
225-
# tests/protocols/schema/test_schema_unit.py:167, which subclasses
225+
# tests/protocols/schema/test_schema_unit.py:168, which subclasses
226226
# ``Protocol`` and so packed happily while every protocol in the
227227
# library raised. Without this line the same hole could be reopened
228228
# by making a protocol subclass ``Protocol`` rather than by fixing
@@ -311,8 +311,9 @@ def test_schema_pack_packs_a_second_real_protocol_as_payload(self) -> None:
311311
defect of its own. Every one of them hands the payload field a
312312
:class:`~pcapkit.protocols.misc.raw.Raw` or a
313313
:class:`~pcapkit.protocols.misc.null.NoPayload`, because those are what
314-
*parsing* yields, so between them they exercise exactly two of the 43
315-
:class:`~pcapkit.protocols.protocol.ProtocolBase` descendants the widened
314+
*parsing* yields, so between them they exercise exactly two of the more
315+
than forty :class:`~pcapkit.protocols.protocol.ProtocolBase` descendants
316+
the widened
316317
check in :meth:`Schema.pack
317318
<pcapkit.protocols.schema.schema.Schema.pack>` has to accept. That is
318319
enough coverage to be defeated by a fix that is not one: replacing the
@@ -324,7 +325,7 @@ def test_schema_pack_packs_a_second_real_protocol_as_payload(self) -> None:
324325
325326
-- special-casing precisely the classes the tests use -- passes all four
326327
of them, measured, while leaving the general defect in place for the
327-
other 40 protocols. #536's own reviewer found that by falsification, and
328+
other protocols. #536's own reviewer found that by falsification, and
328329
this test is what makes the shortcut fail.
329330
330331
So the payload here is a ``UDP``, and the assertions are chosen to be

‎tests/protocols/test_dispatch_reachability_unit.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
rather than just this one.
1010
1111
:file:`test_dispatch_registry_unit.py` walks the problem from the other end: it
12-
takes each of the 38 ``__proto__`` entries that *exist* and checks the class it
12+
takes each ``__proto__`` entry that *exists* and checks the class it
1313
names can parse a packet. That cannot see a class nobody registered at all,
1414
which is exactly how :class:`~pcapkit.protocols.application.ospf.OSPF` shipped
1515
reachable from no table (fixed in #436). This module walks it from the class

‎tests/protocols/test_protocol_code_registration_unit.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
keyword that registers a subclass into the next-layer dispatch registry (or
77
registries) it names -- e.g. :attr:`Link.__proto__
88
<pcapkit.protocols.link.link.Link.__proto__>`. Registration is opt-in,
9-
exactly like the ``name=``/``protocol=``/``fmt=`` keywords part (a) (#547)
9+
exactly like the ``engine=``/``protocol=``/``fmt=`` keywords part (a) (#547)
1010
gave :class:`~pcapkit.foundation.engines.engine.Engine`,
1111
:class:`~pcapkit.foundation.reassembly.reassembly.Reassembly`,
1212
:class:`~pcapkit.foundation.traceflow.traceflow.TraceFlow` and
13-
:class:`~pcapkit.dumpkit.common.Dumper`: omitting ``code`` leaves the
13+
:class:`~pcapkit.dumpkit.common.Dumper` (#557 renamed ``Engine``'s from
14+
``name=``): omitting ``code`` leaves the
1415
subclass unregistered, which is exactly what every built-in protocol class
1516
does today, since the built-in dispatch tables are populated by literal
1617
assignment in each layer module rather than by ``__init_subclass__``.

0 commit comments

Comments
 (0)