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
14 changes: 7 additions & 7 deletions tests/const/test_const_apptype_split_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,11 @@ class is created -- see
the sweep over every member that pins this for each of them, aliased or
not, and
``test_the_new_dunders_are_byte_identical_to_the_percent_form`` for the
sample #1062 formats against the pre-#798 form.
sample #1062 formats against the ``%``-formatted form.
"""
from pcapkit.const.reg.apptype import TCP

# No aliases: byte-identical to the pre-#807 form.
# No aliases: no suffix at all.
self.assertEqual(repr(TCP.finger), '<TCP.finger: 79 [tcp]>')
self.assertEqual(str(TCP.finger), 'finger [79 - tcp]')

Expand Down Expand Up @@ -335,7 +335,7 @@ def test_register_alias_is_scoped_to_one_per_transport_registry(self) -> None:
self.assertEqual(SCTP.get(80).aliases, ())

def test_register_alias_is_reachable_by_its_sanitised_identifier(self) -> None:
"""The finding this issue's second round fixed, pinned directly.
"""An alias is reachable by subscription on its sanitised name.

An alias whose own name does not resolve through subscription is not
much of an alias -- ``TCP['http-alt-test']`` is a ``KeyError`` because
Expand Down Expand Up @@ -385,9 +385,9 @@ def test_register_alias_refuses_an_unsanitisable_name(self) -> None:
"""A name with nothing left after sanitising, or a Python cannot start with.

