|
49 | 49 | string_types = str
|
50 | 50 |
|
51 | 51 |
|
| 52 | +SHAPE_MISMATCH_ERROR = """Error: Image dimensions did not match. |
| 53 | + Expected shape: {expected_shape} |
| 54 | + {expected_path} |
| 55 | + Actual shape: {actual_shape} |
| 56 | + {actual_path}""" |
| 57 | + |
| 58 | + |
52 | 59 | def _download_file(baseline, filename):
|
53 | 60 | # Note that baseline can be a comma-separated list of URLs that we can
|
54 | 61 | # then treat as mirrors
|
@@ -183,6 +190,7 @@ def pytest_runtest_setup(self, item):
|
183 | 190 | if compare is None:
|
184 | 191 | return
|
185 | 192 |
|
| 193 | + from PIL import Image |
186 | 194 | import matplotlib
|
187 | 195 | import matplotlib.pyplot as plt
|
188 | 196 | from matplotlib.testing.compare import compare_images
|
@@ -272,6 +280,17 @@ def item_function_wrapper(*args, **kwargs):
|
272 | 280 | baseline_image = os.path.abspath(os.path.join(result_dir, 'baseline-' + filename))
|
273 | 281 | shutil.copyfile(baseline_image_ref, baseline_image)
|
274 | 282 |
|
| 283 | + # Compare image size ourselves since the Matplotlib exception is a bit cryptic in this case |
| 284 | + # and doesn't show the filenames |
| 285 | + expected_shape = Image.open(baseline_image).size |
| 286 | + actual_shape = Image.open(test_image).size |
| 287 | + if expected_shape != actual_shape: |
| 288 | + error = SHAPE_MISMATCH_ERROR.format(expected_path=baseline_image, |
| 289 | + expected_shape=expected_shape, |
| 290 | + actual_path=test_image, |
| 291 | + actual_shape=actual_shape) |
| 292 | + pytest.fail(error, pytrace=False) |
| 293 | + |
275 | 294 | msg = compare_images(baseline_image, test_image, tol=tolerance)
|
276 | 295 |
|
277 | 296 | if msg is None:
|
|
0 commit comments