summaryrefslogtreecommitdiff
path: root/tests/test_cmdline_tool.py
diff options
context:
space:
mode:
authorDon Bright <hugh.m.bright@gmail.com>2011-09-22 01:11:01 (GMT)
committerDon Bright <hugh.m.bright@gmail.com>2011-09-22 01:11:01 (GMT)
commita2e093c2f1a0d91072c8d5f85567a4a9f565f230 (patch)
tree1d5674c0e4588c0c2a1e2553d07a303377dfa8f1 /tests/test_cmdline_tool.py
parentccc88b0c433e9d66ea24dfd26ad6e835196acca5 (diff)
separate throwntogethertest and opencsgtest
create 'expected' images for throwntogethertest create imgdiff_fail html file generation
Diffstat (limited to 'tests/test_cmdline_tool.py')
-rwxr-xr-xtests/test_cmdline_tool.py57
1 files changed, 56 insertions, 1 deletions
diff --git a/tests/test_cmdline_tool.py b/tests/test_cmdline_tool.py
index 07afcc8..7d7f23c 100755
--- a/tests/test_cmdline_tool.py
+++ b/tests/test_cmdline_tool.py
@@ -24,6 +24,8 @@ import glob
import subprocess
import re
import getopt
+import shutil
+import platform
def initialize_environment():
if not options.generate: options.generate = bool(os.getenv("TEST_GENERATE"))
@@ -67,12 +69,56 @@ def compare_default(resultfilename):
return False
return True
+def append_html_output(expectedfilename, resultfilename):
+ # if html directory & file not there, create them
+ # copy expected filename and result filename to dir
+ # append html to show differences
+ # dump platform.platform()
+ expectedimg = os.path.basename(expectedfilename)
+ resultimg = os.path.basename(resultfilename)
+ template = '''
+<p>
+<div style="border:1px solid gray;padding:10px;">
+Test command: <b>///TESTCMD///</b> Test name: <b>///TESTNAME///</b> <br/>
+ <div style="float: left; width: 50%;">
+ &nbsp;<br/>
+ Expected:<br/>
+ <img style="border:1px solid gray; width:90%;" src="///EXPECTED///"/>
+ </div>
+
+ <div style="float: right; width: 50%;">
+ Actual:<br/>
+ (Platform: ///PLATFORM///)<br/>
+ <img style="border:1px solid gray; width:90%;" src="///RESULT///"/>
+ </div>
+<br style="clear:both;"/>
+</div>
+<p>
+'''
+ html = template
+ html = html.replace('///EXPECTED///',expectedimg)
+ html = html.replace('///RESULT///',resultimg)
+ html = html.replace('///TESTCMD///',os.path.basename(options.cmd))
+ html = html.replace('///TESTNAME///',options.testname)
+ html = html.replace('///PLATFORM///',platform.platform())
+ try:
+ shutil.copy(expectedfilename,options.imgdiff_dir)
+ shutil.copy(resultfilename,options.imgdiff_dir)
+ f = open(options.imgdiff_htmlfile,'a')
+ f.write(html)
+ f.close()
+ print >> sys.stderr, "appended " + options.imgdiff_htmlfile
+ except:
+ print >> sys.stderr, "error appending " + options.imgdiff_htmlfile
+ print >> sys.stderr, sys.exc_info()
+
def compare_png(resultfilename):
if not resultfilename:
print >> sys.stderr, "Error: OpenSCAD did not generate an image"
return False
print >> sys.stderr, 'Yee image compare: ', expectedfilename, ' ', resultfilename
if execute_and_redirect("./yee_compare", [expectedfilename, resultfilename], sys.stderr) != 0:
+ append_html_output(expectedfilename, resultfilename)
return False
return True
@@ -138,6 +184,15 @@ if __name__ == '__main__':
options.regressiondir = os.path.join(os.path.split(sys.argv[0])[0], "regression")
options.generate = False
options.suffix = "txt"
+
+ options.imgdiff_dir = 'imgdiff-fail'
+ options.imgdiff_htmlfile = os.path.join(options.imgdiff_dir,'failed.html')
+ try:
+ if not os.path.isdir(options.imgdiff_dir):
+ os.mkdir(options.imgdiff_dir)
+ except:
+ print >> sys.stderr, "error creating " + options.imgdiff_dir, sys.exc_info()
+
for o, a in opts:
if o in ("-g", "--generate"): options.generate = True
elif o in ("-s", "--suffix"):
@@ -145,7 +200,7 @@ if __name__ == '__main__':
else: options.suffix = a
elif o in ("-t", "--test"):
options.testname = a
-
+
# <cmdline-tool> and <argument>
if len(args) < 2:
usage()
contact: Jan Huwald // Impressum