Skip to content

Split test_regex_sync.py: two unrelated suites share one 1306-line module #352

Description

@derek73

tests/v2/test_regex_sync.py is 1306 lines holding two test suites that share almost nothing, and the seam is exact.

The seam, measured

Lines 1–193 pin nameparser.config constants against their hand copies in nameparser._pipeline/_render — the module's original job, and what its name says. Lines 194–1306 pin hand copies made inside tools/differential/expected_since_*.toml against the same constants, plus the corpus-derived guards #351 added.

By AST, over the whole file:

tail uses things the head DEFINES : ['_SANCTIONED_EXTRAS']
head uses things the tail DEFINES : none

One symbol, and it belongs on the ledger side regardless — it records the sanctioned divergence between the differential rules' character classes and _SCRIPT_RANGES, which is nothing to do with the config↔pipeline copies.

The module docstring's first three paragraphs exist entirely to explain why these two things live together. That is a filename's job.

Proposed split

file contents ~lines
tests/v2/test_regex_sync.py lines 1–193: _SOURCES, _MODULES, the seven *_matches_config tests, the declared-copy sweep, the comma-set pin. The name finally means what it says. 193
tests/v2/test_ledger_guards.py lines 194–1306 unchanged, plus _SANCTIONED_EXTRAS 1113
tests/v2/_differential_fixtures.py _TOOLS, _LEDGERS, _rules, _CORPUS_NAMES, _claimed, _UNCLASSIFIED_NAMES, and the compare.py path-loader ~90

The third file also removes a duplication tests/v2/test_differential.py currently carries: it has its own copy of the compare.py loader (_load_compare), and both modules independently glob the ledgers.

What NOT to do

Do not split the ledger half further — not by spans / vocabularies / claims. That is the same three-way category axis six review rounds proved is the wrong one: every widening found in #351 landed in whichever category the last guard did not cover, and two of the findings existed precisely because no reader could see two guards' coverage side by side. Splitting the guards across files makes that question harder, not easier. grep '^def test_' on one file currently answers "what is guarded"; across three files it does not.

Why this is a follow-up and not part of #351

The reviewers were divided, and the argument against splitting is good: co-location is what let a reader find #351's later defects by reading the file straight through, none of the six rounds' findings was caused by file length, and the module runs in 0.15s — there is no maintenance pain being paid today.

What tips it is that the two halves are genuinely unrelated, and that the guard set has now stopped moving. Doing it while the guards were still being redesigned would have meant rewriting the split every round.

Acceptance

  • No test is added, removed or changed — pure moves plus imports.
  • uv run pytest tests/v2/ -q reports the same count before and after.
  • AGENTS.md:185 lists test_regex_sync.py under "one test module per source module plus the cross-cutting ones"; the new module needs adding there in the same commit.

Follow-up to #351. Filed at Derek's request after the six-round review.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions