summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDon Bright <hugh.m.bright@gmail.com>2013-02-19 03:36:00 (GMT)
committerDon Bright <hugh.m.bright@gmail.com>2013-02-19 03:36:00 (GMT)
commit85d3f3c7c9b165da519d9b4377a1fbd3281f6b14 (patch)
treeb011c366fc5f80d79c032634e768c6e9cb2235bf /tests
parent21e3928854c7f0245ae637c87bea210a1afc4301 (diff)
report is now single monolithic html file using data_uri encoding.
Diffstat (limited to 'tests')
-rwxr-xr-xtests/test_pretty_print.py119
-rwxr-xr-xtests/test_upload.py20
2 files changed, 97 insertions, 42 deletions
diff --git a/tests/test_pretty_print.py b/tests/test_pretty_print.py
index a85d000..8458fdb 100755
--- a/tests/test_pretty_print.py
+++ b/tests/test_pretty_print.py
@@ -5,27 +5,33 @@
# the file named 'COPYING' in OpenSCAD's project root.
#
-# This program 'pretty prints' the ctest output, namely
-# files from builddir/Testing/Temporary.
-# html & wiki output are produced in Testing/Temporary/sysid_report
+# This program 'pretty prints' the ctest output, including
+# - log files from builddir/Testing/Temporary/
+# - .png and .txt files from testname-output/*
#
+# The result is a single html report file with images data-uri encoded
+# into the file. It can be uploaded as a single static file to a web server
+# or the 'test_upload.py' script can be used.
-# Note: Wiki code is deprecated. All future development should move to
-# create html output (or even xml output). Wiki design was based on the
-# wrong assumption of easily accessible public wiki servers with
-# auto-upload scripts available.
# Design philosophy
#
# 1. parse the data (images, logs) into easy-to-use data structures
# 2. wikifiy the data
# 3. save the wikified data to disk
-# 4. save html
-# 5. upload html to public site
+# 4. generate html, including base64 encoding of images
+# 5. save html file
+# 6. upload html to public site and share with others
-#
# todo
-# why is hash differing
+#
+# 1. Note: Wiki code is deprecated. All future development should move to
+# create html output (or even xml output). Wiki design was based on the
+# wrong assumption of easily accessible public wiki servers with
+# auto-upload scripts available. wiki code should be removed and code
+# simplified.
+#
+# 2. why is hash differing
import string,sys,re,os,hashlib,subprocess,textwrap,time,platform
@@ -35,20 +41,24 @@ def tryread(filename):
f = open(filename,'rb')
data = f.read()
f.close()
- except:
+ except Exception, e:
print 'couldn\'t open ',filename
+ print type(e), e
return data
def trysave(filename,data):
+ dir = os.path.dirname(filename)
try:
- if not os.path.isdir(os.path.dirname(filename)):
- #print 'creating',os.path.dirname(filename)
- os.mkdir(os.path.dirname(filename))
+ if not os.path.isdir(dir):
+ if not dir == '':
+ debug( 'creating' + dir)
+ os.mkdir(dir)
f=open(filename,'wb')
f.write(data)
f.close()
- except:
+ except Exception, e:
print 'problem writing to',filename
+ print type(e), e
return None
return True
@@ -119,7 +129,7 @@ class Test:
self.type, self.actualfile, self.expectedfile, self.scadfile = \
type, actualfile, expectedfile, scadfile
self.fulltestlog = log
-
+
def __str__(self):
x = 'fullname: ' + self.fullname
x+= '\nactualfile: ' + self.actualfile
@@ -297,6 +307,19 @@ TESTLOG
return imgs, txtpages
+def png_encode64( fname, width=250 ):
+ # en.wikipedia.org/wiki/Data_URI_scheme
+ f = open( fname, "rb" )
+ data = f.read()
+ data_uri = data.encode("base64").replace("\n","")
+ tag = '<img'
+ tag += ' src="data:image/png;base64,'
+ tag += data_uri + '"'
+ tag += ' width="'+str(width)+'"'
+ tag += ' alt="openscad_test_image"'
+ tag += ' />\n'
+ return tag
+
def tohtml(wiki_rootpath, startdate, tests, enddate, sysinfo, sysid, makefiles):
# kludge. assume wiki stuff has alreayd run and dumped files properly
head = '<html><head><title>'+wiki_rootpath+' test run for '+sysid +'</title></head><body>'
@@ -312,9 +335,10 @@ def tohtml(wiki_rootpath, startdate, tests, enddate, sysinfo, sysid, makefiles):
s=''
- s+= '\n<pre>'
- s+= '\nSYSINFO\n'+ sysinfo
- s+= '\n</pre><p>'
+ s+= '\n<h3>'
+ s+= '\nSystem info\n'
+ s+= '\n</h3><p>'
+ s+= '<pre>'+sysinfo+'</pre>\n'
s+= '\n<pre>'
s+= '\nSTARTDATE: '+ startdate
@@ -326,6 +350,9 @@ def tohtml(wiki_rootpath, startdate, tests, enddate, sysinfo, sysid, makefiles):
s+= '\nPERCENTPASSED: '+ percent
s+= '\n</pre>'
+ if not include_passed:
+ s+= '<h3>Failed tests:</h3>\n'
+
for t in tests_to_report:
if t.type=='txt':
s+='\n<pre>'+t.fullname+'</pre>\n'
@@ -335,22 +362,34 @@ def tohtml(wiki_rootpath, startdate, tests, enddate, sysinfo, sysid, makefiles):
wikiname_a = wikify_filename(tmp,wiki_rootpath,sysid)
tmp = t.expectedfile.replace(os.path.dirname(builddir),'')
wikiname_e = wikify_filename(tmp,wiki_rootpath,sysid)
+ # imgtag_e = <img src='+wikiname_e+' width=250/>'
+ # imatag_a = <img src='+wikiname_a+' width=250/>'
+ imgtag_e = png_encode64( t.expectedfile, 250 )
+ imgtag_a = png_encode64( t.actualfile, 250 )
s+='<table>'
s+='\n<tr><td colspan=2>'+t.fullname
s+='\n<tr><td>Expected<td>Actual'
- s+='\n<tr><td><img src='+wikiname_e+' width=250/>'
- s+='\n <td><img src='+wikiname_a+' width=250/>'
+ s+='\n<tr><td>' + imgtag_e + '</td>'
+ s+='\n <td>' + imgtag_a + '</td>'
s+='\n</table>'
s+='\n<pre>'
s+=t.fulltestlog
s+='\n</pre>'
s+='\n\n<p>\n\n'
+
+ s+= '<h3> CMake .build files </h3>\n'
+ s+= '\n<pre>'
makefiles_wikinames = {}
for mf in sorted(makefiles.keys()):
+ mfname = mf.strip().lstrip(os.path.sep)
+ text = open(os.path.join(builddir,mfname)).read()
+ s+= '</pre><h4>'+mfname+'</h4><pre>'
+ s+= text
tmp = mf.replace('CMakeFiles','').replace('.dir','')
wikiname = wikify_filename(tmp,wiki_rootpath,sysid)
- s += '\n<a href='+wikiname+'>'+wikiname+'</a><br>'
+ # s += '\n<a href='+wikiname+'>'+wikiname+'</a><br>'
+ s+= '\n</pre>'
s+='\n'
return head + s + tail
@@ -437,14 +476,22 @@ def findlogfile(builddir):
sys.exit()
return logpath, logfilename
+def debug(x):
+ if debug_test_pp: print 'test_pretty_print: '+x
+
+debug_test_pp=False
+builddir=os.getcwd()
+
def main():
#wikisite = 'cakebaby.referata.com'
#wiki_api_path = ''
+ global wikisite, wiki_api_path, wiki_rootpath, builddir, debug_test_pp
+ global maxretry, dry, include_passed
+
wikisite = 'cakebaby.wikia.com'
wiki_api_path = '/'
wiki_rootpath = 'OpenSCAD'
- builddir = os.getcwd() # os.getcwd()+'/build'
- verbose = False
+ if '--debug' in string.join(sys.argv): debug_test_pp=True
maxretry = 10
if bool(os.getenv("TEST_GENERATE")): sys.exit(0)
@@ -453,19 +500,19 @@ def main():
if '--include-passed' in sys.argv: include_passed = True
dry = False
- if verbose: print 'running test_pretty_print'
+ debug( 'running test_pretty_print' )
if '--dryrun' in sys.argv: dry=True
suffix = ezsearch('--suffix=(.*?) ',string.join(sys.argv)+' ')
builddir = ezsearch('--builddir=(.*?) ',string.join(sys.argv)+' ')
if builddir=='': builddir=os.getcwd()
- if verbose: print 'build dir set to', builddir
+ debug( 'build dir set to ' + builddir )
sysinfo, sysid = read_sysinfo(os.path.join(builddir,'sysinfo.txt'))
makefiles = load_makefiles(builddir)
logpath, logfilename = findlogfile(builddir)
testlog = tryread(logfilename)
startdate, tests, enddate = parselog(testlog)
- if verbose:
+ if debug_test_pp:
print 'found sysinfo.txt,',
print 'found', len(makefiles),'makefiles,',
print 'found', len(tests),'test results'
@@ -473,22 +520,30 @@ def main():
imgs, txtpages = towiki(wiki_rootpath, startdate, tests, enddate, sysinfo, sysid, makefiles)
wikidir = os.path.join(logpath,sysid+'_report')
- if verbose: print 'erasing files in',wikidir
+ debug( 'erasing files in ' + wikidir )
try: map(lambda x:os.remove(os.path.join(wikidir,x)), os.listdir(wikidir))
except: pass
- print 'writing',len(imgs),'images, ',len(txtpages)-1,'text pages, and index.html to:\n', ' .'+wikidir.replace(os.getcwd(),'')
+ debug( 'output dir:\n' + wikidir.replace(os.getcwd(),'') )
+ debug( 'writing ' + str(len(imgs)) + ' images' )
+ debug( 'writing ' + str(len(txtpages)-1) + ' text pages' )
+ debug( 'writing index.html ' )
for pgname in sorted(imgs): trysave( os.path.join(wikidir,pgname), imgs[pgname])
for pgname in sorted(txtpages): trysave( os.path.join(wikidir,pgname), txtpages[pgname])
htmldata = tohtml(wiki_rootpath, startdate, tests, enddate, sysinfo, sysid, makefiles)
- trysave( os.path.join(wikidir,'index.html'), htmldata )
+ html_basename = sysid+'_report.html'
+ html_filename = os.path.join(builddir,'Testing','Temporary',html_basename)
+ debug('saving ' +html_filename + ' ' + str(len(htmldata)) + ' bytes')
+ trysave( html_filename, htmldata )
+ print "report saved:", html_filename.replace(os.getcwd()+os.path.sep,'')
if '--wiki-upload' in sys.argv:
+ print "wiki upload is deprecated."
upload(wikisite,wiki_api_path,wiki_rootpath,sysid,'openscadbot',
'tobdacsnepo',wikidir,dryrun=dry)
print 'upload attempt complete'
- if verbose: print 'test_pretty_print complete'
+ debug( 'test_pretty_print complete' )
if __name__=='__main__':
main()
diff --git a/tests/test_upload.py b/tests/test_upload.py
index 2e634f1..817d971 100755
--- a/tests/test_upload.py
+++ b/tests/test_upload.py
@@ -88,7 +88,7 @@ usage:
example1:
- $ ctest # result is Testing/Temporary/linux_x86_nvidia_report.html
+ $ ctest # result is linux_x86_nvidia_report.html
$ test_upload.py --username=andreis --host=web.sourceforge.net \
--remotepath=/home/project-web/projectxyz/htdocs/
$ firefox http://projectxyz.sourceforge.net/openscad_tests/index.html
@@ -96,7 +96,7 @@ example1:
example2:
- $ ctest # result in Testing/Temporary/freebsd_ppc_gallium_report.html
+ $ ctest # result in freebsd_ppc_gallium_report.html
$ test_upload.py --username=agorenko --host=fontanka.org --remotepath=/tmp/
$ ssh agorenko@fontanka.org "ls /tmp"
# result is 'index.html' 'freebsd_ppc_gallium_report.html'
@@ -174,19 +174,19 @@ def paramiko_upload( newrept_fname, username, host, remotepath ):
debug("upload local report file to remote file:")
debug(" local:"+newrept_fname)
- debug("remote:"+os.path.join(ftp.getcwd(),newrept_basefname))
-
localf = open( newrept_fname, 'r' )
rept_text = localf.read()
localf.close()
+ debug(" bytes read:"+str(len(rept_text)))
+ debug("remote:"+os.path.join(ftp.getcwd(),newrept_basefname))
f = ftp.file( newrept_basefname, 'w+' )
f.write( rept_text )
f.close()
bytecount += len(rept_text)
- debug( "update index.html (or create blank) ")
+ debug( "file uploaded. now, update index.html (or create blank) ")
if not 'index.html' in ftp.listdir():
f = ftp.file( 'index.html', 'w+')
@@ -266,19 +266,19 @@ def main():
print "unable to find valid system id"
sys.exit(1)
- sysidpath = sysid + '_report' + '.html'
- testdir = os.path.join(builddir, 'Testing', 'Temporary', sysidpath )
- debug("testdir:\n" + testdir )
+ rept_basename = sysid + '_report' + '.html'
+ rept_fname = os.path.join(builddir,'Testing','Temporary',rept_basename )
+ debug("report filename:\n" + rept_fname )
username = ezsearch('--username=(.*?) ',string.join(sys.argv)+' ')
host = ezsearch('--host=(.*?) ',string.join(sys.argv)+' ')
remotepath = ezsearch('--remotepath=(.*?) ',string.join(sys.argv)+' ')
- if testdir=='' or username=='' or host=='' or remotepath=='':
+ if rept_fname=='' or username=='' or host=='' or remotepath=='':
help()
sys.exit(1)
- res = upload( testdir, username, host, remotepath )
+ res = upload( rept_fname, username, host, remotepath )
if res==1:
print "upload failed"
return 1
contact: Jan Huwald // Impressum