Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def restore_module_table() -> 'Iterator[None]':
:class:`~typing.Generic` stayed bound after the test that installed it, and
the next test to import :mod:`pcapkit` died on ``TypeError: type
'ProtocolBase' is not subscriptable`` at
``pcapkit/protocols/misc/pcap/frame.py:59`` -- twelve tests in
``pcapkit/protocols/misc/pcap/frame.py:61`` -- twelve tests in
:mod:`tests.project`, and only when the polluting file happened to be
collected first. Three separate files turned out to leak this way, one of
which -- :mod:`tests.cli.test_main` -- did not import :mod:`tests._support`
Expand Down
22 changes: 11 additions & 11 deletions tests/const/test_const_apptype_split_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ def test_a_bare_int_composite_is_refused_as_a_whole(self) -> None:
transport whose bit was set -- the fix for #759, where resolving one by
picking the lowest set bit (``tcp``, iterating **LSB-first**) dispatched
every composite containing it into the TCP registry whatever else it
named. The owner's ruling on this PR (#836) retires that decoding
named. The owner's ruling on #836 retires that decoding
instead of refining it: with ``TransportProtocol`` no longer a flag,
``|``-joined values are no longer parsed and accepted, and the value is
treated as a whole rather than split. A bare-int composite is therefore
Expand Down Expand Up @@ -1440,20 +1440,20 @@ def test_transport_protocol_dropped_its_flag_base(self) -> None:
self.assertEqual(len(TransportProtocol.__members__), 5)

def test_get_refuses_an_unrecognised_name_rather_than_minting_it(self) -> None:
"""Maintainer ruling on this PR (#836), the ``TransportProtocol.get`` inline comment.
"""Maintainer ruling on #836, the ``TransportProtocol.get`` inline comment.

``TransportProtocol.get`` used to mint a brand-new member for any
name it did not recognise. This PR's own prior revision minted at
name it did not recognise. #836's own prior revision minted at
``max_val + 1`` -- right after ``dccp``'s 8, so ``.get('bogus')``
minted 9 -- rather than stock ``ad4805f5f``'s ``max_val * 2``
doubling, which mints 16 for that same call; the difference between
the two schemes is explained below. The maintainer's ruling, given in
an inline review comment on this PR, refuses minting outright either
an inline review comment on #836, refuses minting outright either
way: ``TransportProtocol`` is not to be extended at all. There is no
bound left to walk and nothing left to mint, so the refusal is the one
plain :class:`ValueError` every unrecognised name gets, whether or not
it happens to spell a composite like ``'tcp|udp'``. A later round of
this PR briefly gave the composite case its own, more specific message;
#836 briefly gave the composite case its own, more specific message;
the owner's ruling retired that split too -- with ``TransportProtocol``
no longer a flag, ``|``-joined values are no longer parsed and
accepted, and the value is treated as a whole rather than split -- so
Expand All @@ -1476,9 +1476,9 @@ def test_get_refuses_an_unrecognised_name_rather_than_minting_it(self) -> None:
:meth:`AppType._dispatch` nothing minted to mis-decode in the first
place.

