diff options
Diffstat (limited to 'tests/test_cmdline_tool.py')
-rwxr-xr-x | tests/test_cmdline_tool.py | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/tests/test_cmdline_tool.py b/tests/test_cmdline_tool.py index 8b49f78..ebe802e 100755 --- a/tests/test_cmdline_tool.py +++ b/tests/test_cmdline_tool.py @@ -35,6 +35,7 @@ def init_expected_filename(testname, cmd): global expecteddir, expectedfilename expecteddir = os.path.join(options.regressiondir, os.path.split(cmd)[1]) expectedfilename = os.path.join(expecteddir, testname + "-expected." + options.suffix) + expectedfilename = os.path.normpath( expectedfilename ) def verify_test(testname, cmd): global expectedfilename @@ -66,32 +67,38 @@ def compare_text(expected, actual): return get_normalized_text(expected) == get_normalized_text(actual) def compare_default(resultfilename): + print >> sys.stderr, 'diff text compare: ' + print >> sys.stderr, ' expected textfile: ', expectedfilename + print >> sys.stderr, ' actual textfile: ', resultfilename if not compare_text(expectedfilename, resultfilename): execute_and_redirect("diff", [expectedfilename, resultfilename], sys.stderr) return False return True def compare_png(resultfilename): + #args = [expectedfilename, resultfilename, "-alpha", "Off", "-compose", "difference", "-composite", "-threshold", "10%", "-blur", "2", "-threshold", "30%", "-format", "%[fx:w*h*mean]", "info:"] + #args = [expectedfilename, resultfilename, "-alpha", "Off", "-compose", "difference", "-composite", "-threshold", "10%", "-morphology", "Erode", "Square", "-format", "%[fx:w*h*mean]", "info:"] + # 'morphology' is only available in newer versions of ImageMagick. + # http://www.imagemagick.org/Usage/morphology/#alturnative + args = [expectedfilename, resultfilename, "-alpha", "Off", + "-compose", "difference", "-composite", "-threshold", "10%", + #"-morphology", "Erode", "Square", + "-gaussian-blur","3x65535", "-threshold","99.999%", + "-format", "%[fx:w*h*mean]", "info:"] + print >> sys.stderr, 'ImageMagick image comparison: convert ', ' '.join(args[2:]) + print >> sys.stderr, ' expected image: ', expectedfilename if not resultfilename: - print >> sys.stderr, "Error: OpenSCAD did not generate an image" + print >> sys.stderr, "Error: OpenSCAD did not generate an image to test" return False + print >> sys.stderr, ' actual image: ', resultfilename -# args = [expectedfilename, resultfilename, "-alpha", "Off", "-compose", "difference", "-composite", "-threshold", "10%", "-blur", "2", "-threshold", "30%", "-format", "%[fx:w*h*mean]", "info:"] - args = [expectedfilename, resultfilename, "-alpha", "Off", "-compose", "difference", "-composite", "-threshold", "10%", "-morphology", "Erode", "Square", "-format", "%[fx:w*h*mean]", "info:"] - print >> sys.stderr, 'convert ', ' '.join(args) - (retval, output) = execute_and_redirect("convert", args, subprocess.PIPE) + (retval, output) = execute_and_redirect(options.convert_exec, args, subprocess.PIPE) if retval == 0: pixelerr = int(float(output.strip())) if pixelerr < 32: return True else: print >> sys.stderr, pixelerr, ' pixel errors' return False -# Old compare solution, based on yee_compare -# print >> sys.stderr, 'Yee image compare: ', expectedfilename, ' ', resultfilename -# if execute_and_redirect("./yee_compare", [expectedfilename, resultfilename, "-downsample", "1", "-threshold", "150"], sys.stderr) != 0: -# return False -# return True - def compare_with_expected(resultfilename): if not options.generate: if "compare_" + options.suffix in globals(): return globals()["compare_" + options.suffix](resultfilename) @@ -143,11 +150,12 @@ def usage(): print >> sys.stderr, " -g, --generate Generate expected output for the given tests" print >> sys.stderr, " -s, --suffix=<suffix> Write -expected and -actual files with the given suffix instead of .txt" print >> sys.stderr, " -t, --test=<name> Specify test name instead of deducting it from the argument" + print >> sys.stderr, " -c, --convexec=<name> Path to ImageMagick 'convert' executable" if __name__ == '__main__': # Handle command-line arguments try: - opts, args = getopt.getopt(sys.argv[1:], "gs:t:", ["generate", "suffix=", "test="]) + opts, args = getopt.getopt(sys.argv[1:], "gs:c:t:", ["generate", "convexec=", "suffix=", "test="]) except getopt.GetoptError, err: usage() sys.exit(2) @@ -165,6 +173,8 @@ if __name__ == '__main__': else: options.suffix = a elif o in ("-t", "--test"): options.testname = a + elif o in ("-c", "--convexec"): + options.convert_exec = os.path.normpath( a ) # <cmdline-tool> and <argument> if len(args) < 2: |