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

Skip to content

Commit a1af04f

Browse files
committed
testing: baseline images now in svn. specify image names without '.png'
svn path=/trunk/matplotlib/; revision=7665
1 parent e236826 commit a1af04f

3 files changed

Lines changed: 32 additions & 8 deletions

File tree

lib/matplotlib/testing/decorators.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from matplotlib.testing.noseclasses import KnownFailureTest, \
22
KnownFailureDidNotFailTest, ImageComparisonFailure
3-
import sys
3+
import os, sys
44
import nose
5-
from matplotlib.cbook import get_sample_data
5+
import matplotlib.tests
66
from matplotlib.testing.compare import compare_images
77

88
def knownfailureif(fail_condition, msg=None):
@@ -36,7 +36,7 @@ def failer(*args, **kwargs):
3636
return nose.tools.make_decorator(f)(failer)
3737
return known_fail_decorator
3838

39-
def image_comparison(baseline_images=None, tol=1e-3):
39+
def image_comparison(baseline_images=None):
4040
"""
4141
compare images generated by the test with those specified in
4242
*baseline_images*, which must correspond within tolerance *tol*,
@@ -49,10 +49,22 @@ def image_comparison(baseline_images=None, tol=1e-3):
4949
def compare_images_decorator(func):
5050
def decorated_compare_images(*args,**kwargs):
5151
result = func(*args,**kwargs)
52+
extension = '.png' # TODO: test more backends
5253
for fname in baseline_images:
53-
actual = fname
54-
expected = get_sample_data('test_baseline_%s'%fname,
55-
asfileobj=False)
54+
actual = fname + extension
55+
56+
# compute filename for baseline image
57+
module_name = func.__module__
58+
mods = module_name.split('.')
59+
assert mods.pop(0)=='matplotlib'
60+
assert mods.pop(0)=='tests'
61+
subdir = '/'.join(mods)
62+
basedir = os.path.dirname(matplotlib.tests.__file__)
63+
baseline_dir = os.path.join(basedir,'baseline_images',subdir)
64+
expected = os.path.join(baseline_dir,fname) + extension
65+
66+
# compare the images
67+
tol=1e-3 # default tolerance
5668
err = compare_images( expected, actual, tol,
5769
in_decorator=True )
5870
if err:

lib/matplotlib/tests/test_spines.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from matplotlib.testing.decorators import image_comparison
44
import matplotlib.pyplot as plt
55

6-
@image_comparison(baseline_images=['spines_axes_positions.png'])
6+
@image_comparison(baseline_images=['spines_axes_positions'])
77
def test_spines_axes_positions():
88
# SF bug 2852168
99
fig = plt.figure()
@@ -18,4 +18,4 @@ def test_spines_axes_positions():
1818
ax.xaxis.set_ticks_position('top')
1919
ax.spines['left'].set_color('none')
2020
ax.spines['bottom'].set_color('none')
21-
fig.savefig('spines_axes_positions.png')
21+
fig.savefig('spines_axes_positions')

setup.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,18 @@
101101
'backends/Matplotlib.nib/*',
102102
]}
103103

104+
if 1:
105+
# TODO: exclude these when making release?
106+
baseline_images = glob.glob(os.path.join('lib','matplotlib','tests',
107+
'baseline_images','*','*'))
108+
def chop_package(fname):
109+
badstr = os.path.join('lib','matplotlib','')
110+
assert fname.startswith(badstr)
111+
result = fname[ len(badstr): ]
112+
return result
113+
baseline_images = [chop_package(f) for f in baseline_images]
114+
package_data['matplotlib'].extend(baseline_images)
115+
104116
if not check_for_numpy():
105117
sys.exit(1)
106118

0 commit comments

Comments
 (0)