Merge branch 'test_support'

* test_support:
  Have montage just do failures and pass them via temp file to allow many at once.
  Add a test for the Ss curve fix
This commit is contained in:
Christopher Kohnert 2017-06-09 13:30:25 -07:00
commit 12b1103d77
2 changed files with 49 additions and 27 deletions

5
test/test-s-curve.svg Normal file
View File

@ -0,0 +1,5 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
<desc>A test that uses s curve for part of the shape.</desc>
<path d="M0 0h512v512H0z"/>
<path fill="#fff" d="M119.436 36c-16.126 0-29.2 17.237-29.2 38.5v363c0 21.263 13.074 38.5 29.2 38.5h275.298c16.126 0 29.198-17.237 29.198-38.5v-363c0-21.263-13.072-38.5-29.198-38.5H119.436zm26.654 8.047s46.338 33.838 47.271 63.068c.776 24.287-25.024 32.122-40.775 18.586l13.633 32.653h-40.117l13.613-32.635c-15.535 13.88-40.006 5.349-40.758-18.604-.88-28.01 47.133-63.068 47.133-63.068zm95.646 120.957h7.963l63.121 160.834c2.536 6.498 7.727 9.748 15.573 9.748h5.468v8.916h-70.134v-8.916h5.587c7.291 0 12.442-.792 15.454-2.377 2.06-1.11 3.09-2.813 3.09-5.111 0-1.347-.278-2.774-.833-4.28l-14.62-37.326h-69.423l-8.2 21.397c-2.14 5.706-3.21 10.222-3.21 13.55 0 3.884 1.782 7.213 5.348 9.987 3.645 2.774 8.916 4.16 15.81 4.16h5.944v8.916h-63.715v-8.916c6.815 0 12.204-1.466 16.166-4.399 3.962-3.011 7.61-8.676 10.938-16.998l59.673-149.185zm-3.447 33.879l-31.502 78.338h62.17l-30.668-78.338zm107.49 154.765h40.116l-13.633 32.653c15.75-13.536 41.551-5.701 40.775 18.586-.933 29.23-47.27 63.068-47.27 63.068s-48.011-35.058-47.132-63.068c.751-23.953 25.222-32.485 40.758-18.604l-13.614-32.635z"/>
</svg>

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -3,6 +3,7 @@ import os
import re
import sys
import codecs
import tempfile
from subprocess import Popen, PIPE, call
@ -15,24 +16,31 @@ class Runner:
def __init__(self):
pass
def add_fail(self, path, msg):
print("FAIL \"%s\" %s" % (path, msg))
self.fail_count += 1
if self.stop_on_fail:
sys.exit(1)
return False
def add_pass(self, input_path, msg, out_path=None, render_path=None, diff_path=None):
return self.add_result(True, input_path, msg, out_path, render_path, diff_path)
def add_pass(self, path, msg):
self.pass_count += 1
print("PASS \"%s\" %s" % (path, msg))
return True
def add_fail(self, input_path, msg, out_path=None, render_path=None, diff_path=None):
return self.add_result(False, input_path, msg, out_path, render_path, diff_path)
def add_result(self, passed, input_path, msg, out_path=None, render_path=None, diff_path=None):
if passed:
self.pass_count += 1
print("PASS \"%s\" %s" % (input_path, msg))
else:
self.fail_count += 1
print("FAIL \"%s\" %s" % (input_path, msg))
if self.stop_on_fail:
sys.exit(1)
def add_output(self, out_path, render_path, diff_path):
self.results.append({
'pass': passed,
'in': input_path,
'out': out_path,
'render': render_path,
'diff': diff_path})
return passed
def get_outputs(self, key):
ret = []
for e in self.results:
@ -88,28 +96,31 @@ def test_svg(path, args, runner):
p = Popen(["compare -fuzz %f%% -metric AE \"%s\" \"%s\" \"%s\"" % (args.fuzz, path, render_path, diff_path)],
stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True)
output, err = p.communicate("")
passed = False
if p.returncode == 1:
runner.add_output(sdf_path, render_path, diff_path)
# Ran successfully, but they are different. Let's parse the output and check the actual error metric.
match = re.match(r'^(\d+)$', err)
passed = False
if match:
try:
pixels = int(match.group(1))
e = float(pixels) / total_pixels * 100.0
if e > args.fail_threshold:
return runner.add_fail(path, "Error = %.3f %% (%d)" % (e, pixels))
msg = "Error = %.3f %% (%d)" % (e, pixels)
else:
return runner.add_pass(path, "OK = %.3f %% (%d)" % (e, pixels))
passed = True
msg = "OK = %.3f %% (%d)" % (e, pixels)
except ValueError:
return runner.add_fail(path, "(Unknown) Error metric = %s" % err)
msg = "(Unknown) Error metric = %s" % err
else:
return runner.add_fail(path, "(Unknown) Error metric = %s" % err)
msg = "(Unknown) Error metric = %s" % err
elif p.returncode != 0:
return runner.add_fail(path, "Error comparing to %s [%d]: %s" % (render_path, p.returncode, err))
msg = "Error comparing to %s [%d]: %s" % (render_path, p.returncode, err)
else:
passed = True
msg = "Identical"
runner.add_output(sdf_path, render_path, diff_path)
return runner.add_pass(path, output)
return runner.add_result(passed, path, msg, sdf_path, render_path, diff_path)
def main():
@ -146,7 +157,7 @@ def main():
help="Use legacy <Version> mode algorithm",
default='0')
parser.add_argument("--montage",
help="Generate montage image(s) for results",
help="Generate montage image of failed results (diffs)",
default=False,
action='store_true')
parser.add_argument("--stop-on-fail",
@ -183,13 +194,19 @@ def main():
if args.montage:
# We keep the diff montage at actual size (we want to see details)
call(["montage -geometry +1+1 %s montage-%s-%s-diff.png" %
(" ".join(runner.get_outputs('diff')), args.mode, args.legacy)], shell=True)
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
temp_file.write("\n".join(runner.get_outputs('diff')))
temp_file.close()
montage_name = "montage-%s-%s-diff.png" % (args.mode, args.legacy)
call(["montage -geometry +1+1 @%s %s" % (temp_file.name, montage_name)], shell=True)
os.unlink(temp_file.name)
# print("Wrote: %s" % montage_name)
# The others, we can let IM do some resizing because it's really just for quick glances.
call(["montage %s montage-%s-%s-out.png" %
(" ".join(runner.get_outputs('out')), args.mode, args.legacy)], shell=True)
call(["montage %s montage-%s-%s-render.png" %
(" ".join(runner.get_outputs('render')), args.mode, args.legacy)], shell=True)
# call(["montage %s montage-%s-%s-out.png" %
# (" ".join(runner.get_outputs('out')), args.mode, args.legacy)], shell=True)
# call(["montage %s montage-%s-%s-render.png" %
# (" ".join(runner.get_outputs('render')), args.mode, args.legacy)], shell=True)
if runner.fail_count > 0:
sys.exit(1)