Skip to content

Commit 8d7601d

Browse files
committed
made testing script more robust again
1 parent 78f21a1 commit 8d7601d

1 file changed

Lines changed: 48 additions & 38 deletions

File tree

‎v3/tests/frontend-tests/opt_frontend_golden_test.py‎

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -56,57 +56,67 @@ def png_files_differ(f1, f2):
5656
# fuzzy image comparison using ImageMagick
5757
# see: http://www.imagemagick.org/Usage/compare/
5858
# compare -metric AE -fuzz 1% aliasing.txt.step.2.png.regular.png ../golden-files/regular/aliasing.txt.step.3.png -compose src -highlight-color White -lowlight-color Black cmp.png
59+
DIFF_PNG = '/tmp/diff.png'
5960
def png_files_differ(f1, f2):
61+
6062
# adjust fuzz to a higher percentage if it's not sensitive enough
6163
# /tmp/diff.png shows pixel differences,
6264
# and the number of differed pixels is sent to stderr
6365
cmdline = ['compare', '-metric', 'AE', '-fuzz', '3%',
6466
f1, f2,
6567
'-compose', 'src', '-highlight-color', 'White',
66-
'-lowlight-color', 'Black', '/tmp/diff.png']
68+
'-lowlight-color', 'Black', DIFF_PNG]
6769
(stdout, stderr) = Popen(cmdline, stdout=PIPE, stderr=PIPE).communicate()
6870
assert stderr
69-
num_pixels_diff = int(stderr)
70-
return num_pixels_diff != 0
71+
if 'image widths or heights differ' in stderr:
72+
if os.path.isfile(DIFF_PNG):
73+
os.remove(DIFF_PNG)
74+
return True
75+
else:
76+
num_pixels_diff = int(stderr)
77+
return num_pixels_diff != 0
7178

7279

7380
def run_test(input_filename, clobber_golden=False):
74-
print 'Testing', input_filename
75-
bn = os.path.basename(input_filename)
76-
77-
# test all frontend display options
78-
for option in OPTIONS_DICT:
79-
print " " + option
80-
execute(input_filename, option)
81-
82-
output_png_files = [e for e in os.listdir('.') if bn + '.step.' in e]
83-
if not output_png_files:
84-
print " " + RED + "no output .png files, maybe server is down?" + ENDC
85-
86-
87-
for e in output_png_files:
88-
golden_file = 'golden-files/' + option + '/' + e
89-
90-
if os.path.isfile(golden_file):
91-
if png_files_differ(e, golden_file):
92-
print " " + RED + e + " differs, moved to failed-tests/" + ENDC
93-
94-
# save it under a new name in failed-tests/
95-
newname = os.path.splitext(e)[0] + '.' + option + '.png'
96-
os.rename(e, 'failed-tests/' + newname)
97-
# ... and the diff too:
98-
os.rename('/tmp/diff.png',
99-
'failed-tests/' + os.path.splitext(newname)[0] + '.diff.png')
100-
if clobber_golden:
81+
try:
82+
print 'Testing', input_filename
83+
bn = os.path.basename(input_filename)
84+
85+
# test all frontend display options
86+
for option in OPTIONS_DICT:
87+
print " " + option
88+
execute(input_filename, option)
89+
90+
output_png_files = [e for e in os.listdir('.') if bn + '.step.' in e]
91+
if not output_png_files:
92+
print " " + RED + "no output .png files, maybe server is down?" + ENDC
93+
94+
95+
for e in output_png_files:
96+
golden_file = 'golden-files/' + option + '/' + e
97+
98+
if os.path.isfile(golden_file):
99+
if png_files_differ(e, golden_file):
100+
print " " + RED + e + " differs, moved to failed-tests/" + ENDC
101+
102+
# save it under a new name in failed-tests/
103+
newname = os.path.splitext(e)[0] + '.' + option + '.png'
104+
os.rename(e, 'failed-tests/' + newname)
105+
# ... and the diff too, if it exists:
106+
if os.path.isfile(DIFF_PNG):
107+
os.rename(DIFF_PNG, 'failed-tests/' + os.path.splitext(newname)[0] + '.diff.png')
108+
109+
if clobber_golden:
110+
clobber_golden_file(e, golden_file)
111+
else:
101112
clobber_golden_file(e, golden_file)
102-
else:
103-
clobber_golden_file(e, golden_file)
104-
105-
# do a crude cleanup pass at the very end of the test
106-
# to not interfere as much with Dropbox's weird behavior
107-
for e in os.listdir('.'):
108-
if '.step.' in e:
109-
os.remove(e)
113+
114+
finally:
115+
# do a crude cleanup pass at the very end of the test
116+
# to not interfere as much with Dropbox's weird behavior
117+
for e in os.listdir('.'):
118+
if '.step.' in e:
119+
os.remove(e)
110120

111121

112122
def run_all_tests(clobber=False):

0 commit comments

Comments
 (0)