FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Ps tests by mdboom · Pull Request #115 · matplotlib/matplotlib · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .cpp  (1) .pdf  (181) .py  (6) .svg  (181) All 4 file types selected
Deleted files Viewed files
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
  •  
  •  
  •  
31 changes: 25 additions & 6 deletions lib/matplotlib/testing/compare.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,11 @@ def convert(filename):
newname = base + '_' + extension + '.png'
if not os.path.exists(filename):
raise IOError, "'%s' does not exist" % filename
converter[extension](filename, newname)
# Only convert the file if the destination doesn't already exist or
# is out of date.
if (not os.path.exists(newname) or
os.stat(newname).st_mtime < os.stat(filename).st_mtime):
converter[extension](filename, newname)
return newname

verifiers = { }
Expand Down Expand Up @@ -163,6 +167,15 @@ def verify(filename):
verifiers['svg'] = lambda filename: [
'xmllint', '--valid', '--nowarning', '--noout', filename]

def crop_to_same(actual_path, actual_image, expected_path, expected_image):
# clip the images to the same size -- this is useful only when
# comparing eps to pdf
if actual_path[-7:-4] == 'eps' and expected_path[-7:-4] == 'pdf':
aw, ah = actual_image.size
ew, eh = expected_image.size
actual_image = actual_image.crop((aw/2-ew/2, ah/2-eh/2, aw/2+ew/2, ah/2+eh/2))
return actual_image, expected_image

def compare_images( expected, actual, tol, in_decorator=False ):
'''Compare two image files - not the greatest, but fast and good enough.

Expand Down Expand Up @@ -199,12 +212,15 @@ def compare_images( expected, actual, tol, in_decorator=False ):
# Convert the image to png
extension = expected.split('.')[-1]
if extension != 'png':
actual, expected = convert(actual), convert(expected)
actual = convert(actual)
expected = convert(expected)

# open the image files and remove the alpha channel (if it exists)
expectedImage = Image.open( expected ).convert("RGB")
actualImage = Image.open( actual ).convert("RGB")

actualImage, expectedImage = crop_to_same(actual, actualImage, expected, expectedImage)

# normalize the images
expectedImage = ImageOps.autocontrast( expectedImage, 2 )
actualImage = ImageOps.autocontrast( actualImage, 2 )
Expand Down Expand Up @@ -251,10 +267,13 @@ def compare_images( expected, actual, tol, in_decorator=False ):

def save_diff_image( expected, actual, output ):
from PIL import Image
expectedImage = np.array(Image.open( expected ).convert("RGB")).astype(np.float)
actualImage = np.array(Image.open( actual ).convert("RGB")).astype(np.float)
assert expectedImage.ndim==expectedImage.ndim
assert expectedImage.shape==expectedImage.shape
expectedImage = Image.open( expected ).convert("RGB")
actualImage = Image.open( actual ).convert("RGB")
actualImage, expectedImage = crop_to_same(actual, actualImage, expected, expectedImage)
expectedImage = np.array(expectedImage).astype(np.float)
actualImage = np.array(actualImage).astype(np.float)
assert expectedImage.ndim==actualImage.ndim
assert expectedImage.shape==actualImage.shape
absDiffImage = abs(expectedImage-actualImage)
# expand differences in luminance domain
absDiffImage *= 10
Expand Down
9 changes: 6 additions & 3 deletions lib/matplotlib/testing/decorators.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ def test(self):
fail_msg = 'No failure expected'

orig_expected_fname = os.path.join(baseline_dir, baseline) + '.' + extension
expected_fname = os.path.join(result_dir, 'expected-' + 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))
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 @@ -110,11 +112,12 @@ def test(self):
def do_test():
figure.savefig(actual_fname)

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

if not os.path.exists(expected_fname):
raise ImageComparisonFailure(
'image does not exist: %s' % expected_fname)

err = compare_images(expected_fname, actual_fname, self._tol, in_decorator=True)
if err:
raise ImageComparisonFailure(
'images not close: %(actual)s vs. %(expected)s '
Expand Down Expand Up @@ -150,7 +153,7 @@ def image_comparison(baseline_images=None, extensions=None, tol=1e-3):

if extensions is None:
# default extensions to test
extensions = ['png', 'pdf', 'svg']
extensions = ['png', 'pdf', 'svg', 'eps']

def compare_images_decorator(func):
# We want to run the setup function (the actual test function
Expand Down
Binary file not shown.
Loading

Back | FazBrowse Home | New Git URL