Skip to content

Commit 48b2cdb

Browse files
thodson-usgsclaude
andcommitted
test(waterdata): cover backward compat of every legacy camelCase get_samples kwarg
The existing tests check a couple of deprecated camelCase params end-to-end. Add a single unit test that iterates the whole `_SAMPLES_LEGACY_KWARGS` mapping and asserts, for every legacy name, that it is still accepted, emits a `DeprecationWarning` naming the snake_case replacement, is renamed to that param, and round-trips to the same Samples-API wire name it always used — so every existing camelCase call site keeps producing an identical request. A future param renamed without a legacy alias now fails this test. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Sjb14HkwuCydKSKMsaXsgd
1 parent 1981440 commit 48b2cdb

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

tests/waterdata_test.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,41 @@ def f(new_name=None):
219219
assert not [w for w in recwarn.list if w.category is DeprecationWarning]
220220

221221

222+
def test_every_legacy_camelcase_samples_kwarg_is_backward_compatible():
223+
"""Every deprecated camelCase ``get_samples`` parameter stays backward
224+
compatible: it is still accepted, is renamed to its snake_case replacement
225+
with a ``DeprecationWarning``, and resolves to the exact same Samples-API
226+
wire parameter it always did — so existing camelCase call sites keep
227+
producing identical requests after the rename. Covers the whole mapping, so
228+
a future param renamed without a legacy alias fails here."""
229+
from dataretrieval.waterdata.api import (
230+
_SAMPLES_LEGACY_KWARGS,
231+
_SAMPLES_PARAM_TO_API,
232+
)
233+
from dataretrieval.waterdata.utils import _accept_legacy_kwargs
234+
235+
assert _SAMPLES_LEGACY_KWARGS, "expected a non-empty legacy-kwarg mapping"
236+
237+
received = {}
238+
239+
@_accept_legacy_kwargs(_SAMPLES_LEGACY_KWARGS)
240+
def spy(**kwargs):
241+
received.clear()
242+
received.update(kwargs)
243+
244+
for old_camel, new_snake in _SAMPLES_LEGACY_KWARGS.items():
245+
# The deprecated camelCase name is accepted, warns, and is translated to
246+
# the snake_case parameter the function now expects ...
247+
with pytest.warns(DeprecationWarning, match=new_snake):
248+
spy(**{old_camel: "sentinel"})
249+
assert received == {new_snake: "sentinel"}, (
250+
f"legacy {old_camel!r} did not map to {new_snake!r}"
251+
)
252+
# ... and that snake_case parameter resolves back to the same camelCase
253+
# wire name, so the request is byte-identical to the pre-rename behavior.
254+
assert _SAMPLES_PARAM_TO_API[new_snake] == old_camel
255+
256+
222257
def test_check_profiles():
223258
"""Tests that correct errors are raised for invalid profiles."""
224259
with pytest.raises(ValueError):

0 commit comments

Comments
 (0)