Regression check: this fails against this PR's own prior head,
Regression check: this fails against #836's own prior head,
``3567359e2``, which still mints ``9`` and returns it rather than
raising -- see the session report for the quoted failure.
raising.
"""
from pcapkit.utilities.exceptions import ProtocolError

Expand Down Expand Up @@ -1521,12 +1521,12 @@ def test_get_refuses_a_composite_spelled_string(self) -> None:
``test_a_bare_int_composite_is_refused_as_a_whole``).
:func:`~pcapkit.foundation.registry.protocols.register_apptype` refuses
the identical string the same generic way it refuses any other
unrecognised one, and the owner's ruling on this PR -- with
unrecognised one, and the owner's ruling on #836 -- with
``TransportProtocol`` no longer a flag, ``|``-joined values are no
longer parsed and accepted, and the value is treated as a whole rather
than split -- settles :meth:`TransportProtocol.get` onto that same
answer: ``'|'`` is not special, it is simply not the name of a declared
member. A review round of this PR briefly carved the composite case out
member. A review round of #836 briefly carved the composite case out
with its own diagnostic message; the owner's ruling retired that too.
"""
from pcapkit.const.reg.apptype import TransportProtocol
Expand All @@ -1546,8 +1546,8 @@ def test_a_bare_int_with_a_stray_bit_names_no_registry_either(self) -> None:
``17`` is ``1 | 16`` -- ``tcp`` plus a bit no registry declares -- so
it never named a clean composite of real transports the way ``3``
(``tcp | udp``) once did either, back when ``_dispatch`` still
decoded a bare int's bits at all. The owner's ruling on this PR
(#836) retired that decoding entirely (see
decoded a bare int's bits at all. The owner's ruling on #836
retired that decoding entirely (see
``test_a_bare_int_composite_is_refused_as_a_whole``), so ``17`` and
``3`` are no longer two different cases -- both are simply an
``int`` that names no registry, and both get the identical plain
Expand Down
20 changes: 11 additions & 9 deletions tests/const/test_const_enum_builtin_parity.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@
templates under :mod:`pcapkit.vendor` rather than hand-written -- the tree is
generated, so a fix that is not in the template is reverted by the next crawl.

The one deliberate divergence from the built-in is preserved and pinned here:
the *mutable* registries look a value up, miss, and then **register** it with
:func:`~aenum.extend_enum` instead of raising. That is the exception the owner
named, and :class:`ConstEnumRegisterFallbackTests` exists so a future guard
cannot quietly turn a registration into a rejection -- the failure mode GitHub
issues #584 and #623 are both about.
The one divergence from the built-in the owner named was the *mutable*
registries': look a value up, miss, and then **register** it with
:func:`~aenum.extend_enum` instead of raising. GitHub issues #775 and #860
retired it, so a miss resolves to an equal, unregistered member instead, and
only :class:`~pcapkit.const.mh.cga_type.CGAType` still extends on a miss.
:class:`ConstEnumRegisterFallbackTests` pins that, and that no guard turns the
lookup into an outright crash -- the failure mode GitHub issues #584 and #623
are both about.

The guard for the three flag registries delegates in-range composites to
``super()._missing_`` rather than resolving them itself, because GitHub issue
Expand Down Expand Up @@ -854,7 +856,7 @@ def test_transport_protocol_can_no_longer_be_extended_at_runtime(self) -> None:
for why composing stopped mattering -- but left the doubling itself
alone: stock ``ad4805f5f`` still mints at ``max_val * 2``, so
``.get('quic')`` there returns ``16``, right after ``dccp``'s ``8``.
This PR's own intermediate revision, not #808, is what switched an
#836's own intermediate revision, not #808, is what switched an
unrecognised name to ``max_val + 1`` instead, minting ``9``. The
review ruling on PR #836 removes the registration from
``TransportProtocol.get`` entirely, regardless of which scheme numbered
Expand All @@ -868,9 +870,9 @@ def test_transport_protocol_can_no_longer_be_extended_at_runtime(self) -> None:
module's ruling changing which registries are mutable, not a
regression the sweep above would otherwise have to catch.

Regression check: this fails against this PR's own prior head,
Regression check: this fails against #836's own prior head,
``3567359e2``, which still registers ``'quic'`` at value 9 rather
than raising -- see the session report for the quoted failure.
than raising.
"""
from pcapkit.const.reg.apptype import TransportProtocol

Expand Down
16 changes: 8 additions & 8 deletions tests/const/test_const_enum_no_mint.py
Original file line number Diff line number Diff line change
Expand Up @@ -1785,7 +1785,7 @@ def test_optiontype_members_ns_is_not_corrupted(self) -> None:

def test_optiontype_get_int_path_no_longer_mints(self) -> None:
""":meth:`OptionType.get` used to mint directly on a miss (bypassing
``_missing_`` entirely) -- a second, independent mint site this PR's
``_missing_`` entirely) -- a second, independent mint site #869's
first pass left alone. Round 2 review measured it live on the
wire-facing path (:meth:`pcapkit.protocols.misc.pcapng.PCAPNG.
_make_pcapng_options` calls ``get()`` with raw option-code bytes),
Expand Down Expand Up @@ -1980,7 +1980,7 @@ def test_command_missing_no_longer_mints(self) -> None:
measured regression risk: swapping the value for the canonicalised
name (as an earlier revision of this conversion did) would make
``Command('xyzw') == 'xyzw'`` false, which never held on ``main``
and would have been this PR's one real behaviour break."""
and would have been #869's one real behaviour break."""
from pcapkit.const.ftp.command import Command, CommandType, ConformanceRequirement

