Skip to content

Commit 00ab659

Browse files
manugvsoxofaan
authored andcommitted
Added test for pixel-tolerance.
1 parent a8c7f3f commit 00ab659

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

tests/testing/test_results.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,39 @@ def test_simple_atol(self, actual, atol, expected_issues):
151151
expected = xarray.DataArray([1, 2, 3])
152152
assert _compare_xarray_dataarray(actual=actual, expected=expected, rtol=0, atol=atol) == expected_issues
153153

154+
@pytest.mark.parametrize(
155+
["actual", "atol", "pixel_tolerance", "expected_issues"],
156+
[
157+
(xarray.DataArray([1, 2, 3.001, 4, 5]), 1e-4, 21.0, []),
158+
(xarray.DataArray([1, 2, 3.00001, 4.1, 5]), 1e-4, 21, []),
159+
(
160+
xarray.DataArray([1, 2, 3.001, 4.1, 5]),
161+
1e-4,
162+
21,
163+
[
164+
dirty_equals.IsStr(
165+
regex=r"Percentage number of pixels that are different is above the threshold",
166+
regex_flags=re.DOTALL,
167+
)
168+
],
169+
),
170+
(
171+
xarray.DataArray([1, 2, 3.001, 4, 5]),
172+
1e-4,
173+
0,
174+
[dirty_equals.IsStr(regex=r"Left and right DataArray objects are not close.*", regex_flags=re.DOTALL)],
175+
),
176+
],
177+
)
178+
def test_simple_pixel_tolerance(self, actual, atol, pixel_tolerance, expected_issues):
179+
expected = xarray.DataArray([1, 2, 3, 4, 5])
180+
assert (
181+
_compare_xarray_dataarray(
182+
actual=actual, expected=expected, atol=atol, rtol=0, pixel_tolerance=pixel_tolerance
183+
)
184+
== expected_issues
185+
)
186+
154187

155188
def test_nan_handling(self):
156189
expected = xarray.DataArray([1, 2, numpy.nan, 4, float("nan")])

0 commit comments

Comments
 (0)