Source
###
### use like:
###
### PYTHONPATH=build/lib.macosx-10.12-x86_64-3.6 python tests/run.py tests/tools/image/test_ia_imageconcat.py tests/tools/image/test_ia_makecomplex.py
###
import os
import sys
import time
import inspect
import unittest
import subprocess
from subprocess import Popen, PIPE
from distutils.dir_util import remove_tree
from xml.sax.saxutils import escape
###
### xUnit generation
###
xml_escape_table = {
"&": "&",
'"': """,
"'": "'",
">": ">",
"<": "<",
}
def xml_escape(text):
return "".join(xml_escape_table.get(c,c) for c in text)
def readFile(f):
with open(f, 'r') as f1:
return f1.read()
def test_result_to_xml (result):
returncode, testname, run_time, teststdout, testerr = result
testxml = '<testcase classname="' + testname + '"' \
+ ' name="full log" time="' + str(round(run_time)) + '">'
if ( returncode != 0) :
testxml = testxml + '<failure>' + xml_escape(readFile(testerr)) + '</failure>'
testxml = testxml + '</testcase>\n'
return testxml
###
### support routines
###
def mkpath(path):
try:
os.makedirs(path)
except OSError as exc:
if exc.errno == errno.EEXIST and os.path.isdir(path):
pass
else:
raise
pyversion = float(sys.version_info[0]) + float(sys.version_info[1]) / 10.0
if pyversion < 3:
str_encode = str
str_decode = str
def pipe_decode(output):
return output