11from matplotlib .testing .noseclasses import KnownFailureTest , \
22 KnownFailureDidNotFailTest , ImageComparisonFailure
3- import sys
3+ import os , sys
44import nose
5- from matplotlib .cbook import get_sample_data
5+ import matplotlib .tests
66from matplotlib .testing .compare import compare_images
77
88def 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 :
0 commit comments