Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion xrspatial/aspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion xrspatial/slope.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
12 changes: 11 additions & 1 deletion xrspatial/tests/test_geodesic_aspect.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Tests for geodesic aspect computation."""
import re

import numpy as np
import pytest
import xarray as xr
Expand Down Expand Up @@ -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'])
Expand Down
12 changes: 11 additions & 1 deletion xrspatial/tests/test_geodesic_slope.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Tests for geodesic slope computation."""
import re

import numpy as np
import pytest
import xarray as xr
Expand Down Expand Up @@ -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'])
Expand Down
Loading