Skip to content

Commit a435f55

Browse files
committed
De-dupe variant parametrization
1 parent 9df04a5 commit a435f55

File tree

2 files changed

+29
-131
lines changed

2 files changed

+29
-131
lines changed

xarray/tests/test_units/params.py

+12
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,15 @@ def parametrize_unit_compatibility(error, allow_compatible_unit=True):
2020
),
2121
ids=repr,
2222
)
23+
24+
25+
parametrize_variant = pytest.mark.parametrize(
26+
"variant",
27+
(
28+
"data",
29+
pytest.param(
30+
"dims", marks=pytest.mark.skip(reason="indexes don't support units")
31+
),
32+
"coords",
33+
),
34+
)

xarray/tests/test_units/test_units.py

+17-131
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
requires_matplotlib,
2020
)
2121
from xarray.tests.test_plot import PlotTestCase
22-
from xarray.tests.test_units.params import parametrize_unit_compatibility
22+
from xarray.tests.test_units.params import (
23+
parametrize_unit_compatibility,
24+
parametrize_variant,
25+
)
2326
from xarray.tests.test_units.pint import unit_registry
2427
from xarray.tests.test_variable import _PAD_XR_NP_ARGS
2528

@@ -369,16 +372,7 @@ def __repr__(self):
369372
return f"function_{self.name}"
370373

371374

