Skip to content

Commit

Permalink
complete tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienlanglois committed Jan 16, 2024
1 parent 4084d57 commit 5be464e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
10 changes: 8 additions & 2 deletions tests/test_gis.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,10 @@ def test_land_classification_xarray(

xr.testing.assert_equal(ds_classification, ds_expected)

def test_land_classification_plot(self, monkeypatch):
@pytest.mark.parametrize("unique_id,", [("Station"), (None)])
def test_land_classification_plot(self, unique_id, monkeypatch):
monkeypatch.setattr(plt, "show", lambda: None)
xh.gis.land_use_plot(self.gdf, unique_id="Station", idx=0)
xh.gis.land_use_plot(self.gdf, unique_id=unique_id, idx=0)

def test_errors(self):
with pytest.raises(
Expand All @@ -231,3 +232,8 @@ def test_errors(self):
match="Expected year argument None to be a digit.",
):
xh.gis.land_use_classification(self.gdf, unique_id="Station", year=None)
with pytest.raises(
TypeError,
match="Expected year argument None to be a digit.",
):
xh.gis.land_use_plot(self.gdf, unique_id="Station", idx=0, year=None)
7 changes: 3 additions & 4 deletions xhydro/gis.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,10 +475,9 @@ def land_use_plot(
if year == "latest":
year = str(merged.time.dt.year[-1].values)
else:
try:
year = str(year)
except TypeError:
print(f"Expected year argument {year} to be a digit.")
year = str(year)
if not year.isdigit():
raise TypeError(f"Expected year argument {year} to be a digit.")

merged = merged.sel(time=year).min("time")

Expand Down

0 comments on commit 5be464e

Please sign in to comment.