Skip to content

Make tests faster #778

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 8 commits into from
Aug 5, 2012
Merged
Prev Previous commit
Next Next commit
Add a new kwarg to the image_comparison decorator, remove_text, which…
… 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
commit 342de605ffc81efc40b79b44b62f186c97af7a2c
26 changes: 23 additions & 3 deletions lib/matplotlib/testing/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import matplotlib
import matplotlib.tests
import matplotlib.units
from matplotlib import ticker
from matplotlib import pyplot as plt
from matplotlib import ft2font
import numpy as np
Expand Down Expand Up @@ -99,6 +100,16 @@ def setup_class(cls):

cls._func()

@staticmethod
def remove_text(figure):
Copy link
Member

Choose a reason for hiding this comment

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

docstring. also, does the axes.texts list need to be cleared?

Copy link
Member

Choose a reason for hiding this comment

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

also, does the axes.texts list need to be cleared?

Ignore that, the docstring below explains.

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):
baseline_dir, result_dir = _image_directories(self._func)

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

figure.savefig(actual_fname)

err = compare_images(expected_fname, actual_fname,
Expand All @@ -151,7 +165,8 @@ def 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::

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
The expected freetype version or range of versions for this
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:
Expand Down Expand Up @@ -210,7 +230,8 @@ def compare_images_decorator(func):
'_baseline_images': baseline_images,
'_extensions': extensions,
'_tol': tol,
'_freetype_version': freetype_version})
'_freetype_version': freetype_version,
'_remove_text': remove_text})

return new_class
return compare_images_decorator
Expand Down Expand Up @@ -242,4 +263,3 @@ def _image_directories(func):
os.makedirs(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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading