Skip to content

Commit 4e2e194

Browse files
thodson-usgsclaude
andcommitted
test(waterdata): Dedup TestCheckMonitoringLocationId; add per-item format check
``_check_monitoring_location_id`` is a thin wrapper that delegates iterable normalization to ``_normalize_str_iterable`` and only adds the AGENCY-ID format check. The duplicated iterable-handling cases (valid_list, none_passes, tuple/Series/Index/ndarray normalize, list-of-ints reject, dict reject) are already covered verbatim by ``TestNormalizeStrIterable`` below — keep only the format-check and public-API integration smokes in the wrapper's own suite. Adds one missing case the dedup exposed: the AGENCY-ID format check must run on EVERY list element (no test previously fed a list with a malformed entry past the first), so a regression that bailed early in ``_check_id_format``'s per-item loop would have gone undetected. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 1b534c9 commit 4e2e194

1 file changed

Lines changed: 15 additions & 62 deletions

File tree

tests/waterdata_test.py

Lines changed: 15 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -609,24 +609,20 @@ def test_get_channel():
609609

610610

611611
class TestCheckMonitoringLocationId:
612-
"""Tests for _check_monitoring_location_id input validation.
612+
"""Tests for the AGENCY-ID-specific layer over ``_normalize_str_iterable``.
613+
614+
Generic type/iterable normalization is covered by
615+
``TestNormalizeStrIterable`` below; this suite holds only the format
616+
check (``AGENCY-NUMBER`` shape) and the public-API integration smokes.
613617
614618
Regression tests for GitHub issue #188.
615619
"""
616620

617621
def test_valid_string(self):
618-
"""A correctly formatted string passes and is returned unchanged."""
622+
"""Happy-path smoke: the wrapper still routes through normalization
623+
for a well-formed AGENCY-ID string."""
619624
assert _check_monitoring_location_id("USGS-01646500") == "USGS-01646500"
620625

621-
def test_valid_list(self):
622-
"""A list of correctly formatted strings passes without error."""
623-
ids = ["USGS-01646500", "USGS-02238500"]
624-
assert _check_monitoring_location_id(ids) == ids
625-
626-
def test_none_passes(self):
627-
"""None is allowed (optional parameter)."""
628-
assert _check_monitoring_location_id(None) is None
629-
630626
def test_integer_raises_type_error(self):
631627
"""An integer ID raises TypeError with a helpful AGENCY-ID hint."""
632628
with pytest.raises(TypeError, match="not int") as exc_info:
@@ -635,11 +631,6 @@ def test_integer_raises_type_error(self):
635631
# helper alone doesn't carry.
636632
assert "USGS-01646500" in str(exc_info.value)
637633

638-
def test_integer_in_list_raises_type_error(self):
639-
"""An integer inside a list raises TypeError."""
640-
with pytest.raises(TypeError, match="not int"):
641-
_check_monitoring_location_id(["USGS-01646500", 5129115])
642-
643634
def test_missing_agency_prefix_raises_value_error(self):
644635
"""A string without the AGENCY- prefix raises ValueError."""
645636
with pytest.raises(ValueError, match="Invalid monitoring_location_id"):
@@ -655,57 +646,19 @@ def test_get_daily_integer_id_raises(self):
655646
with pytest.raises(TypeError):
656647
get_daily(monitoring_location_id=5129115, parameter_code="00060")
657648

658-
def test_tuple_normalizes_to_list(self):
659-
"""A tuple of valid strings is accepted and normalized to list."""
660-
result = _check_monitoring_location_id(("USGS-01646500", "USGS-02238500"))
661-
assert result == ["USGS-01646500", "USGS-02238500"]
662-
assert isinstance(result, list)
663-
664-
def test_pandas_series_normalizes_to_list(self):
665-
"""A pandas.Series of valid strings is accepted and normalized to list."""
666-
s = pd.Series(["USGS-01646500", "USGS-02238500"])
667-
result = _check_monitoring_location_id(s)
668-
assert result == ["USGS-01646500", "USGS-02238500"]
669-
assert isinstance(result, list)
670-
671-
def test_pandas_index_normalizes_to_list(self):
672-
"""A pandas.Index of valid strings is accepted and normalized to list."""
673-
idx = pd.Index(["USGS-01646500", "USGS-02238500"])
674-
result = _check_monitoring_location_id(idx)
675-
assert result == ["USGS-01646500", "USGS-02238500"]
676-
assert isinstance(result, list)
677-
678-
def test_numpy_array_normalizes_to_list(self):
679-
"""A numpy.ndarray of valid strings is accepted and normalized to list."""
680-
import numpy as np
681-
682-
arr = np.array(["USGS-01646500", "USGS-02238500"])
683-
result = _check_monitoring_location_id(arr)
684-
assert result == ["USGS-01646500", "USGS-02238500"]
685-
assert isinstance(result, list)
686-
687-
def test_numpy_int_array_raises_type_error(self):
688-
"""An iterable whose elements aren't strings (numpy int array) raises."""
689-
import numpy as np
690-
691-
with pytest.raises(TypeError, match="elements must be strings"):
692-
_check_monitoring_location_id(np.array([1, 2, 3]))
693-
694-
def test_pandas_series_of_ints_raises_type_error(self):
695-
"""An iterable whose elements aren't strings (Series of ints) raises."""
696-
with pytest.raises(TypeError, match="elements must be strings"):
697-
_check_monitoring_location_id(pd.Series([1, 2, 3]))
698-
699-
def test_dict_raises_type_error(self):
700-
"""Mappings are rejected — iterating a dict yields keys, which is a footgun."""
701-
with pytest.raises(TypeError, match="not dict"):
702-
_check_monitoring_location_id({"USGS-01646500": "site"})
703-
704649
def test_get_daily_malformed_id_raises(self):
705650
"""get_daily raises ValueError for a malformed string ID."""
706651
with pytest.raises(ValueError):
707652
get_daily(monitoring_location_id="dog", parameter_code="00060")
708653

654+
def test_per_item_format_check_in_list(self):
655+
"""The AGENCY-ID format check runs on EVERY element of an
656+
iterable, not just the first. Regression guard against a
657+
future ``_check_id_format`` loop that bails after one valid
658+
item or only checks the head."""
659+
with pytest.raises(ValueError, match="Invalid monitoring_location_id"):
660+
_check_monitoring_location_id(["USGS-01646500", "badformat"])
661+
709662

710663
class TestNormalizeStrIterable:
711664
"""Tests for the generic _normalize_str_iterable helper.

0 commit comments

Comments
 (0)