(self, func, unit, error, dtype)
| 1923 | ids=repr, |
| 1924 | ) |
| 1925 | def test_1d_math(self, func, unit, error, dtype): |
| 1926 | base_unit = unit_registry.m |
| 1927 | array = np.arange(5).astype(dtype) * base_unit |
| 1928 | variable = xr.Variable("x", array) |
| 1929 | |
| 1930 | values = np.ones(5) |
| 1931 | y = values * unit |
| 1932 | |
| 1933 | if error is not None and func.name in ("sum", "commutative_sum"): |
| 1934 | with pytest.raises(error): |
| 1935 | func(variable, y) |
| 1936 | |
| 1937 | return |
| 1938 | |
| 1939 | units = extract_units(func(array, y)) |
| 1940 | if all(compatible_mappings(units, extract_units(y)).values()): |
| 1941 | converted_y = convert_units(y, units) |
| 1942 | else: |
| 1943 | converted_y = y |
| 1944 | |
| 1945 | if all(compatible_mappings(units, extract_units(variable)).values()): |
| 1946 | converted_variable = convert_units(variable, units) |
| 1947 | else: |
| 1948 | converted_variable = variable |
| 1949 | |
| 1950 | expected = attach_units( |
| 1951 | func(strip_units(converted_variable), strip_units(converted_y)), units |
| 1952 | ) |
| 1953 | actual = func(variable, y) |
| 1954 | |
| 1955 | assert_units_equal(expected, actual) |
| 1956 | assert_allclose(expected, actual) |
| 1957 | |
| 1958 | @pytest.mark.parametrize( |
| 1959 | "unit,error", |
nothing calls this directly
no test coverage detected