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
Next Next commit
Change generated filenames. Put the phrases "expected" and "failed-di…
…ff" toward the end of the filename so files are more appropriately grouped when viewed in file managers and thumbnail tools (eg. gthumb)
  • Loading branch information
mdboom committed Jun 13, 2012
commit b58aa94160ea98bde97edb6ec0d17a905760162b
12 changes: 10 additions & 2 deletions lib/matplotlib/testing/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@
]

#-----------------------------------------------------------------------

def make_test_filename(fname, purpose):
"""
Make a new filename by inserting `purpose` before the file's
extension.
"""
base, ext = os.path.splitext(fname)
return '%s-%s%s' % (base, purpose, ext)

def compare_float( expected, actual, relTol = None, absTol = None ):
"""Fail if the floating point values are not close enough, with
the givem message.
Expand Down Expand Up @@ -232,8 +241,7 @@ def compare_images( expected, actual, tol, in_decorator=False ):
rms += np.sum(np.power((h1h-h2h), 2))
rms = np.sqrt(rms / (256 * 3))

diff_image = os.path.join(os.path.dirname(actual),
'failed-diff-'+os.path.basename(actual))
diff_image = make_test_filename(actual, 'failed-diff')

if ( (rms / 10000.0) <= tol ):
if os.path.exists(diff_image):
Expand Down
9 changes: 6 additions & 3 deletions lib/matplotlib/testing/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from matplotlib import pyplot as plt
from matplotlib import ft2font
import numpy as np
from matplotlib.testing.compare import comparable_formats, compare_images
from matplotlib.testing.compare import comparable_formats, compare_images, \
make_test_filename
import warnings

def knownfailureif(fail_condition, msg=None, known_exception_class=None ):
Expand Down Expand Up @@ -114,7 +115,8 @@ def test(self):
orig_expected_fname = os.path.join(baseline_dir, baseline) + '.' + extension
if extension == 'eps' and not os.path.exists(orig_expected_fname):
orig_expected_fname = os.path.join(baseline_dir, baseline) + '.pdf'
expected_fname = os.path.join(result_dir, 'expected-' + os.path.basename(orig_expected_fname))
expected_fname = make_test_filename(os.path.join(
result_dir, os.path.basename(orig_expected_fname)), 'expected')
actual_fname = os.path.join(result_dir, baseline) + '.' + extension
if os.path.exists(orig_expected_fname):
shutil.copyfile(orig_expected_fname, expected_fname)
Expand All @@ -128,7 +130,8 @@ def test(self):
def do_test():
figure.savefig(actual_fname)

err = compare_images(expected_fname, actual_fname, self._tol, in_decorator=True)
err = compare_images(expected_fname, actual_fname,
self._tol, in_decorator=True)

try:
if not os.path.exists(expected_fname):
Expand Down