|
1 | 1 | import os
|
| 2 | +from pathlib import Path |
2 | 3 | import shutil
|
3 | 4 |
|
4 | 5 | import pytest
|
5 | 6 | from pytest import approx
|
6 | 7 |
|
7 |
| -from matplotlib.testing.compare import compare_images |
| 8 | +from matplotlib.testing.compare import compare_images, make_test_filename |
8 | 9 | from matplotlib.testing.decorators import _image_directories
|
9 | 10 |
|
10 | 11 |
|
11 |
| -baseline_dir, result_dir = _image_directories(lambda: 'dummy func') |
12 |
| - |
13 |
| - |
14 | 12 | # Tests of the image comparison algorithm.
|
15 | 13 | @pytest.mark.parametrize(
|
16 | 14 | 'im1, im2, tol, expect_rms',
|
@@ -56,14 +54,16 @@ def test_image_comparison_expect_rms(im1, im2, tol, expect_rms):
|
56 | 54 | succeed if compare_images succeeds. Otherwise, the test will succeed if
|
57 | 55 | compare_images fails and returns an RMS error almost equal to this value.
|
58 | 56 | """
|
59 |
| - im1 = os.path.join(baseline_dir, im1) |
60 |
| - im2_src = os.path.join(baseline_dir, im2) |
61 |
| - im2 = os.path.join(result_dir, im2) |
62 |
| - # Move im2 from baseline_dir to result_dir. This will ensure that |
63 |
| - # compare_images writes the diff file to result_dir, instead of trying to |
64 |
| - # write to the (possibly read-only) baseline_dir. |
65 |
| - shutil.copyfile(im2_src, im2) |
66 |
| - results = compare_images(im1, im2, tol=tol, in_decorator=True) |
| 57 | + baseline_dir, result_dir = map(Path, _image_directories(lambda: "dummy")) |
| 58 | + # Copy both "baseline" and "test" image to result_dir, so that 1) |
| 59 | + # compare_images writes the diff to result_dir, rather than to the source |
| 60 | + # tree and 2) the baseline image doesn't appear missing to triage_tests.py. |
| 61 | + result_im1 = make_test_filename(result_dir / im1, "expected") |
| 62 | + shutil.copyfile(baseline_dir / im1, result_im1) |
| 63 | + result_im2 = result_dir / im1 |
| 64 | + shutil.copyfile(baseline_dir / im2, result_im2) |
| 65 | + results = compare_images( |
| 66 | + result_im1, result_im2, tol=tol, in_decorator=True) |
67 | 67 |
|
68 | 68 | if expect_rms is None:
|
69 | 69 | assert results is None
|
|
0 commit comments