Skip to content

test: parametrize two clean duplicated-test clusters#337

Merged
thodson-usgs merged 1 commit into
DOI-USGS:mainfrom
thodson-usgs:test/parametrize-more
Jun 24, 2026
Merged

test: parametrize two clean duplicated-test clusters#337
thodson-usgs merged 1 commit into
DOI-USGS:mainfrom
thodson-usgs:test/parametrize-more

Conversation

@thodson-usgs

@thodson-usgs thodson-usgs commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

Draft. Follow-up to #336 (the WQP what_* parametrization, merged). Test-only.

Scope (revised after a readability pass)

Parametrization trades named tests for a data table, so it's only a win when it
reduces LOC and the cases are pure data-variations of one assertion with
no per-case rationale lost. Two clusters clear that bar:

  • _format_api_dates (waterdata_utils_test.py) — 12 one-line equality tests
    → 1 (13 rows, explicit ids). Big, clean reduction.
  • TestNormalizeStrIterable iterable-normalizes (waterdata_test.py) — 4 → 1;
    same assertion, only the container type varies (list / tuple / Series / ndarray).

Net −16 lines, every case preserved, readable ids
(test_format_api_dates[offset_to_utc], …[ndarray]). 89 tests pass; ruff/mypy clean.

Deliberately NOT parametrized

After a second look I dropped three clusters I'd initially collapsed — they made
the tests harder to read:

  • _parse_retry_after — these were 4 distinct documented behaviors (None
    fallback, delta-seconds, clamp-negative, unparseable), each with a docstring
    explaining the why. Flattening to bare tuples deleted that rationale.
  • _build_filter — the long CQL expected-strings forced multi-line tuples, so
    it didn't reduce LOC and read worse than 5 named one-line tests.
  • reject-non-string-types — only 3 cases; the param table added lines, and the
    test names already documented each case.

Conventions used / proposed

  • Parametrize only when it cuts LOC and the cases are one-assertion data-variations.
  • Keep named tests when each encodes a distinct behavior or carries explanatory docs.
  • Always give explicit, readable ids (or pytest.param(..., id=...) for short
    data); keep the body to a single assertion.

🤖 Generated with Claude Code

Two clusters of near-identical tests that differ only by data collapse cleanly
into one `@pytest.mark.parametrize`d test each — a genuine LOC reduction with
every case preserved as a row carrying a readable id:

- waterdata_utils_test: `_format_api_dates` — 12 one-line equality tests → 1.
- waterdata_test: `TestNormalizeStrIterable` iterable-normalizes — 4 → 1 (same
  assertion, vary the container type: list / tuple / Series / ndarray).

Deliberately NOT parametrized (reconsidered for readability): `_parse_retry_after`
and the `_build_filter` / reject-type clusters. Those either encode distinct
behaviors with explanatory docstrings, or didn't actually reduce LOC (long
multi-line param tuples), so named tests read better there.
@thodson-usgs thodson-usgs force-pushed the test/parametrize-more branch from 2d24b8b to 190bef3 Compare June 24, 2026 20:53
@thodson-usgs thodson-usgs changed the title test: parametrize four more duplicated test clusters test: parametrize two clean duplicated-test clusters Jun 24, 2026
@thodson-usgs thodson-usgs marked this pull request as ready for review June 24, 2026 21:09
@thodson-usgs thodson-usgs merged commit 5b79b2d into DOI-USGS:main Jun 24, 2026
9 checks passed
@thodson-usgs thodson-usgs deleted the test/parametrize-more branch June 24, 2026 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant