12 report = {
"results":[],
"not_passed":[],
"statistics": {} }
14 for l
in output.splitlines():
15 if l.startswith(
"--- TEST RESULTS"):
16 current_block =
"results"
17 elif l.startswith(
"--- TESTS THAT DID NOT PASS"):
18 current_block =
"not_passed"
19 elif l.startswith(
"--- STATISTICS"):
20 current_block =
"statistics"
22 if current_block
in [
"results",
"not_passed"]:
23 report[current_block].append(l)
24 elif current_block ==
"statistics":
27 report[
"statistics"][tkns[-1]] = int(tkns[0])
29 report[
"results"] = report[
"results"][:-1]
30 report[
"not_passed"] = report[
"not_passed"][:-2]
31 if report[
"not_passed"][-1].strip() ==
"None.":
32 report[
"not_passed"] = []
44 if "QMTESTRESULTSDIR" in os.environ:
45 outputdir = os.path.normpath(os.path.expandvars(os.environ[
"QMTESTRESULTSDIR"]))
54 cmt_br_header_re = re.compile(
r"^# Now trying.*in (.*) \([0-9]+/[0-9]+\)")
58 old_CMTUSERCONTEXT =
None
59 if "CMTUSERCONTEXT" in os.environ:
60 old_CMTUSERCONTEXT = os.environ[
"CMTUSERCONTEXT"]
61 del os.environ[
"CMTUSERCONTEXT"]
63 for l
in os.popen(
"cmt broadcast",
"r"):
64 m = cmt_br_header_re.match(l)
66 dirs.append(m.group(1))
69 if old_CMTUSERCONTEXT
is not None:
70 os.environ[
"CMTUSERCONTEXT"] = old_CMTUSERCONTEXT
74 results = filter(os.path.isfile,[ os.path.realpath(os.path.join(d,
'..',os.environ[
"CMTCONFIG"],
"results.qmr"))
for d
in dirs ])
78 pkg = os.path.basename(os.path.dirname(d))
79 r = os.path.join(outputdir,
"%s.%s.qmr" % (pkg, os.environ.get(
"CMTCONFIG",
"noConfig")))
87 for r, ds, fs
in os.walk(os.getcwd()):
89 if f.endswith(
'.qmr'):
90 results.append(os.path.join(r, f))
94 if os.path.exists(
'CMakeCache.txt'):
104 print "Warning: no result file found! (Did you run the tests?)"
110 from tempfile
import mkdtemp
111 from shutil
import rmtree
113 origdir = os.getcwd()
117 os.popen(
"qmtest create-tdb",
"r").read()
120 out = os.popen(
"qmtest summarize -f brief %s"%r,
"r").read()
125 report[
"results"] += rep[
"results"]
126 if rep[
"not_passed"]:
127 report[
"not_passed"] += rep[
"not_passed"]
128 for k
in rep[
"statistics"]:
129 if k
in report[
"statistics"]:
130 report[
"statistics"][k] += rep[
"statistics"][k]
132 report[
"statistics"][k] = rep[
"statistics"][k]
135 rmtree(tmpdir,ignore_errors=
True)
138 print "Warning: I could not generate the report"
142 report[
"results"].append(
'')
143 if not report[
"not_passed"]:
144 report[
"not_passed"] = [
'',
' None.']
145 report[
"not_passed"] += [
'',
'']
147 statistics_output = [
'--- STATISTICS ---------------------------------------------------------------',
'']
150 tot = report[
"statistics"][
"total"]
151 statistics_output.append(
"%8d tests total"%(tot))
153 for k
in [
"ERROR",
"FAIL",
"UNTESTED",
"PASS" ]:
154 if k
in report[
"statistics"]:
155 n = report[
"statistics"][k]
156 p = round(100. * n / tot)
157 statistics_output.append(
"%8d (%3d%%) tests %s"%(n,p,k))
158 if k
in [
"ERROR",
"FAIL"]:
160 statistics_output.append(
'')
162 results_output = [
'--- TEST RESULTS -------------------------------------------------------------']
163 results_output += report[
"results"]
165 not_passed_output = [
'--- TESTS THAT DID NOT PASS --------------------------------------------------']
166 if not report[
"not_passed"]:
168 not_passed_output += report[
"not_passed"]
170 output = statistics_output + not_passed_output + results_output + not_passed_output + statistics_output
171 print '\n'.join(output)
175 if __name__ ==
'__main__':