11
11
parser.add_option("-d", "--directory", dest="directory", help="test directory", default=".")
12
12
parser.add_option("-i", "--inkscape", dest="inkscape", help="path to inkscape", default="inkscape")
13
13
parser.add_option("--compare-png", dest="comparepng", help="PNG comparison tool", default="")
14
parser.add_option("--timeout", type="int", dest="timeout", help="Time given to Inkscape to render each file (in seconds)", default=20)
14
15
(options, args) = parser.parse_args()
16
17
timestamp = datetime.utcnow().isoformat();
111
112
executionlog.flush()
112
113
executionlog.write('\n')
115
def executeSilentlyTimed(cmd, timeout):
117
header = 'Executing: %s (timeout after %ds)' % cmd, timeout
118
executionlog.write(header + '\n')
119
executionlog.write(('-' * len(header)) + '\n')
121
proc = subprocess.Popen(cmd, stdout=executionlog, stderr=executionlog, shell=True)
124
while (time.time()-st) < timeout:
126
if proc.poll() is not None:
129
if proc.poll() is None: # timeout was reached, kill the thing
131
executionlog.write('>>> KILLED INKSCAPE PROCESS <<<')
134
result = proc.returncode
136
executionlog.write('\n')
139
def testRenderSVGtoPNG(name, ext):
140
outputName = name + '.png'
141
patchFile = os.path.join(casesDirectory, name + '-patch' + ext)
142
patchOutput = os.path.join(passReferencesDirectory, name + '-patch.png')
143
if os.path.exists(patchFile):
144
if isNewerThan(patchFile,patchOutput):
145
ensureDirectoryExists(os.path.dirname(patchOutput))
146
inkscapeCmd = '%(inkscape)s -e "%(output)s" "%(input)s"' % \
147
{'inkscape': inkscapePath, 'output': patchOutput, 'input': patchFile}
148
print "Rendering patch for %s" % name
149
result = executeSilently(inkscapeCmd)
151
return {'result': 40, 'output': outputName}
152
elif os.path.exists(patchOutput):
153
print "Removing old patch for %s" % name
154
os.remove(patchOutput)
155
output = os.path.join(newDirectory, outputName)
156
ensureDirectoryExists(os.path.split(output)[0])
157
inkscapeCmd = '%(inkscape)s -e "%(output)s" "%(input)s"' % \
158
{'inkscape': inkscapePath, 'output': output, 'input': os.path.join(casesDirectory,name+ext)}
159
# execute inkscapeCmd, but make sure it does not take longer than x seconds
160
result = executeSilentlyTimed(inkscapeCmd, )
161
return {'result': result, 'output': outputName}
114
163
def testRender(name, ext):
115
164
outputName = name+'.png'
116
165
patchFile = os.path.join(casesDirectory, name+'-patch'+ext)
146
195
def extensionOf(tc):
147
196
(path,ext) = os.path.splitext(tc)
149
testHandlers = {'.svg':testRender}
199
testHandlers = {'.svg':testRenderSVGtoPNG}
150
200
resultCodes = {0: 'Pass', 1: 'Fail', 2: 'New', 3: 'No references', \
151
201
10: 'Error', 11: 'Crash', \
152
202
20: 'Syntax error', 21: 'Unable to stat/open file', \
153
203
30: 'Compare error', 31: 'Compare crash',
154
40: 'Error creating reference from patch'}
204
40: 'Error creating reference from patch',
155
206
resultCounts = {}
156
207
for relpath in testCases:
157
208
(name,ext) = os.path.splitext(relpath)