Skip to content

Commit 150ba47

Browse files
authored
docs(tests): fourth whole-repo pass over tests (#1103) (#1915)
* docs(tests): fourth whole-repo pass over tests (#1103) Accuracy: - correct the pyproject.toml lines the linktype-209 gate cites, and say that cron-vendor.yml does run that pin when a crawl changes a constant - the MH default-argument cleanup comment no longer calls _missing_ loud or says it sets sys.tracebacklimit (#1845) - the builtin-parity rationale accounts for get()'s _CaughtByCaller block - conftest.py's docstring lists the session hooks it holds - the PyPCAPFile marker note names the legs by version, PyPy included - fix a "below" that pointed at a constant defined above it Counts: - reword codebase counts count-free in comments and docstrings, including the enum no-mint narrative and the arithmetic comment that no longer added up; the asserted constants carry the figures instead Timed context: - drop "today", "currently" and "as of <round>" where they added nothing Prose only: an AST guard with docstrings blanked is identical on every file. Refs #1103 * test: address #1915 review (#1103) - test_const_linktype_209_unit: cite the pyproject note as :325-332, and drop "since #849" for a plain issue cite. - test_mh_unit: drop "any more" from the tracebacklimit cleanup comment. - Drop remaining counts of codebase items and timed wording ("now", "any more", "no longer", "since #") from comments and docstrings in test_const_enum_no_mint, test_const_method_value_lookup_908_unit, test_const_registry_protocol, test_fields_copy_dispatch_unit, test_ipv6_ext_unit, test_option_generator_tcp_base_unit, test_docstring_contract and test_vendor_missing_body_unit. Comments and docstrings only; the AST is unchanged. * test: name the #860 exception instead of counting it (#1103) - test_const_enum_no_mint: say #860 step 2's PR 1 converted every bespoke class except AppType, rather than "most" of them. - Drop "now" and "any more" from the RulingConversionSourceTests comment. Comments and docstrings only; the AST is unchanged.
1 parent 0d91e8e commit 150ba47

55 files changed

Lines changed: 249 additions & 243 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎tests/_dependency_gates.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@
4545
4646
One thing this deliberately does not model, recorded here rather than left to
4747
be discovered: **environment markers.** ``PyPCAPFile = [ "pypcapfile;
48-
python_version < '3.12'" ]`` resolves to nothing on four of the five supported
49-
legs (3.12-3.15), so an install line carrying that extra would satisfy this module
50-
while only 3.11 and the KTLO legs ran the tests. :func:`requirement_key`
48+
python_version < '3.12'" ]`` resolves to nothing on every leg from 3.12 up,
49+
so an install line carrying that extra would satisfy this module while only the
50+
legs below 3.12 ran the tests. :func:`requirement_key`
5151
strips the marker and :func:`provided_by` ignores it; the marker text is kept
5252
on :class:`Requirement` so a diagnostic can say so.
5353
@@ -195,7 +195,7 @@
195195
# generated constants on a schedule rather than as a check -- so excluding
196196
# this flag would have left `make isort`'s verdict unverified everywhere,
197197
# which is the #766 complaint. Cost does not argue the other way either:
198-
# isort is a pure-Python wheel and all four Makefile lines together measure
198+
# isort is a pure-Python wheel and the Makefile's isort lines together measure
199199
# about 1.5s, against the ~238 MB and licence questions that keep ``NGAP``
200200
# out of ``all``.
201201
'isort': ('isort',),
@@ -1153,7 +1153,7 @@ def module_flag_requirements(path: 'pathlib.Path') -> 'dict[str, frozenset[str]]
11531153
11541154
Public for the same reason :func:`module_gates` is: the shapes it has to
11551155
understand are best pinned against source written to exercise them one at a
1156-
time, rather than against whichever of them the suite happens to use today.
1156+
time, rather than against whichever of them the suite happens to use.
11571157
11581158
"""
11591159
try:
@@ -1535,7 +1535,7 @@ def pytest_jobs(workflow: 'Optional[pathlib.Path]' = None) -> 'tuple[Job, ...]':
15351535
# `integration` job's names `fixture_tier_paths()`, so classifying on
15361536
# the whole job section reads `gate` as an ignore-selection job and
15371537
# credits it with reaching only the unit tier. Matching on the step name
1538-
# would work today and break the day a step is renamed.
1538+
# would work only until a step is renamed.
15391539
steps = re.findall(r'(?ms)^ - name: [^\n]*\n(.*?)(?=^ - name:|\Z)', section)
15401540
running = [step for step in steps if 'python -m pytest' in step]
15411541
if len(running) != 1:

‎tests/_support.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -794,8 +794,8 @@ def restore_modules_after(test: 'unittest.TestCase',
794794
Registered **once per test** however many times this is called, and the
795795
snapshot kept is the first one -- the only one taken before any of the loads
796796
wrote anything. That is what lets :func:`bootstrap_core_modules` announce
797-
itself and then make seven :func:`load_module` calls without registering
798-
eight cleanups to eight successively more polluted snapshots.
797+
itself and then make a run of :func:`load_module` calls without registering
798+
a cleanup per call, each to a successively more polluted snapshot.
799799
800800
Registered with :meth:`~unittest.TestCase.addCleanup` rather than done in a
801801
``tearDown``, for the reasons :func:`isolate_modules` gives: it runs even
@@ -1008,7 +1008,7 @@ def purge_modules(prefixes: Iterable[str]) -> None:
10081008
test. Take the two together rather than reading the paragraph above as a promise
10091009
that a purge leaves no trace -- under a runner that loads no ``conftest``, it
10101010
does. Measured on ``b337cdbc2``: ``python -m unittest discover -s tests/corekit``
1011-
fails 5 of that class's identity subtests, because ``test_module`` sorts first
1011+
fails that class's identity subtests, because ``test_module`` sorts first
10121012
and purges, while the same file alone passes and :program:`pytest` -- the
10131013
supported runner, and what :file:`.github/workflows/unit-tests.yml` invokes --
10141014
passes either way.

‎tests/_tiers.py‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@
7474
7575
What neither catches, deliberately: a unit-tier module that opens a capture
7676
without going through :func:`~tests._support.sample_path` at all, e.g. by joining
77-
:file:`examples/captures/` and a name itself. No *unit-tier* module does this
78-
today -- :file:`tests/protocols/misc/test_pcapng_unit.py` was the last one and
79-
now reads ``sample_path('dhcp_big_endian.pcapng')`` inside the ``try``/``except
77+
:file:`examples/captures/` and a name itself. No *unit-tier* module does this:
78+
:file:`tests/protocols/misc/test_pcapng_unit.py` was the last one, and
79+
reads ``sample_path('dhcp_big_endian.pcapng')`` inside the ``try``/``except
8080
FileNotFoundError`` idiom :func:`explain` recommends. Only the *unit* tier is
8181
claimed there, deliberately: fixture-tier modules join the directory freely and
8282
are entitled to, e.g. :file:`tests/protocols/test_option_coverage_runtime.py`,
@@ -734,7 +734,7 @@ def skip_idiom_modules() -> 'tuple[pathlib.Path, ...]':
734734
:func:`audit_module` carries and for the same reason: a name computed at
735735
call time, e.g. ``sample_path(sample)`` in a parametrised loop, is
736736
invisible to a static pass. No module in the suite does this inside a
737-
handled call today -- see ``test_every_handled_call_names_a_literal_capture``
737+
handled call -- see ``test_every_handled_call_names_a_literal_capture``
738738
in :file:`tests/test_tier_guard.py`, which exists to catch the day one does,
739739
since such a call would silently drop out of this function's result and
740740
its fixture-backed coverage would quietly stop running anywhere.
@@ -771,12 +771,12 @@ def _enclosing_scope(tree: 'ast.Module', lineno: 'int') -> 'Optional[tuple[Optio
771771
carry that context as it goes. "Most tightly" is decided by span, so a
772772
helper function defined inside a test method and containing the line in
773773
question would win over the test method itself; nothing in this suite's
774-
skip idiom does that today, but the rule is stated so a future one is
774+
skip idiom does that, but the rule is stated so a future one is
775775
handled the same way :func:`sample_path_calls` already treats nesting.
776776
777777
Returns:
778778
:data:`None` if no function definition contains ``lineno`` at all --
779-
a module-level call, which does not happen in this suite today.
779+
a module-level call, which does not happen in this suite.
780780
781781
"""
782782
best = None # type: Optional[tuple[Optional[str], str, int]]
@@ -822,8 +822,8 @@ def skip_idiom_test_ids() -> 'tuple[str, ...]':
822822
823823
Falls back to the *module* path when a handled call cannot be resolved to
824824
one enclosing function -- :func:`_enclosing_scope` returns :data:`None` for
825-
a module-level call, which is not a shape this suite's skip idiom uses
826-
today, but a fallback that still runs the file is safer than one that
825+
a module-level call, which is not a shape this suite's skip idiom uses,
826+
but a fallback that still runs the file is safer than one that
827827
drops the call's coverage entirely.
828828
829829
Returns:

‎tests/conftest.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# -*- coding: utf-8 -*-
22
"""Suite-wide :program:`pytest` configuration.
33
4-
Holds three things. The first is :func:`restore_module_table`, the guard that
4+
Besides session hooks documented where they are defined -- the warm import
5+
and coverage flush in :func:`pytest_sessionstart` and
6+
:func:`pytest_sessionfinish`, and the timer release in
7+
:func:`pytest_timeout_cancel_timer` -- it holds the following. The first is
8+
:func:`restore_module_table`, the guard that
59
puts the :mod:`pcapkit` region of :data:`sys.modules` back after every test; see
610
its own docstring for why it is here rather than left to each test file.
711

‎tests/const/test_const_apptype_split_unit.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ def test_every_transport_named_span_is_claimed_by_one_registry(self) -> None:
669669
:mod:`pcapkit.vendor.reg.apptype.apptype` stops emitting the test -- and
670670
it returns silently, because a shadowed branch is unreachable rather than
671671
wrong. This asserts the invariant over every branch instead of over the two
672-
spans that happen to collide today: a branch minting a member for a named
672+
spans that happen to collide: a branch minting a member for a named
673673
transport protocol is claimed by that registry, and one minting for
674674
``undefined`` claims nothing, since IANA's unassigned and reserved markers
675675
belong to whichever registry was asked.

‎tests/const/test_const_enum_builtin_parity.py‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,11 +432,17 @@ def test_the_exception_is_not_an_in_library_one(self) -> None:
432432
"""Explicitly *not* ``EnumError``, and explicitly not loud.
433433
434434
:class:`~pcapkit.utilities.exceptions.BaseError` logs at CRITICAL from
435-
its constructor, so it fires even for an exception that is caught and
436-
discarded -- which the ``except ValueError`` fallback in every generated
437-
``get()`` does on purpose. A guard raising a
435+
its constructor unless it is quiet, so it fires even for an exception
436+
that is caught and discarded. The base
437+
:meth:`~pcapkit.corekit.enum.EnumLookup.get` constructs its lookup inside
438+
a ``_CaughtByCaller(ValueError)`` block (#1845), which quiets a
439+
:exc:`ValueError` subclass there, but a direct ``cls(value)`` caught by
440+
its caller has no such block: a guard raising a
438441
:class:`~pcapkit.utilities.exceptions.BaseError` subclass would log once
439-
per discarded default.
442+
per value discarded that way. And
443+
:class:`~pcapkit.utilities.exceptions.EnumError`, not being a
444+
:exc:`ValueError`, would escape its ``except ValueError`` fallback
445+
altogether.
440446
"""
441447
from pcapkit.utilities.exceptions import BaseError, EnumError
442448

0 commit comments

Comments
 (0)