Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Correctly setup comparisons in test_compare_images. #15263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/matplotlib/testing/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,8 @@ def compare_images(expected, actual, tol, in_decorator=False):
raise IOError('Baseline image %r does not exist.' % expected)
extension = expected.split('.')[-1]
if extension != 'png':
actual = convert(actual, False)
expected = convert(expected, True)
actual = convert(actual, cache=False)
expected = convert(expected, cache=True)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(not directly related, but this is clearer and I was going through compare_images to try to understand the source of the warning...)


# open the image files and remove the alpha channel (if it exists)
with open(expected, "rb") as expected_file:
Expand Down
24 changes: 12 additions & 12 deletions lib/matplotlib/tests/test_compare_images.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import os
from pathlib import Path
import shutil

import pytest
from pytest import approx

from matplotlib.testing.compare import compare_images
from matplotlib.testing.compare import compare_images, make_test_filename
from matplotlib.testing.decorators import _image_directories


baseline_dir, result_dir = _image_directories(lambda: 'dummy func')


# Tests of the image comparison algorithm.
@pytest.mark.parametrize(
'im1, im2, tol, expect_rms',
Expand Down Expand Up @@ -56,14 +54,16 @@ def test_image_comparison_expect_rms(im1, im2, tol, expect_rms):
succeed if compare_images succeeds. Otherwise, the test will succeed if
compare_images fails and returns an RMS error almost equal to this value.
"""
im1 = os.path.join(baseline_dir, im1)
im2_src = os.path.join(baseline_dir, im2)
im2 = os.path.join(result_dir, im2)
# Move im2 from baseline_dir to result_dir. This will ensure that
# compare_images writes the diff file to result_dir, instead of trying to
# write to the (possibly read-only) baseline_dir.
shutil.copyfile(im2_src, im2)
results = compare_images(im1, im2, tol=tol, in_decorator=True)
baseline_dir, result_dir = map(Path, _image_directories(lambda: "dummy"))
# Copy both "baseline" and "test" image to result_dir, so that 1)
# compare_images writes the diff to result_dir, rather than to the source
# tree and 2) the baseline image doesn't appear missing to triage_tests.py.
result_im1 = make_test_filename(result_dir / im1, "expected")
shutil.copyfile(baseline_dir / im1, result_im1)
result_im2 = result_dir / im1
shutil.copyfile(baseline_dir / im2, result_im2)
results = compare_images(
result_im1, result_im2, tol=tol, in_decorator=True)

if expect_rms is None:
assert results is None
Expand Down