Skip to content

Commit

Permalink
also check whether the error for a invalid attribute is properly form…
Browse files Browse the repository at this point in the history
…atted
  • Loading branch information
keewis committed Apr 23, 2021
1 parent ebd511e commit 4d73a81
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pint_xarray/tests/test_accessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ def test_error_on_nonsense_units(self, example_unitless_da):
with pytest.raises(ValueError, match=str(da.name)):
da.pint.quantify(units="aecjhbav")

def test_error_on_nonsense_units_attrs(self, example_unitless_da):
da = example_unitless_da
da.attrs["units"] = "aecjhbav"
with pytest.raises(
ValueError, match=rf"{da.name}: {da.attrs['units']} \(attribute\)"
):
da.pint.quantify()

def test_parse_integer_inverse(self):
# Regression test for issue #40
da = xr.DataArray([10], attrs={"units": "m^-1"})
Expand Down Expand Up @@ -248,6 +256,14 @@ def test_error_on_nonsense_units(self, example_unitless_ds):
with pytest.raises(ValueError):
ds.pint.quantify(units={"users": "aecjhbav"})

def test_error_on_nonsense_units_attrs(self, example_unitless_ds):
ds = example_unitless_ds
ds.users.attrs["units"] = "aecjhbav"
with pytest.raises(
ValueError, match=rf"'users': {ds.users.attrs['units']} \(attribute\)"
):
ds.pint.quantify()

def test_error_indicates_problematic_variable(self, example_unitless_ds):
ds = example_unitless_ds
with pytest.raises(ValueError, match="'users'"):
Expand Down

0 comments on commit 4d73a81

Please sign in to comment.