Skip to content

Commit

Permalink
Add a new kwarg to the image_comparison decorator, remove_text, which…
Browse files Browse the repository at this point in the history
… removes titles and ticks from a figure before comparison. Use this throughout to make more of the tests less dependent on text differences.
  • Loading branch information
mdboom committed Jun 13, 2012
1 parent bf23f41 commit 342de60
Show file tree
Hide file tree
Showing 120 changed files with 53,790 additions and 56,118 deletions.
26 changes: 23 additions & 3 deletions lib/matplotlib/testing/decorators.py
Expand Up @@ -6,6 +6,7 @@
import matplotlib import matplotlib
import matplotlib.tests import matplotlib.tests
import matplotlib.units import matplotlib.units
from matplotlib import ticker
from matplotlib import pyplot as plt from matplotlib import pyplot as plt
from matplotlib import ft2font from matplotlib import ft2font
import numpy as np import numpy as np
Expand Down Expand Up @@ -99,6 +100,16 @@ def setup_class(cls):


cls._func() cls._func()


@staticmethod
def remove_text(figure):
figure.suptitle("")
for ax in figure.get_axes():
ax.set_title("")
ax.xaxis.set_major_formatter(ticker.NullFormatter())
ax.xaxis.set_minor_formatter(ticker.NullFormatter())
ax.yaxis.set_major_formatter(ticker.NullFormatter())
ax.yaxis.set_minor_formatter(ticker.NullFormatter())

def test(self): def test(self):
baseline_dir, result_dir = _image_directories(self._func) baseline_dir, result_dir = _image_directories(self._func)


Expand Down Expand Up @@ -128,6 +139,9 @@ def test(self):
will_fail, fail_msg, will_fail, fail_msg,
known_exception_class=ImageComparisonFailure) known_exception_class=ImageComparisonFailure)
def do_test(): def do_test():
if self._remove_text:
self.remove_text(figure)

figure.savefig(actual_fname) figure.savefig(actual_fname)


err = compare_images(expected_fname, actual_fname, err = compare_images(expected_fname, actual_fname,
Expand All @@ -151,7 +165,8 @@ def do_test():


yield (do_test,) yield (do_test,)


def image_comparison(baseline_images=None, extensions=None, tol=1e-3, freetype_version=None): def image_comparison(baseline_images=None, extensions=None, tol=1e-3,
freetype_version=None, remove_text=False):
""" """
call signature:: call signature::
Expand Down Expand Up @@ -179,6 +194,11 @@ def image_comparison(baseline_images=None, extensions=None, tol=1e-3, freetype_v
*freetype_version*: str or tuple *freetype_version*: str or tuple
The expected freetype version or range of versions for this The expected freetype version or range of versions for this
test to pass. test to pass.
*remove_text*: bool
Remove the title and tick text from the figure before
comparison. This does not remove other, more deliberate,
text, such as legends and annotations.
""" """


if baseline_images is None: if baseline_images is None:
Expand Down Expand Up @@ -210,7 +230,8 @@ def compare_images_decorator(func):
'_baseline_images': baseline_images, '_baseline_images': baseline_images,
'_extensions': extensions, '_extensions': extensions,
'_tol': tol, '_tol': tol,
'_freetype_version': freetype_version}) '_freetype_version': freetype_version,
'_remove_text': remove_text})


return new_class return new_class
return compare_images_decorator return compare_images_decorator
Expand Down Expand Up @@ -242,4 +263,3 @@ def _image_directories(func):
os.makedirs(result_dir) os.makedirs(result_dir)


return baseline_dir, result_dir return baseline_dir, result_dir

Binary file modified lib/matplotlib/tests/baseline_images/test_axes/arc_ellipse.pdf
Binary file not shown.
Binary file modified lib/matplotlib/tests/baseline_images/test_axes/arc_ellipse.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 342de60

Please sign in to comment.