(self, shared, unit, error, dtype)
| 3998 | ), |
| 3999 | ) |
| 4000 | def test_init(self, shared, unit, error, dtype): |
| 4001 | original_unit = unit_registry.m |
| 4002 | scaled_unit = unit_registry.mm |
| 4003 | |
| 4004 | a = np.linspace(0, 1, 10).astype(dtype) * unit_registry.Pa |
| 4005 | b = np.linspace(-1, 0, 10).astype(dtype) * unit_registry.degK |
| 4006 | |
| 4007 | values_a = np.arange(a.shape[0]) |
| 4008 | dim_a = values_a * original_unit |
| 4009 | coord_a = dim_a.to(scaled_unit) |
| 4010 | |
| 4011 | values_b = np.arange(b.shape[0]) |
| 4012 | dim_b = values_b * unit |
| 4013 | coord_b = ( |
| 4014 | dim_b.to(scaled_unit) |
| 4015 | if unit_registry.is_compatible_with(dim_b, scaled_unit) |
| 4016 | and unit != scaled_unit |
| 4017 | else dim_b * 1000 |
| 4018 | ) |
| 4019 | |
| 4020 | variants = { |
| 4021 | "nothing": ({}, {}), |
| 4022 | "dims": ({"x": dim_a}, {"x": dim_b}), |
| 4023 | "coords": ( |
| 4024 | {"x": values_a, "y": ("x", coord_a)}, |
| 4025 | {"x": values_b, "y": ("x", coord_b)}, |
| 4026 | ), |
| 4027 | } |
| 4028 | coords_a, coords_b = variants[shared] |
| 4029 | |
| 4030 | dims_a, dims_b = ("x", "y") if shared == "nothing" else ("x", "x") |
| 4031 | |
| 4032 | a = xr.DataArray(data=a, coords=coords_a, dims=dims_a) |
| 4033 | b = xr.DataArray(data=b, coords=coords_b, dims=dims_b) |
| 4034 | |
| 4035 | if error is not None and shared != "nothing": |
| 4036 | with pytest.raises(error): |
| 4037 | xr.Dataset(data_vars={"a": a, "b": b}) |
| 4038 | |
| 4039 | return |
| 4040 | |
| 4041 | actual = xr.Dataset(data_vars={"a": a, "b": b}) |
| 4042 | |
| 4043 | units = merge_mappings( |
| 4044 | extract_units(a.rename("a")), extract_units(b.rename("b")) |
| 4045 | ) |
| 4046 | expected = attach_units( |
| 4047 | xr.Dataset(data_vars={"a": strip_units(a), "b": strip_units(b)}), units |
| 4048 | ) |
| 4049 | |
| 4050 | assert_units_equal(expected, actual) |
| 4051 | assert_equal(expected, actual) |
| 4052 | |
| 4053 | @pytest.mark.parametrize( |
| 4054 | "func", (pytest.param(str, id="str"), pytest.param(repr, id="repr")) |
nothing calls this directly
no test coverage detected