00036 :
00037
00038
00039
00040
00041
00042
00043
00044
00045 if "QMTESTRESULTSDIR" in os.environ:
00046 outputdir = os.path.normpath(os.path.expandvars(os.environ["QMTESTRESULTSDIR"]))
00047 else:
00048 outputdir = None
00049
00050
00051
00052
00053
00054
00055 cmt_br_header_re = re.compile(r"^# Now trying.*in (.*) \([0-9]+/[0-9]+\)")
00056 dirs = []
00057
00058
00059 old_CMTUSERCONTEXT = None
00060 if "CMTUSERCONTEXT" in os.environ:
00061 old_CMTUSERCONTEXT = os.environ["CMTUSERCONTEXT"]
00062 del os.environ["CMTUSERCONTEXT"]
00063
00064 for l in os.popen("cmt broadcast","r"):
00065 m = cmt_br_header_re.match(l)
00066 if m:
00067 dirs.append(m.group(1))
00068
00069
00070 if old_CMTUSERCONTEXT is not None:
00071 os.environ["CMTUSERCONTEXT"] = old_CMTUSERCONTEXT
00072
00073
00074 if not outputdir:
00075 results = filter(os.path.isfile,[ os.path.realpath(os.path.join(d,'..',os.environ["CMTCONFIG"],"results.qmr")) for d in dirs ])
00076 else:
00077 results = []
00078 for d in dirs:
00079 pkg = os.path.basename(os.path.dirname(d))
00080 r = os.path.join(outputdir, "%s.%s.qmr" % (pkg, os.environ.get("CMTCONFIG", "noConfig")))
00081 if os.path.isfile(r):
00082 results.append(r)
00083
00084
00085 if len(results) == 0:
00086 print "Warning: no result file found! (Did you run the tests?)"
00087 sys.exit()
00088
00089
00090
00091
00092 from tempfile import mkdtemp
00093 from shutil import rmtree
00094 tmpdir = mkdtemp()
00095 origdir = os.getcwd()
00096 report = None
00097 try:
00098 os.chdir(tmpdir)
00099 os.popen("qmtest create-tdb","r").read()
00100
00101 for r in results:
00102 out = os.popen("qmtest summarize -f brief %s"%r,"r").read()
00103 rep = parse_summary(out)
00104 if report is None:
00105 report = rep
00106 else:
00107 report["results"] += rep["results"]
00108 if rep["not_passed"]:
00109 report["not_passed"] += rep["not_passed"]
00110 for k in rep["statistics"]:
00111 if k in report["statistics"]:
00112 report["statistics"][k] += rep["statistics"][k]
00113 else:
00114 report["statistics"][k] = rep["statistics"][k]
00115 finally:
00116 os.chdir(origdir)
00117 rmtree(tmpdir,ignore_errors=True)
00118
00119 if report is None:
00120 print "Warning: I could not generate the report"
00121 sys.exit()
00122
00123
00124 report["results"].append('')
00125 if not report["not_passed"]:
00126 report["not_passed"] = ['',' None.']
00127 report["not_passed"] += ['','']
00128
00129 statistics_output = ['--- STATISTICS ---------------------------------------------------------------','']
00130
00131
00132 tot = report["statistics"]["total"]
00133 statistics_output.append("%8d tests total"%(tot))
00134 success = True
00135 for k in [ "ERROR", "FAIL", "UNTESTED", "PASS" ]:
00136 if k in report["statistics"]:
00137 n = report["statistics"][k]
00138 p = round(100. * n / tot)
00139 statistics_output.append("%8d (%3d%%) tests %s"%(n,p,k))
00140 if k in ["ERROR", "FAIL"]:
00141 success = False
00142 statistics_output.append('')
00143
00144 results_output = ['--- TEST RESULTS -------------------------------------------------------------']
00145 results_output += report["results"]
00146
00147 not_passed_output = ['--- TESTS THAT DID NOT PASS --------------------------------------------------']
00148 if not report["not_passed"]:
00149 not_passed_output
00150 not_passed_output += report["not_passed"]
00151
00152 output = statistics_output + not_passed_output + results_output + not_passed_output + statistics_output
00153 print '\n'.join(output)
00154 return success