Skip to content

Commit 68772fc

Browse files
thodson-usgsclaude
andcommitted
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) <noreply@anthropic.com>
1 parent 51ac674 commit 68772fc

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

dataretrieval/nldi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ def _validate_data_source(data_source: str):
486486
def _validate_navigation_mode(navigation_mode: str):
487487
navigation_mode = navigation_mode.upper()
488488
if navigation_mode not in ("UM", "DM", "UT", "DD"):
489-
raise TypeError(f"Invalid navigation mode '{navigation_mode}'")
489+
raise ValueError(f"Invalid navigation mode '{navigation_mode}'")
490490

491491

492492
def _validate_feature_source_comid(

tests/nldi_test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import pytest
12
from geopandas import GeoDataFrame
23

34
from dataretrieval.nldi import (
45
NLDI_API_BASE_URL,
6+
_validate_navigation_mode,
57
get_basin,
68
get_features,
79
get_flowlines,
@@ -280,3 +282,9 @@ def test_search_for_features_by_lat_long(requests_mock):
280282
assert search_results["features"][0]["type"] == "Feature"
281283
assert search_results["features"][0]["geometry"]["type"] == "LineString"
282284
assert len(search_results["features"][0]["geometry"]["coordinates"]) == 27
285+
286+
287+
def test_validate_navigation_mode_invalid_raises_value_error():
288+
"""Invalid navigation mode is a bad value, not a bad type -> ValueError."""
289+
with pytest.raises(ValueError, match="Invalid navigation mode"):
290+
_validate_navigation_mode("XX")

0 commit comments

Comments
 (0)