Skip to content

De-duplicate some unit test paramatrization #7800

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
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
Empty file.
34 changes: 34 additions & 0 deletions xarray/tests/test_units/params.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import pytest

pint = pytest.importorskip("pint")
from xarray.tests.test_units.pint import unit_registry


def parametrize_unit_compatibility(error, allow_compatible_unit=True):
return pytest.mark.parametrize(
"unit,error",
(
pytest.param(1, error, id="no_unit"),
pytest.param(unit_registry.dimensionless, error, id="dimensionless"),
pytest.param(unit_registry.s, error, id="incompatible_unit"),
pytest.param(
unit_registry.mm,
None if allow_compatible_unit else error,
id="compatible_unit",
),
pytest.param(unit_registry.m, None, id="identical_unit"),
),
ids=repr,
)


parametrize_variant = pytest.mark.parametrize(
"variant",
(
"data",
pytest.param(
"dims", marks=pytest.mark.skip(reason="indexes don't support units")
),
"coords",
),
)
7 changes: 7 additions & 0 deletions xarray/tests/test_units/pint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import pytest

pint = pytest.importorskip("pint")

# make sure scalars are converted to 0d arrays so quantities can
# always be treated like ndarrays
unit_registry = pint.UnitRegistry(force_ndarray_like=True)
Loading