before = len(Command.__members__)
Expand Down Expand Up @@ -2347,13 +2347,13 @@ class AppTypeUnmintConvertedTests(unittest.TestCase):
genuine IANA-registered name or a manufactured placeholder, because
only ``register()`` may create a new entry and ``get()`` never has
enough information to build one itself. A lookup resolving
``TCP(6010)`` after this PR therefore returns an *unregistered* ``x11``
``TCP(6010)`` therefore returns an *unregistered* ``x11``
member -- correct as a service name, but absent from
``__members__``/``_value2member_map_`` until someone calls
``TCP.register(6010, 'x11')`` explicitly.

Unlike every bespoke class #860 step 2's PR 1 converted,
:meth:`AppType.get` already existed before this PR and does genuine
:meth:`AppType.get` already existed before #874 and does genuine
transport-protocol dispatch through :meth:`~AppType._dispatch` -- so,
unlike :class:`~pcapkit.const.http.status_code.StatusCode`/
:class:`~pcapkit.const.ftp.return_code.ReturnCode`, it keeps its own
Expand All @@ -2367,7 +2367,7 @@ class AppTypeUnmintConvertedTests(unittest.TestCase):
:meth:`__repr__`/:meth:`__str__`/:meth:`__int__`/the comparison
operators/:attr:`~AppType.aliases` to run on the result without raising.

:meth:`AppType.register` is new on this PR. ``AppType`` already had a
:meth:`AppType.register` arrived with #874. ``AppType`` already had a
working ``get``/``get_all``/``register_alias`` of its own, but never a
working ``register`` -- and the base's generic one (which calls
``cls.__new__(cls, value)`` with only ``value``) would have built a
Expand All @@ -2388,7 +2388,7 @@ def test_apptype_family_carries_the_registry_protocol(self) -> None:
"""#842's ruling is that ``get``/``get_all``/``register``/
``register_alias`` exist on every registry -- #860 step 2 PR 2 is
what actually delivers that for this family, including ``register``,
which none of the five had a working version of before this PR."""
which none of the five had a working version of before #874."""
from pcapkit.const.reg.apptype.apptype import AppType
from pcapkit.const.reg.apptype.dccp import DCCP
from pcapkit.const.reg.apptype.sctp import SCTP
Expand Down Expand Up @@ -2503,7 +2503,7 @@ def test_get_second_mint_site_no_longer_mints(self) -> None:
self.assertFalse(TCP.__registry__.getlist(54321))

