mirror of https://github.com/vitalif/openscad
Implemented rudimentary image compare for OpenCSG regression tests
parent
0340d4e0a1
commit
b9608dd2f8
|
@ -0,0 +1,31 @@
|
|||
#!/bin/sh
|
||||
|
||||
|
||||
while getopts 'v' c
|
||||
do
|
||||
case $c in
|
||||
v) set -x ;;
|
||||
esac
|
||||
done
|
||||
|
||||
shift $(($OPTIND - 1))
|
||||
|
||||
# FIXME: Sometimes, compare fails when comparing very small images (e.g. 40 x 10 pixels).
|
||||
# It's unknown why this happens..
|
||||
pixelerror=`compare -fuzz 10% -metric AE $1 $2 null: 2>&1`
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "General error: Ouch"
|
||||
exit 1 # Compare failed to read image
|
||||
else
|
||||
# Check if $pixelerror contains an integer (it sometimes outputs things like '0 @ 0,0')
|
||||
if [ $pixelerror -eq $pixelerror 2> /dev/null ]; then
|
||||
if [ $pixelerror == 0 ]; then
|
||||
exit 0
|
||||
fi
|
||||
echo "Pixel error: $pixelerror"
|
||||
else
|
||||
echo "Pixel error: Err"
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
exit 0
|
Binary file not shown.
After Width: | Height: | Size: 8.7 KiB |
Binary file not shown.
After Width: | Height: | Size: 8.2 KiB |
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
Binary file not shown.
After Width: | Height: | Size: 8.7 KiB |
|
@ -32,7 +32,7 @@ def initialize_environment():
|
|||
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.join(expecteddir, testname + "-expected." + options.suffix)
|
||||
|
||||
def verify_test(testname, cmd):
|
||||
global expectedfilename
|
||||
|
@ -54,18 +54,28 @@ def get_normalized_text(filename):
|
|||
def compare_text(expected, actual):
|
||||
return get_normalized_text(expected) == get_normalized_text(actual)
|
||||
|
||||
def compare_default(resultfilename):
|
||||
if not compare_text(expectedfilename, resultfilename):
|
||||
execute_and_redirect("diff", [expectedfilename, resultfilename], sys.stderr)
|
||||
return False
|
||||
return True
|
||||
|
||||
def compare_png(resultfilename):
|
||||
if execute_and_redirect("diff", [expectedfilename, resultfilename], sys.stderr) != 0:
|
||||
return False
|
||||
return True
|
||||
|
||||
def compare_with_expected(resultfilename):
|
||||
if not options.generate:
|
||||
if not compare_text(expectedfilename, resultfilename):
|
||||
execute_and_redirect("diff", [expectedfilename, resultfilename], sys.stderr)
|
||||
return False
|
||||
if "compare_" + options.suffix in globals(): return globals()["compare_" + options.suffix](resultfilename)
|
||||
else: return compare_default(resultfilename)
|
||||
return True
|
||||
|
||||
def run_test(testname, cmd, args):
|
||||
cmdname = os.path.split(options.cmd)[1]
|
||||
|
||||
outputdir = os.path.join(os.getcwd(), cmdname + "-output")
|
||||
actualfilename = os.path.join(outputdir, testname + "-actual" + options.suffix)
|
||||
actualfilename = os.path.join(outputdir, testname + "-actual." + options.suffix)
|
||||
|
||||
if options.generate:
|
||||
if not os.path.exists(expecteddir): os.makedirs(expecteddir)
|
||||
|
@ -116,13 +126,12 @@ if __name__ == '__main__':
|
|||
options = Options()
|
||||
options.regressiondir = os.path.join(os.path.split(sys.argv[0])[0], "regression")
|
||||
options.generate = False
|
||||
options.suffix = ".txt"
|
||||
options.suffix = "txt"
|
||||
for o, a in opts:
|
||||
if o in ("-g", "--generate"): options.generate = True
|
||||
elif o in ("-s", "--suffix"):
|
||||
if a[0] == '.': options.suffix = ""
|
||||
else: options.suffix = "."
|
||||
options.suffix += a
|
||||
if a[0] == '.': options.suffix = a[1:]
|
||||
else: options.suffix = a
|
||||
elif o in ("-t", "--test"):
|
||||
options.testname = a
|
||||
|
||||
|
|
Loading…
Reference in New Issue