372-
@pytest.mark.parametrize(
373-
"variant",
374-
(
375-
"data",
376-
pytest.param(
377-
"dims", marks=pytest.mark.skip(reason="indexes don't support units")
378-
),
379-
"coords",
380-
),
381-
)
375+
@parametrize_variant
382376
def test_apply_ufunc_dataarray(variant, dtype):
383377
variants = {
384378
"data": (unit_registry.m, 1, 1),
@@ -402,16 +396,7 @@ def test_apply_ufunc_dataarray(variant, dtype):
402396
assert_identical(expected, actual)
403397

404398

405-
@pytest.mark.parametrize(
406-
"variant",
407-
(
408-
"data",
409-
pytest.param(
410-
"dims", marks=pytest.mark.skip(reason="indexes don't support units")
411-
),
412-
"coords",
413-
),
414-
)
399+
@parametrize_variant
415400
def test_apply_ufunc_dataset(variant, dtype):
416401
variants = {
417402
"data": (unit_registry.m, 1, 1),
@@ -445,16 +430,7 @@ def test_apply_ufunc_dataset(variant, dtype):
445430

446431

447432
@parametrize_unit_compatibility(DimensionalityError)
448-
@pytest.mark.parametrize(
449-
"variant",
450-
(
451-
"data",
452-
pytest.param(
453-
"dims", marks=pytest.mark.skip(reason="indexes don't support units")
454-
),
455-
"coords",
456-
),
457-
)
433+
@parametrize_variant
458434
@pytest.mark.parametrize("value", (10, dtypes.NA))
459435
def test_align_dataarray(value, variant, unit, error, dtype):
460436
if variant == "coords" and (
@@ -537,16 +513,7 @@ def test_align_dataarray(value, variant, unit, error, dtype):
537513

538514

539515
@parametrize_unit_compatibility(DimensionalityError)
540-
@pytest.mark.parametrize(
541-
"variant",
542-
(
543-
"data",
544-
pytest.param(
545-
"dims", marks=pytest.mark.skip(reason="indexes don't support units")
546-
),
547-
"coords",
548-
),
549-
)
516+
@parametrize_variant
550517
@pytest.mark.parametrize("value", (10, dtypes.NA))
551518
def test_align_dataset(value, unit, variant, error, dtype):
552519
if variant == "coords" and (
@@ -687,16 +654,7 @@ def test_broadcast_dataset(dtype):
687654

688655

689656
@parametrize_unit_compatibility(DimensionalityError)
690-
@pytest.mark.parametrize(
691-
"variant",
692-
(
693-
"data",
694-
pytest.param(
695-
"dims", marks=pytest.mark.skip(reason="indexes don't support units")
696-
),
697-
"coords",
698-
),
699-
)
657+
@parametrize_variant
700658
def test_combine_by_coords(variant, unit, error, dtype):
701659
original_unit = unit_registry.m
702660

@@ -752,16 +710,7 @@ def test_combine_by_coords(variant, unit, error, dtype):
752710

753711

754712
@parametrize_unit_compatibility(DimensionalityError)
755-
@pytest.mark.parametrize(
756-
"variant",
757-
(
758-
"data",
759-
pytest.param(
760-
"dims", marks=pytest.mark.skip(reason="indexes don't support units")
761-
),
762-
"coords",
763-
),
764-
)
713+
@parametrize_variant
765714
def test_combine_nested(variant, unit, error, dtype):
766715
original_unit = unit_registry.m
767716

@@ -846,16 +795,7 @@ def test_combine_nested(variant, unit, error, dtype):
846795

847796

848797
@parametrize_unit_compatibility(DimensionalityError)
849-
@pytest.mark.parametrize(
850-
"variant",
851-
(
852-
"data",
853-
pytest.param(
854-
"dims", marks=pytest.mark.skip(reason="indexes don't support units")
855-
),
856-
"coords",
857-
),
858-
)
798+
@parametrize_variant
859799
def test_concat_dataarray(variant, unit, error, dtype):
860800
original_unit = unit_registry.m
861801

@@ -902,16 +842,7 @@ def test_concat_dataarray(variant, unit, error, dtype):
902842

903843

904844
@parametrize_unit_compatibility(DimensionalityError)
905-
@pytest.mark.parametrize(
906-
"variant",
907-
(
908-
"data",
909-
pytest.param(
910-
"dims", marks=pytest.mark.skip(reason="indexes don't support units")
911-
),
912-
"coords",
913-
),
914-
)
845+
@parametrize_variant
915846
def test_concat_dataset(variant, unit, error, dtype):
916847
original_unit = unit_registry.m
917848

@@ -956,16 +887,7 @@ def test_concat_dataset(variant, unit, error, dtype):
956887

957888

958889
@parametrize_unit_compatibility(DimensionalityError)
959-
@pytest.mark.parametrize(
960-
"variant",
961-
(
962-
"data",
963-
pytest.param(
964-
"dims", marks=pytest.mark.skip(reason="indexes don't support units")
965-
),
966-
"coords",
967-
),
968-
)
890+
@parametrize_variant
969891
def test_merge_dataarray(variant, unit, error, dtype):
970892
original_unit = unit_registry.m
971893

@@ -1048,16 +970,7 @@ def test_merge_dataarray(variant, unit, error, dtype):
1048970

1049971

1050972
@parametrize_unit_compatibility(DimensionalityError)
1051-
@pytest.mark.parametrize(
1052-
"variant",
1053-
(
1054-
"data",
1055-
pytest.param(
1056-
"dims", marks=pytest.mark.skip(reason="indexes don't support units")
1057-
),
1058-
"coords",
1059-
),
1060-
)
973+
@parametrize_variant
1061974
def test_merge_dataset(variant, unit, error, dtype):
1062975
original_unit = unit_registry.m
1063976

@@ -1125,16 +1038,7 @@ def test_merge_dataset(variant, unit, error, dtype):
11251038
assert_allclose(expected, actual)
11261039

11271040

1128-
@pytest.mark.parametrize(
1129-
"variant",
1130-
(
1131-
"data",
1132-
pytest.param(
1133-
"dims", marks=pytest.mark.skip(reason="indexes don't support units")
1134-
),
1135-
"coords",
1136-
),
1137-
)
1041+
@parametrize_variant
11381042
@pytest.mark.parametrize("func", (xr.zeros_like, xr.ones_like))
11391043
def test_replication_dataarray(func, variant, dtype):
11401044
unit = unit_registry.m
@@ -1161,16 +1065,7 @@ def test_replication_dataarray(func, variant, dtype):
11611065
assert_identical(expected, actual)
11621066

11631067

1164-
@pytest.mark.parametrize(
1165-
"variant",
1166-
(
1167-
"data",
1168-
pytest.param(
1169-
"dims", marks=pytest.mark.skip(reason="indexes don't support units")
1170-
),
1171-
"coords",
1172-
),
1173-
)
1068+
@parametrize_variant
11741069
@pytest.mark.parametrize("func", (xr.zeros_like, xr.ones_like))
11751070
def test_replication_dataset(func, variant, dtype):
11761071
unit = unit_registry.m
@@ -2790,16 +2685,7 @@ def is_compatible(a, b):
27902685
pytest.param(unit_registry.m, id="identical_unit"),
27912686
),
27922687
)
2793-
@pytest.mark.parametrize(
2794-
"variant",
2795-
(
2796-
"data",
2797-
pytest.param(
2798-
"dims", marks=pytest.mark.skip(reason="indexes don't support units")
2799-
),
2800-
"coords",
2801-
),
2802-
)
2688+
@parametrize_variant
28032689
def test_broadcast_like(self, variant, unit, dtype):
28042690
original_unit = unit_registry.m
28052691

0 commit comments

Comments
 (0)