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/const/test_const_apptype_lazy_1538_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
:mod:`~pcapkit.const.reg.apptype.udp` are generated from IANA's registry and
hold about 49,700 lines of members between them; ``python -X importtime -c
'import pcapkit'`` put them at 104 ms and 102 ms of a 700 ms import. Nothing on
any import path needs them, so :mod:`pcapkit.const.reg.apptype` now imports them
any import path needs them, so :mod:`pcapkit.const.reg.apptype` imports them
from a :pep:`562` ``__getattr__`` and from
:attr:`AppType.__registries__ <pcapkit.const.reg.apptype.apptype.AppType.__registries__>`
the first time either is read.
Expand Down
19 changes: 10 additions & 9 deletions tests/const/test_const_apptype_register_range_1792_unit.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# -*- coding: utf-8 -*-
"""``AppType.register`` refuses a port that ``get`` refuses.

GitHub issue #1792. :meth:`~pcapkit.const.reg.apptype.apptype.AppType.register`
neither called nor overrode
:meth:`~pcapkit.corekit.enum.EnumLookup._validate_value`, so ``TCP.register(70000,
'x')`` minted a member, and ``AppType.get(70000, proto='tcp')`` then returned it
although ``get`` raises :exc:`ValueError` for a port outside ``0``-``65535``
(#758). ``AppType`` now overrides the hook with :meth:`_missing_`'s own check and
``register`` calls it after its duplicate check, as the base ``register`` does.
The override raises :exc:`~pcapkit.utilities.exceptions.EnumValueError`, as the
registry-protocol convention asks of one, with the message ``get`` raises.
GitHub issue #1792. Without the fix,
:meth:`~pcapkit.const.reg.apptype.apptype.AppType.register` neither calls nor
overrides :meth:`~pcapkit.corekit.enum.EnumLookup._validate_value`, so
``TCP.register(70000, 'x')`` mints a member, and ``AppType.get(70000,
proto='tcp')`` then returns it although ``get`` raises :exc:`ValueError` for a
port outside ``0``-``65535`` (#758). ``AppType`` overrides the hook with
:meth:`_missing_`'s own check and ``register`` calls it after its duplicate
check, as the base ``register`` does. The override raises
:exc:`~pcapkit.utilities.exceptions.EnumValueError`, as the registry-protocol
convention asks of one, with the message ``get`` raises.

Each test imports the registries after
:func:`~tests._support.reimport_once_per_class`, whose ``restore`` puts the
Expand Down
527 changes: 243 additions & 284 deletions tests/const/test_const_apptype_split_unit.py

Large diffs are not rendered by default.

321 changes: 148 additions & 173 deletions tests/const/test_const_enum_builtin_parity.py

Large diffs are not rendered by default.

304 changes: 129 additions & 175 deletions tests/const/test_const_enum_get.py

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions tests/const/test_const_enum_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
: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 now carries the same guard ending in
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
Expand All @@ -48,13 +48,12 @@
under :mod:`pcapkit.const`, including ones nothing else touches (e.g.
:mod:`pcapkit.const.reg.apptype`). ``tests/cli/test_main.py`` stubs pieces of
:mod:`pcapkit.utilities.compat` and :mod:`pcapkit.utilities.exceptions`
straight into :data:`sys.modules` for its own isolation and, depending on
suite order, those stubs used to still be sitting there when this module ran --
purging first forces a clean re-import instead of tripping over them. That file
has since been put under :func:`tests._support.isolate_modules` and puts them
back itself (issue #688), so it is no longer the specific hazard; the purge stays
because the convention is worth keeping and because the *next* stand-in written
without the helpers would be.
straight into :data:`sys.modules` for its own isolation; it runs under
:func:`tests._support.isolate_modules` and puts them back itself (issue #688).
The purge stays because the convention is worth keeping: a stand-in written
without the helpers would leave its stubs sitting there when this module runs,
depending on suite order, and purging first forces a clean re-import instead of
tripping over them.

"""
from __future__ import annotations
Expand Down Expand Up @@ -276,8 +275,8 @@ def test_ftp_return_code_missing_methods_are_classmethods(self) -> None:
self.assertIsInstance(ResponseKind.__dict__['_missing_'], classmethod)
self.assertIsInstance(GroupingInformation.__dict__['_missing_'], classmethod)

# And the actual symptom: every unknown value used to raise TypeError
# rather than extending the enum, not merely value 0.
# And the actual symptom: without the fix, every unknown value raises
# TypeError rather than extending the enum, not merely value 0.
self.assertEqual(int(ResponseKind(7)), 7)
self.assertEqual(int(ResponseKind(0)), 0)
self.assertEqual(int(GroupingInformation(9)), 9)
Expand All @@ -290,8 +289,8 @@ class ConstFlagMissingRecursionTests(unittest.TestCase):
enumerations ended in ``return cls(value)`` -- the constructor that had just
failed to find the value -- so every in-range non-member re-entered
``_missing_`` unbounded and raised :exc:`RecursionError`. The tests below
assert the *resolved* value rather than catching the recursion, so an
unfixed tree fails on the error rather than on an assertion, and the four
assert the *resolved* value rather than catching the recursion, so without
the fix they fail on the error rather than on an assertion, and the four
named registries are covered alongside the sweep.

"""
Expand Down Expand Up @@ -408,10 +407,11 @@ def test_the_vendor_templates_still_emit_the_fix(self) -> None:
import pathlib

# NOTE: the class statement names EnumRegistry and the first method after
# the enumeration block is a classmethod, because #775's tier 2 moved
# get/get_all/register/register_alias off these templates and onto
# pcapkit.corekit.enum.EnumRegistry -- the generated `@staticmethod get`
# that used to close the block is gone, leaving `_missing_` next.
# the enumeration block is a classmethod, because
# get/get_all/register/register_alias live on
# pcapkit.corekit.enum.EnumRegistry (#775's tier 2), not on these
# templates -- no generated `@staticmethod get` closes the block,
# leaving `_missing_` next.
block = re.compile(
r'class \w+\(EnumRegistry, IntFlag\):\n """.*?"""\n\n (.*?)\n\n @classmethod',
re.S)
Expand Down
Loading
Loading