|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | import contextlib |
| 4 | +import warnings |
4 | 5 | from pathlib import Path |
5 | 6 |
|
6 | 7 | import numpy as np |
|
9 | 10 |
|
10 | 11 | from ._show_diff import show_diff_helper |
11 | 12 |
|
| 13 | +FRAME_ABSOLUTE_TOLERANCE = 1.01 |
| 14 | +FRAME_MISMATCH_RATIO_TOLERANCE = 1e-5 |
| 15 | + |
12 | 16 |
|
13 | 17 | class _FramesTester: |
14 | 18 | def __init__(self, file_path: Path, show_diff=False) -> None: |
@@ -42,12 +46,27 @@ def check_frame(self, frame_number: int, frame: np.ndarray): |
42 | 46 | np.testing.assert_allclose( |
43 | 47 | frame, |
44 | 48 | self._frames[frame_number], |
45 | | - atol=1.01, |
| 49 | + atol=FRAME_ABSOLUTE_TOLERANCE, |
46 | 50 | err_msg=f"Frame no {frame_number}. You can use --show_diff to visually show the difference.", |
47 | 51 | verbose=False, |
48 | 52 | ) |
49 | 53 | self._frames_compared += 1 |
50 | 54 | except AssertionError as e: |
| 55 | + number_of_matches = np.isclose( |
| 56 | + frame, self._frames[frame_number], atol=FRAME_ABSOLUTE_TOLERANCE |
| 57 | + ).sum() |
| 58 | + number_of_mismatches = frame.size - number_of_matches |
| 59 | + if number_of_mismatches / frame.size < FRAME_MISMATCH_RATIO_TOLERANCE: |
| 60 | + # we tolerate a small (< 0.001%) amount of pixel value errors |
| 61 | + # in the tests, this accounts for minor OS dependent inconsistencies |
| 62 | + self._frames_compared += 1 |
| 63 | + warnings.warn( |
| 64 | + f"Mismatch of {number_of_mismatches} pixel values in frame {frame_number} " |
| 65 | + f"against control data in {self._file_path}. Below error threshold, " |
| 66 | + "continuing..." |
| 67 | + ) |
| 68 | + return |
| 69 | + |
51 | 70 | if self._show_diff: |
52 | 71 | show_diff_helper( |
53 | 72 | frame_number, |
|
0 commit comments