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

Skip to content

Commit 5e50b90

Browse files
committed
reverting testing/compare.py back to master
1 parent be6af2f commit 5e50b90

File tree

1 file changed

+16
-58
lines changed

1 file changed

+16
-58
lines changed

lib/matplotlib/testing/compare.py

Lines changed: 16 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -83,22 +83,6 @@ def compare_float( expected, actual, relTol = None, absTol = None ):
8383
# convert files with that extension to png format.
8484
converter = { }
8585

86-
def make_external_conversion_command(cmd):
87-
def convert(*args):
88-
cmdline = cmd(*args)
89-
oldname, newname = args
90-
pipe = subprocess.Popen(cmdline, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
91-
stdout, stderr = pipe.communicate()
92-
errcode = pipe.wait()
93-
if not os.path.exists(newname) or errcode:
94-
msg = "Conversion command failed:\n%s\n" % ' '.join(cmd)
95-
if stdout:
96-
msg += "Standard output:\n%s\n" % stdout
97-
if stderr:
98-
msg += "Standard error:\n%s\n" % stderr
99-
raise IOError, msg
100-
return convert
101-
10286
if matplotlib.checkdep_ghostscript() is not None:
10387
# FIXME: make checkdep_ghostscript return the command
10488
if sys.platform == 'win32':
@@ -108,49 +92,13 @@ def convert(*args):
10892
cmd = lambda old, new: \
10993
[gs, '-q', '-sDEVICE=png16m', '-dNOPAUSE', '-dBATCH',
11094
'-sOutputFile=' + new, old]
111-
converter['pdf'] = make_external_conversion_command(cmd)
112-
converter['eps'] = make_external_conversion_command(cmd)
95+
converter['pdf'] = cmd
96+
converter['eps'] = cmd
11397

11498
if matplotlib.checkdep_inkscape() is not None:
115-
class SVGConverter:
116-
def __init__(self):
117-
self._count = 0
118-
self._process = None
119-
120-
def get_process(self):
121-
# Since Inkscape can leak a little memory, we run X
122-
# conversions and then shut it down and start up a new
123-
# Inkscape.
124-
if self._count == 0:
125-
if self._process is not None:
126-
self._process.communicate('quit\n')
127-
self._process = subprocess.Popen(['inkscape', '-z', '--shell'],
128-
stdin=subprocess.PIPE,
129-
stdout=subprocess.PIPE,
130-
stderr=subprocess.STDOUT)
131-
self.read_to_end(self._process.stdout)
132-
self._count = 10
133-
self._count -= 1
134-
return self._process
135-
136-
def __call__(self, old, new):
137-
process = self.get_process()
138-
process.stdin.write('%s --export-png=%s\n' % (old, new))
139-
process.stdin.flush()
140-
self.read_to_end(process.stdout)
141-
142-
def read_to_end(self, buf):
143-
ret = ''
144-
lastchar = ''
145-
while True:
146-
char = buf.readline(1)
147-
if char == '>' and lastchar == '\n':
148-
break
149-
ret += char
150-
lastchar = char
151-
return ret
152-
153-
converter['svg'] = SVGConverter()
99+
cmd = lambda old, new: \
100+
['inkscape', old, '--export-png=' + new]
101+
converter['svg'] = cmd
154102

155103
def comparable_formats():
156104
'''Returns the list of file formats that compare_images can compare
@@ -168,7 +116,17 @@ def convert(filename):
168116
newname = base + '_' + extension + '.png'
169117
if not os.path.exists(filename):
170118
raise IOError, "'%s' does not exist" % filename
171-
converter[extension](filename, newname)
119+
cmd = converter[extension](filename, newname)
120+
pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
121+
stdout, stderr = pipe.communicate()
122+
errcode = pipe.wait()
123+
if not os.path.exists(newname) or errcode:
124+
msg = "Conversion command failed:\n%s\n" % ' '.join(cmd)
125+
if stdout:
126+
msg += "Standard output:\n%s\n" % stdout
127+
if stderr:
128+
msg += "Standard error:\n%s\n" % stderr
129+
raise IOError, msg
172130
return newname
173131

174132
verifiers = { }

0 commit comments

Comments
 (0)