Refused explicitly rather than falling back to a synthetic identifier
such as the port-and-counter scheme this method used before this
round -- a fallback here would just recreate the original defect of
an alias unreachable by anything resembling its own name.
such as a port-and-counter scheme -- a fallback here would just
recreate the defect of an alias unreachable by anything resembling its
own name.
"""
from pcapkit.const.reg.apptype import TCP

Expand Down Expand Up @@ -525,7 +525,7 @@ def test_a_port_lookup_on_the_base_dispatches_by_transport(self) -> None:
AppType.get(80)

def test_a_service_name_is_not_a_port_lookup(self) -> None:
"""GitHub issue #734's junk-minting path is gone rather than fixed.
"""A service name is refused rather than resolved (GitHub issue #734).

The string branch #734 reported tested ``key in __members_proto__``, which is keyed
by transport protocol, so a name never matched and
Expand Down
57 changes: 24 additions & 33 deletions tests/const/test_const_enum_builtin_parity.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@
}

#: The pair GitHub issue #804 finished, as ``(vendor module, class name, const
#: module)``. Their templates are the two of :data:`BESPOKE_TEMPLATES`' four
#: that #798 left on ``%``-formatted ``__repr__`` methods.
#: module)``. Their templates are those of :data:`BESPOKE_TEMPLATES` that #798
#: left on ``%``-formatted ``__repr__`` methods.
ISSUE_804_PAIR = (
('pcapkit.vendor.ftp.command', 'Command', 'pcapkit.const.ftp.command'),
('pcapkit.vendor.http.method', 'Method', 'pcapkit.const.http.method'),
Expand All @@ -153,9 +153,8 @@
#: ``pcapkit.const.http.{error_code,frame,setting}``, whose ``%`` lives in
#: their ``_missing_`` guard (inherited from the *shared*
#: :mod:`pcapkit.vendor.default` template) and which the issue's own last
#: comment split back out, plus ``pcapkit.const.reg.apptype.apptype`` (already
#: an f-string since #792, and off the table anyway while PR #815
#: owns that tree). What is left with an actual ``%``-formatted ``__repr__``
#: comment split back out, plus ``pcapkit.const.reg.apptype.apptype`` (an
#: f-string, #792). What is left with an actual ``%``-formatted ``__repr__``
#: is exactly these three -- each its own bespoke vendor template, like
#: :data:`ISSUE_804_PAIR`'s pair, so each gets a const half and a vendor half.
ISSUE_818_TRIPLE = (
Expand Down Expand Up @@ -365,30 +364,23 @@ def test_the_sweep_size_is_pinned(self) -> None:
if issubclass(obj, int) and not issubclass(obj, aenum.Flag)]

# The decomposition is asserted, not just the total, so this sweep stays
# in step with the three narrower ones it overlaps: 112 non-flag IntEnum
# and 6 IntFlag in tests.const.test_const_enum_lookup, and 118 -- their
# sum, unchanged -- in tests.const.test_const_enum_get. GitHub issue #808
# moved ``TransportProtocol`` from the flag count to the int count by
# dropping its ``IntFlag`` base, one for one, so the sum each of those
# counts on stays the same even though the two addends moved.
# in step with the three narrower ones it overlaps: the non-flag IntEnum
# and the IntFlag sweeps of tests.const.test_const_enum_lookup, and their
# sum in tests.const.test_const_enum_get. ``TransportProtocol`` has no
# ``IntFlag`` base (GitHub issue #808), so it is in the int count.
#
# Five of the ten string registries are the application layer one, which
# GitHub issue #732 split into a package: the memberless
# pcapkit.const.reg.apptype.apptype.AppType base plus one registry per
# transport protocol. It is discovered exactly like a member-bearing
# The application layer registry, which GitHub issue #732 split into a
# package -- the memberless pcapkit.const.reg.apptype.apptype.AppType base
# plus one registry per transport protocol -- accounts for several of the
# string registries. It is discovered exactly like a member-bearing
# registry, since this sweep is structural and never looks at members.
# The tenth is GitHub issue #886's
# pcapkit.const.pcapng.tls_key_label.TLSKeyLabel, moved here from a
# hand-written class under pcapkit.protocols.misc.pcapng -- it defines
# no ``_missing_`` of its own, so it is not among the three ``value.
# upper()`` outliers #647 fixed above, and it never reached
# Another is GitHub issue #886's
# pcapkit.const.pcapng.tls_key_label.TLSKeyLabel -- it defines no
# ``_missing_`` of its own, so it is not among the ``value.upper()``
# outliers #647 fixed above, and it is outside
# tests.const.test_const_enum_get's narrower (IntEnum, IntFlag)-only
# sweep, so that module's own pinned count does not move.
# 112 became 114 with GitHub issue #880's ngap.ProcedureCode and
# ngap.ProtocolIE, moved onto EnumRegistry from hand-rolled IntEnum
# classes in pcapkit.protocols.application.ngap -- two more IntEnum
# registries, two more modules, no change to the flag or str counts --
# and the sum in tests.const.test_const_enum_get became 120 with them.
# sweep. The int count includes GitHub issue #880's ngap.ProcedureCode
# and ngap.ProtocolIE, which are on EnumRegistry.
self.assertEqual(len(ints), 114)
self.assertEqual(len(flags), 6)
self.assertEqual(len(strs), 10)
Expand Down Expand Up @@ -897,9 +889,9 @@ class ConstEnumGuardTemplateTests(unittest.TestCase):

:mod:`pcapkit.const` is generated from :mod:`pcapkit.vendor`, so the
committed tree passing the tests above is not evidence that the templates
agree with it -- the next crawl would simply revert them. The four templates
agree with it -- the next crawl would simply revert them. The templates
below each carry their own copy of the guard rather than inheriting the one
in :mod:`pcapkit.vendor.default`, which is why all four are checked --
in :mod:`pcapkit.vendor.default`, which is why each is checked --
each against its own guard text in :data:`BESPOKE_TEMPLATES`, none of
which uses ``%`` formatting (GitHub issues #792 and #798).
"""
Expand Down Expand Up @@ -945,7 +937,7 @@ def test_no_bespoke_const_module_still_uses_percent_formatting_for_its_guard(sel
def test_the_disable_drops_only_where_nothing_else_needs_percent_formatting(self) -> None:
"""GitHub issue #798's third part, finished by #804: the disable is earned.

All four bespoke const modules carry no ``%``-formatted code, so none
No bespoke const module carries ``%``-formatted code, so none
carries a module-level ``consider-using-f-string`` disable.
``pcapkit.const.tcp.flags`` and ``pcapkit.const.reg.apptype.apptype``
are covered by PR #803, which converted their guards -- and, for the
Expand Down Expand Up @@ -1202,12 +1194,11 @@ def test_the_tcp_flags_template_renders_the_committed_module(self) -> None:

NOTE: the class statement names ``EnumRegistry`` and the first method
after the enumeration block is a ``classmethod``, because ``tcp/flags``
is on :class:`~pcapkit.corekit.enum.EnumRegistry` alongside the four
``mh/*_flag`` templates (GitHub issue #775's tier 2 found its own
exclusion rationale did not hold -- see
is on :class:`~pcapkit.corekit.enum.EnumRegistry` alongside the
``mh/*_flag`` templates (GitHub issue #775's tier 2 -- see
``tests.const.test_const_registry_protocol``). No generated
``@staticmethod get`` closes the block, leaving ``_missing_`` next, the
same shape ``test_const_enum_lookup.py`` expects for those four.
same shape ``test_const_enum_lookup.py`` expects for those templates.
"""
import pathlib

Expand Down
52 changes: 24 additions & 28 deletions tests/const/test_const_enum_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,23 @@
fail this suite rather than silently reintroducing GitHub issue #492.

That sweep deliberately skips :class:`~aenum.IntFlag`, on the grounds that it is
"a different value-lookup contract" -- which is exactly why it did not catch
"a different value-lookup contract" -- which is exactly why it cannot catch
GitHub issue #623, a third lookup defect of the same family living in the class
of enum it excluded. The four Mobility Header flag enumerations overrode
``_missing_`` with a body ending in ``return cls(value)``, the same constructor
that had just failed to find the value, so every in-range value that is not
already a member re-entered ``_missing_`` unbounded and raised
of enum it excludes. It guards against the Mobility Header flag enumerations
overriding ``_missing_`` with a body ending in ``return cls(value)``, the same
constructor that has just failed to find the value, under which every in-range
value that is not already a member re-enters ``_missing_`` unbounded and raises
:exc:`RecursionError`. Because their members are single bits, the reachable hole
was ``0`` -- no flags set -- and every composite of two defined bits. Overriding
``_missing_`` at all is what caused it: the override shadowed the ``aenum``
:class:`~aenum.Flag` machinery that resolves precisely those values, which is why
:class:`~pcapkit.const.tcp.flags.Flags`, which at the time defined no
``_missing_``, never had the defect -- and, as GitHub issue #647 then found, had
no range guard either, so it resolved *any* integer and ``Flags(-1)`` read back
as every TCP header flag set at once. It carries the same guard ending in
``return super()._missing_(value)``, which is what keeps issue #623 fixed while
issue #647 is too; :mod:`tests.const.test_const_enum_builtin_parity` is where
that lands. :class:`~pcapkit.const.mh.binding_ack_flag.BindingACKFlag` and its
three siblings end in that same tail, the one
is ``0`` -- no flags set -- and every composite of two defined bits. Such an
override shadows the ``aenum`` :class:`~aenum.Flag` machinery that resolves
precisely those values. Defining no ``_missing_`` at all avoids that, but -- as
GitHub issue #647 finds for :class:`~pcapkit.const.tcp.flags.Flags` -- leaves no
range guard either, so *any* integer resolves and ``Flags(-1)`` reads back as
every TCP header flag set at once. ``Flags`` carries the same guard ending in
``return super()._missing_(value)``, which keeps both issues fixed;
:mod:`tests.const.test_const_enum_builtin_parity` is where that lands.
:class:`~pcapkit.const.mh.binding_ack_flag.BindingACKFlag` and its siblings end
in that same tail, the one
:mod:`pcapkit.vendor.default` emits for every other generated enumeration. So
this module carries a companion sweep over the :class:`~aenum.IntFlag` classes,
covering the contract the :class:`~aenum.IntEnum` sweep declines to.
Expand Down Expand Up @@ -196,12 +195,10 @@ def test_every_registry_enum_was_discovered(self) -> None:
# Pins the size of the sweep itself: if this drifts, a const enum was
# added, removed, or renamed, and EXPECTED_TO_REJECT_ZERO (and the
# analysis in GitHub issue #492) needs a fresh look rather than a
# silent pass. 112 rather than 111 since GitHub issue #808: dropping
# ``TransportProtocol``'s ``IntFlag`` base moved it from
# ``_iter_const_int_flags`` into this sweep. 114 rather than 112 since
# GitHub issue #880's ngap.ProcedureCode and ngap.ProtocolIE joined
# this sweep, moved onto EnumRegistry from hand-rolled IntEnum classes
# in pcapkit.protocols.application.ngap.
# silent pass. ``TransportProtocol`` has no ``IntFlag`` base (GitHub
# issue #808), so it is in this sweep rather than
# ``_iter_const_int_flags``'s, and so are GitHub issue #880's
# ngap.ProcedureCode and ngap.ProtocolIE, which are on EnumRegistry.
names = {f'{obj.__module__}.{obj.__qualname__}' for obj in self.enums}
self.assertEqual(len(self.enums), 114)
self.assertTrue(EXPECTED_TO_REJECT_ZERO.issubset(names),
Expand Down Expand Up @@ -245,9 +242,9 @@ class ConstMissingClassmethodTests(unittest.TestCase):
aenum invokes lookup failures as ``cls._missing_(value)``. Without
``@classmethod``, the sole positional argument binds to ``cls`` and
``value`` goes unfilled, so *every* call raises :class:`TypeError` instead
of running the intended fallback body -- see GitHub issue #492 (LOW
severity there because, at the time, nothing reachable at runtime ever
triggered the broken path).
of running the intended fallback body -- see GitHub issue #492, which
rates it LOW severity because nothing reachable at runtime triggers the
broken path.

"""

Expand Down Expand Up @@ -314,9 +311,8 @@ def setUpClass(cls) -> None:
def test_the_sweep_size_is_pinned(self) -> None:
"""A flag enum added or removed needs a fresh look, not a silent pass.

6 rather than 7 since GitHub issue #808: dropping
``TransportProtocol``'s ``IntFlag`` base moved it out of this sweep and
into ``_iter_const_int_enums`` instead.
``TransportProtocol`` has no ``IntFlag`` base (GitHub issue #808), so
it is in ``_iter_const_int_enums``'s sweep rather than this one.
"""
names = {f'{obj.__module__}.{obj.__qualname__}' for obj in self.flags}
self.assertEqual(len(self.flags), 6)
Expand Down
Loading
Loading