Source
testwidth = 0 if len(tests) == 0 else max(map(lambda x: len(os.path.basename(x[0])) + 3, tests))
# use like:
# python testrunner/run.py casatests/test.py
import os
import sys
import time
import unittest
import subprocess
from subprocess import Popen, PIPE
from distutils.dir_util import remove_tree
import errno
# 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(rf):
with open(rf, '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