diff --git a/tests/nwis_test.py b/tests/nwis_test.py index 78e5b98b..c70b6e5b 100644 --- a/tests/nwis_test.py +++ b/tests/nwis_test.py @@ -332,7 +332,7 @@ def test_set_metadata_info_countyCd(self, httpx_mock): class TestReadRdb: - """Tests for the NWIS-specific _read_rdb wrapper. + """Tests for the NWIS-specific parse-then-format path. The format-agnostic parser is exercised in tests/rdb_test.py; this class pins the wrapper-specific contract — that an empty parser @@ -374,6 +374,17 @@ def test_no_peaks_flows_through_format_response(self): assert isinstance(df, pd.DataFrame) assert df.empty + def test_malformed_peaks_frame_still_raises(self): + """Only an *empty* peaks frame is a legitimate empty result. A + non-empty frame with no ``peak_dt`` column is a malformed response -- + a truncated or altered RDB header -- and must stay loud rather than be + returned silently without its datetime index. + """ + df = pd.DataFrame({"peak_va": [1000]}) + + with pytest.raises(KeyError, match="peak_dt"): + format_response(df, service="peaks") + class TestGetRecordDispatch: """``get_record`` is a router; each service must reach its own getter.