Skip to content

Commit 70c8a4f

Browse files
authored
Merge pull request #15263 from anntzer/test_compare_images
Correctly setup comparisons in test_compare_images.
2 parents d706018 + 93aad5f commit 70c8a4f

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

lib/matplotlib/testing/compare.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,8 @@ def compare_images(expected, actual, tol, in_decorator=False):
380380
raise IOError('Baseline image %r does not exist.' % expected)
381381
extension = expected.split('.')[-1]
382382
if extension != 'png':
383-
actual = convert(actual, False)
384-
expected = convert(expected, True)
383+
actual = convert(actual, cache=False)
384+
expected = convert(expected, cache=True)
385385

386386
# open the image files and remove the alpha channel (if it exists)
387387
with open(expected, "rb") as expected_file:

lib/matplotlib/tests/test_compare_images.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
import os
2+
from pathlib import Path
23
import shutil
34

45
import pytest
56
from pytest import approx
67

7-
from matplotlib.testing.compare import compare_images
8+
from matplotlib.testing.compare import compare_images, make_test_filename
89
from matplotlib.testing.decorators import _image_directories
910

1011

11-
baseline_dir, result_dir = _image_directories(lambda: 'dummy func')
12-
13-
1412
# Tests of the image comparison algorithm.
1513
@pytest.mark.parametrize(
1614
'im1, im2, tol, expect_rms',
@@ -56,14 +54,16 @@ def test_image_comparison_expect_rms(im1, im2, tol, expect_rms):
5654
succeed if compare_images succeeds. Otherwise, the test will succeed if
5755
compare_images fails and returns an RMS error almost equal to this value.
5856
"""
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)
6767

6868
if expect_rms is None:
6969
assert results is None

0 commit comments

Comments
 (0)