diff --git a/xrspatial/aspect.py b/xrspatial/aspect.py index a0fd626c5..8155d029e 100644 --- a/xrspatial/aspect.py +++ b/xrspatial/aspect.py @@ -445,7 +445,7 @@ def aspect(agg: xr.DataArray, else: # geodesic if z_unit not in Z_UNITS: raise ValueError( - f"z_unit must be one of {sorted(set(Z_UNITS.values()), key=str)}, " + f"z_unit must be one of {sorted(Z_UNITS)}, " f"got {z_unit!r}" ) z_factor = Z_UNITS[z_unit] diff --git a/xrspatial/slope.py b/xrspatial/slope.py index 74bc06b8c..85a857f64 100644 --- a/xrspatial/slope.py +++ b/xrspatial/slope.py @@ -412,7 +412,7 @@ def slope(agg: xr.DataArray, else: # geodesic if z_unit not in Z_UNITS: raise ValueError( - f"z_unit must be one of {sorted(set(Z_UNITS.values()), key=str)}, " + f"z_unit must be one of {sorted(Z_UNITS)}, " f"got {z_unit!r}" ) z_factor = Z_UNITS[z_unit] diff --git a/xrspatial/tests/test_geodesic_aspect.py b/xrspatial/tests/test_geodesic_aspect.py index fcf96163c..b661bc292 100644 --- a/xrspatial/tests/test_geodesic_aspect.py +++ b/xrspatial/tests/test_geodesic_aspect.py @@ -1,4 +1,6 @@ """Tests for geodesic aspect computation.""" +import re + import numpy as np import pytest import xarray as xr @@ -213,9 +215,17 @@ def test_invalid_method_raises(self): def test_invalid_z_unit_raises(self): elev = _flat_surface() raster = _make_geo_raster(elev, 40.0, 41.0, 10.0, 11.0) - with pytest.raises(ValueError, match="z_unit"): + with pytest.raises(ValueError, match="z_unit") as excinfo: aspect(raster, method='geodesic', z_unit='cubit') + # The message must list the accepted unit-name strings (the keys a + # user is allowed to pass), not the numeric conversion factors. + msg = str(excinfo.value) + assert "'meter'" in msg + assert "'foot'" in msg + # No bare numeric conversion factor should leak into the message. + assert not re.search(r"\d+\.\d+", msg) + def test_missing_coords_raises(self): data = np.ones((5, 5)) raster = xr.DataArray(data, dims=['dim_0', 'dim_1']) diff --git a/xrspatial/tests/test_geodesic_slope.py b/xrspatial/tests/test_geodesic_slope.py index 2747f95f5..64bb4240e 100644 --- a/xrspatial/tests/test_geodesic_slope.py +++ b/xrspatial/tests/test_geodesic_slope.py @@ -1,4 +1,6 @@ """Tests for geodesic slope computation.""" +import re + import numpy as np import pytest import xarray as xr @@ -209,9 +211,17 @@ def test_invalid_method_raises(self): def test_invalid_z_unit_raises(self): elev = _flat_surface() raster = _make_geo_raster(elev, 40.0, 41.0, 10.0, 11.0) - with pytest.raises(ValueError, match="z_unit"): + with pytest.raises(ValueError, match="z_unit") as excinfo: slope(raster, method='geodesic', z_unit='cubit') + # The message must list the accepted unit-name strings (the keys a + # user is allowed to pass), not the numeric conversion factors. + msg = str(excinfo.value) + assert "'meter'" in msg + assert "'foot'" in msg + # No bare numeric conversion factor should leak into the message. + assert not re.search(r"\d+\.\d+", msg) + def test_missing_coords_raises(self): data = np.ones((5, 5)) raster = xr.DataArray(data, dims=['dim_0', 'dim_1'])