def test_missing_direct_call_still_raises_for_the_same_port(self) -> None:
"""The asymmetry this PR leaves in place, deliberately: a direct
"""The asymmetry #874 leaves in place, deliberately: a direct
``TCP(54321)`` has no ``get()`` around it to catch ``_missing_``'s
:obj:`None` answer and build an ``'unknown'`` member from it, so it
still raises exactly as it did on ``main`` -- only :meth:`AppType.
Expand Down Expand Up @@ -2649,7 +2649,7 @@ def test_values_are_sequential_from_zero(self) -> None:
self.assertEqual(int(TransportProtocol.dccp), 4)

def test_still_not_a_registry(self) -> None:
"""Unaffected by this PR: ``TransportProtocol`` never minted through
"""Unaffected by #874: ``TransportProtocol`` never minted through
:meth:`~pcapkit.corekit.enum.EnumRegistry._unregistered_member`, and
does not mix in :class:`~pcapkit.corekit.enum.EnumRegistry` now
either -- only ``AppType`` and its four transport subclasses do."""
Expand Down
2 changes: 1 addition & 1 deletion tests/const/test_const_ipv6_extension_header_925_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_extension_header_now_has_exactly_eleven_members(self) -> None:
self.assertNotIn('BIT_EMU', names)

def test_bit_emu_value_no_longer_resolves(self) -> None:
# The exact call pcapkit/protocols/internet/ipv6.py:378 makes at the
# The exact call IPv6._decode_next_layer makes at the
# top of its extension-header walk loop. With BIT_EMU gone and no
# _missing_ defined on this generated file (neither EnumLookup nor
# EnumRegistry in pcapkit.corekit.enum defines one either), 147 now
Expand Down
4 changes: 2 additions & 2 deletions tests/const/test_const_linktype_209_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
#: ``html5lib`` is the one that is actually missing on ``test``: ``requests`` and
#: ``bs4`` have shipped in the ``test`` extra since #507, but only
#: ``beautifulsoup4[html5lib]`` -- the ``vendor`` and ``all`` extras -- provides a
#: parser (``pyproject.toml:203``, and the note at ``:256-263`` saying so
#: parser (``pyproject.toml:234``, and the note at ``:313-320`` saying so
#: deliberately).
VENDOR_DEPS = ('requests', 'bs4', 'html5lib')

Expand Down Expand Up @@ -511,7 +511,7 @@ def test_malformed_en_dash_range_still_raises_loudly(self) -> None:
temp.split('–'))``, which hits the identical unpack error a few
lines later and still raises, uncaught, out of :meth:`process`.
That statement predates #852 entirely, so this assertion passes
identically on ``main``, on this PR's first commit (before
identically on ``main``, on #854's first commit (before
``_expand`` existed), and here: nothing about the pre-scan is what
is being pinned.
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/const/test_const_str_payload_870_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
own wire string now succeeds where it used to fail silently (no exception --
just an unexpected :data:`False`). Nothing under :mod:`pcapkit.protocols`
compared a member this way before the fix (the one caller,
:meth:`pcapkit.protocols.application.httpv1.HTTP.read_http_header`, only ever
:meth:`pcapkit.protocols.application.httpv1.HTTP._read_http_header`, only ever
reads ``.value`` indirectly through :meth:`~pcapkit.const.http.method.Method.
get`, never ``str()`` or ``==`` against the member itself), so the change is
observable only to external callers and to this module's own dunders
Expand Down
16 changes: 8 additions & 8 deletions tests/corekit/test_fields_copy_dispatch_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def assertCallReachesCopyDunderOnly(self, field: 'FieldBase[Any]') -> None:
self.assertIsInstance(new_field, type(field))

def test_field_base_call_field_py_294(self) -> None:
""":meth:`FieldBase.__call__` (``field.py:294``), reached via :class:`NoValueField`.
""":meth:`FieldBase.__call__` (``field.py:281``), reached via :class:`NoValueField`.

:class:`~pcapkit.corekit.fields.misc.NoValueField` is the one concrete
class in this package that never overrides ``__call__``, so it is the
Expand All @@ -98,41 +98,41 @@ class in this package that never overrides ``__call__``, so it is the
self.assertCallReachesCopyDunderOnly(NoValueField())

def test_field_call_field_py_579(self) -> None:
""":meth:`Field.__call__` (``field.py:579``)."""
""":meth:`Field.__call__` (``field.py:581``)."""
from pcapkit.corekit.fields.field import Field

self.assertCallReachesCopyDunderOnly(Field(length=4))

def test_list_field_call_collections_py_84(self) -> None:
""":meth:`ListField.__call__` (``collections.py:84``)."""
""":meth:`ListField.__call__` (``collections.py:124``)."""
from pcapkit.corekit.fields.collections import ListField

self.assertCallReachesCopyDunderOnly(ListField(length=4))

def test_conditional_field_call_misc_py_148(self) -> None:
""":meth:`ConditionalField.__call__` (``misc.py:148``)."""
""":meth:`ConditionalField.__call__` (``misc.py:150``)."""
from pcapkit.corekit.fields.field import Field
from pcapkit.corekit.fields.misc import ConditionalField

field = ConditionalField(field=Field(length=1), condition=lambda packet: True)
self.assertCallReachesCopyDunderOnly(field)

def test_payload_field_call_misc_py_299(self) -> None:
""":meth:`PayloadField.__call__` (``misc.py:299``)."""
""":meth:`PayloadField.__call__` (``misc.py:351``)."""
from pcapkit.corekit.fields.misc import PayloadField

self.assertCallReachesCopyDunderOnly(PayloadField(length=4))

def test_switch_field_call_misc_py_427(self) -> None:
""":meth:`SwitchField.__call__` (``misc.py:427``)."""
""":meth:`SwitchField.__call__` (``misc.py:479``)."""
from pcapkit.corekit.fields.field import Field
from pcapkit.corekit.fields.misc import SwitchField

field = SwitchField(selector=lambda packet: Field(length=1))
self.assertCallReachesCopyDunderOnly(field)

def test_schema_field_call_misc_py_650(self) -> None:
""":meth:`SchemaField.__call__` (``misc.py:650``)."""
""":meth:`SchemaField.__call__` (``misc.py:694``)."""
from pcapkit.corekit.fields.misc import SchemaField
from pcapkit.corekit.fields.numbers import UInt8Field
from pcapkit.protocols.schema.schema import Schema, schema_final
Expand All @@ -144,7 +144,7 @@ class OneField(Schema):
self.assertCallReachesCopyDunderOnly(SchemaField(schema=OneField))

def test_forward_match_field_call_misc_py_782(self) -> None:
""":meth:`ForwardMatchField.__call__` (``misc.py:782``)."""
""":meth:`ForwardMatchField.__call__` (``misc.py:849``)."""
from pcapkit.corekit.fields.field import Field
from pcapkit.corekit.fields.misc import ForwardMatchField

Expand Down
2 changes: 1 addition & 1 deletion tests/corekit/test_fields_misc_packet_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def test_nested_schema_reads_enclosing_field_by_name_and_does_not_leak_writes(se
def test_pcapng_byteorder_consumer_still_works_with_both_shapes(self) -> None:
"""The one existing, hand-rolled ``__packet__`` fallback is unaffected.

``packet_byteorder`` (``pcapkit/corekit/fields/byteorder.py:29``)
``packet_byteorder`` (``pcapkit/corekit/fields/byteorder.py:28``)
is called both with a plain dict built by hand -- as several tests and
:func:`~pcapkit.foundation.engines.pcapng` construct -- and with what
``SchemaField`` now actually builds. Both must keep working, and
Expand Down
4 changes: 2 additions & 2 deletions tests/corekit/test_fields_numbers_port_option_no_mint_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

return self._namespace.get(value, proto=...)

which mints a fresh member -- via :func:`aenum.extend_enum` -- for any value
which minted a fresh member -- via :func:`aenum.extend_enum` -- for any value
neither an existing row nor one of the registry's own documented spans
accounts for. On ``examples/captures/http.pcap`` that is 111 calls, all from
ephemeral TCP ports with no IANA assignment, and measured at 13-17% of
extraction self time.

Every one of those four subclasses now falls through to
Each of them now falls through to
:meth:`EnumField._unregistered_member <pcapkit.corekit.fields.numbers.EnumField._unregistered_member>`
instead of minting: an actual instance of the registry the field names --
``isinstance`` holds, and it renders and dispatches exactly like a declared
Expand Down
Loading
Loading