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

Skip to content

Commit b096a6e

Browse files
committed
Make it not an error if the system does not have gs
svn path=/trunk/matplotlib/; revision=7831
1 parent 8c60d5c commit b096a6e

2 files changed

Lines changed: 29 additions & 6 deletions

File tree

lib/matplotlib/testing/compare.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,21 @@
33
"""
44
#=======================================================================
55

6+
import matplotlib
67
import math
78
import operator
89
import os
910
import numpy as np
1011
import shutil
1112
import subprocess
13+
import sys
1214

1315
#=======================================================================
1416

1517
__all__ = [
1618
'compare_float',
1719
'compare_images',
20+
'comparable_formats',
1821
]
1922

2023
#-----------------------------------------------------------------------
@@ -77,17 +80,32 @@ def compare_float( expected, actual, relTol = None, absTol = None ):
7780
# A dictionary that maps filename extensions to functions that map
7881
# parameters old and new to a list that can be passed to Popen to
7982
# convert files with that extension to png format.
80-
converter = { 'pdf': lambda old, new: \
81-
['gs', '-q', '-sDEVICE=png16m', '-dNOPAUSE', '-dBATCH',
82-
'-sOutputFile=' + new, old],
83-
}
83+
converter = { }
84+
85+
if matplotlib.checkdep_ghostscript() is not None:
86+
# FIXME: make checkdep_ghostscript return the command
87+
if sys.platform == 'win32':
88+
gs = 'gswin32c'
89+
else:
90+
gs = 'gs'
91+
cmd = lambda old, new: \
92+
[gs, '-q', '-sDEVICE=png16m', '-dNOPAUSE', '-dBATCH',
93+
'-sOutputFile=' + new, old]
94+
converter['pdf'] = cmd
95+
converter['eps'] = cmd
96+
97+
def comparable_formats():
98+
'''Returns the list of file formats that compare_images can compare
99+
on this system.'''
100+
return ['png'] + converter.keys()
101+
84102
def convert(filename):
85103
'''Convert the named file into a png file.
86104
Returns the name of the created file.
87105
'''
88106
base, extension = filename.rsplit('.', 1)
89107
if extension not in converter:
90-
raise KeyError, "Don't know how to convert %s files to png" % extension
108+
raise NotImplementedError, "Don't know how to convert %s files to png" % extension
91109
newname = base + '_' + extension + '.png'
92110
cmd = converter[extension](filename, newname)
93111
pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

lib/matplotlib/testing/decorators.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import nose
55
import matplotlib
66
import matplotlib.tests
7-
from matplotlib.testing.compare import compare_images
7+
from matplotlib.testing.compare import comparable_formats, compare_images
88

99
def knownfailureif(fail_condition, msg=None):
1010
"""
@@ -88,6 +88,11 @@ def decorated_compare_images(*args,**kwargs):
8888
for fname in baseline_images:
8989
actual = os.path.join(result_dir, fname) + '.' + extension
9090
expected = os.path.join(baseline_dir,fname) + '.' + extension
91+
if (extension not in comparable_formats()
92+
or not os.path.exists(expected)):
93+
# FIXME: Should it be a known fail if this format
94+
# cannot be compared in this environment?
95+
continue
9196

9297
# compare the images
9398
tol=1e-3 # default tolerance

0 commit comments

Comments
 (0)