Skip to content

test(wqp): parametrize the what_* tests + factor shared assertions#336

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

test(wqp): parametrize the what_* tests + factor shared assertions#336
thodson-usgs merged 1 commit into
DOI-USGS:mainfrom
thodson-usgs:test/parametrize-wqp

Conversation

@thodson-usgs

Copy link
Copy Markdown
Collaborator

Draft. A test-only readability refactor — no production code, no coverage change.

What

The eight WQP what_* tests (test_what_sites, test_what_organizations, …)
were near-identical: each issued the same statecode=US:34 /
characteristicName=Chloride query against its own service endpoint and
repeated the same six assertions, differing only by:

  • the service path segment (Station, Organization, Activity, …),
  • the response fixture, and
  • the expected df.size.

This collapses them into a single @pytest.mark.parametrized test_what_query
driven by a _WHAT_CASES table, and factors the repeated metadata block
(md.url / query_time / mock_header / comment) into a
_assert_wqp_metadata helper now shared with the get_results /
get_results_WQX3 tests as well.

Why it's safe

  • Same coverage. All eight wrappers still run — each as its own parametrized
    case with a readable id, so a failure still points at the exact wrapper:
    test_what_query[what_sites]
    test_what_query[what_organizations]
    ... (8 total)
    
    Each case still asserts the correct service URL, parsed DataFrame, size, and
    metadata.
  • −90 lines (+59 / −149), and adding a new what_* wrapper is now one row
    in _WHAT_CASES instead of a ~16-line copy-paste.
  • 15 tests pass offline; ruff / mypy clean.

Scope

WQP only — the clearest case from the suite review. A similar parametrize-refactor
of nwis_test.py::TestMetaData (6 near-identical site_info cases) is a possible
follow-up, but it lives in a file currently being changed by #335, so I left it
out to avoid churn.

🤖 Generated with Claude Code

…tions

The eight `what_*` tests were near-identical — each issued the same
`statecode`/`characteristicName` query against its own service endpoint and
repeated the same six assertions, differing only by the service path segment,
the response fixture, and the expected size. Collapse them into one
`@pytest.mark.parametrize`d `test_what_query` (readable ids per wrapper), and
factor the repeated metadata block (`url` / `query_time` / `mock_header` /
`comment`) into a `_assert_wqp_metadata` helper now shared with the
`get_results` tests too.

Same coverage (all eight wrappers still exercised, each as its own parametrized
case), ~75 fewer lines, and a new wrapper is now one row in `_WHAT_CASES`.
@thodson-usgs thodson-usgs marked this pull request as ready for review June 24, 2026 20:33
@thodson-usgs thodson-usgs merged commit 8bb15a2 into DOI-USGS:main Jun 24, 2026
9 checks passed
@thodson-usgs thodson-usgs deleted the test/parametrize-wqp branch June 24, 2026 20:33
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