From 68772fc7860b6d81e41c7c985dbebdeb7c59a99c Mon Sep 17 00:00:00 2001 From: thodson-usgs Date: Mon, 4 May 2026 01:51:43 -0500 Subject: [PATCH 1/2] nldi: raise ValueError (not TypeError) for invalid navigation mode `_validate_navigation_mode` raised `TypeError` for an invalid string value (e.g. "ABC"). The sister helper `_validate_data_source` in the same file already raises `ValueError` for the same kind of bad-input case. `TypeError` is reserved for cases where an argument's type is wrong; an unrecognized navigation-mode string is a value error. Co-Authored-By: Claude Opus 4.7 (1M context) --- dataretrieval/nldi.py | 2 +- tests/nldi_test.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/dataretrieval/nldi.py b/dataretrieval/nldi.py index 8cb8f0aa..64763938 100644 --- a/dataretrieval/nldi.py +++ b/dataretrieval/nldi.py @@ -486,7 +486,7 @@ def _validate_data_source(data_source: str): def _validate_navigation_mode(navigation_mode: str): navigation_mode = navigation_mode.upper() if navigation_mode not in ("UM", "DM", "UT", "DD"): - raise TypeError(f"Invalid navigation mode '{navigation_mode}'") + raise ValueError(f"Invalid navigation mode '{navigation_mode}'") def _validate_feature_source_comid( diff --git a/tests/nldi_test.py b/tests/nldi_test.py index 462a5755..a6551e8e 100644 --- a/tests/nldi_test.py +++ b/tests/nldi_test.py @@ -1,7 +1,9 @@ +import pytest from geopandas import GeoDataFrame from dataretrieval.nldi import ( NLDI_API_BASE_URL, + _validate_navigation_mode, get_basin, get_features, get_flowlines, @@ -280,3 +282,9 @@ def test_search_for_features_by_lat_long(requests_mock): assert search_results["features"][0]["type"] == "Feature" assert search_results["features"][0]["geometry"]["type"] == "LineString" assert len(search_results["features"][0]["geometry"]["coordinates"]) == 27 + + +def test_validate_navigation_mode_invalid_raises_value_error(): + """Invalid navigation mode is a bad value, not a bad type -> ValueError.""" + with pytest.raises(ValueError, match="Invalid navigation mode"): + _validate_navigation_mode("XX") From 38c79b8646dc8ef7fc0efa903508795291d05ff5 Mon Sep 17 00:00:00 2001 From: thodson-usgs Date: Mon, 4 May 2026 01:54:46 -0500 Subject: [PATCH 2/2] Drop trivial test for one-line ValueError change Co-Authored-By: Claude Opus 4.7 (1M context) --- tests/nldi_test.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tests/nldi_test.py b/tests/nldi_test.py index a6551e8e..462a5755 100644 --- a/tests/nldi_test.py +++ b/tests/nldi_test.py @@ -1,9 +1,7 @@ -import pytest from geopandas import GeoDataFrame from dataretrieval.nldi import ( NLDI_API_BASE_URL, - _validate_navigation_mode, get_basin, get_features, get_flowlines, @@ -282,9 +280,3 @@ def test_search_for_features_by_lat_long(requests_mock): assert search_results["features"][0]["type"] == "Feature" assert search_results["features"][0]["geometry"]["type"] == "LineString" assert len(search_results["features"][0]["geometry"]["coordinates"]) == 27 - - -def test_validate_navigation_mode_invalid_raises_value_error(): - """Invalid navigation mode is a bad value, not a bad type -> ValueError.""" - with pytest.raises(ValueError, match="Invalid navigation mode"): - _validate_navigation_mode("XX")