|
Gaudi Framework, version v21r6 |
| Home | Generated: 11 Nov 2009 |
Functions | |
| def | parse_summary |
| def | main |
| def qmtest_summarize::main | ( | ) |
Definition at line 35 of file qmtest_summarize.py.
00035 : 00036 # I assume that this script is run from a CMT action, which implies few other 00037 # things: 00038 # - we are in the cmt directory of a package 00039 # - CMTCONFIG etc. are correctly defined 00040 # - we can call cmt 00041 00042 # Directory where to store the report 00043 if "CMTINSTALLAREA" not in os.environ: 00044 os.environ["CMTINSTALLAREA"] = os.popen("cmt show macro_value CMTINSTALLAREA","r").read().strip() 00045 00046 # Find the packages (their cmt dirs) 00047 cmt_br_header_re = re.compile(r"^# Now trying.*in (.*) \([0-9]+/[0-9]+\)") 00048 dirs = [] 00049 00050 # Hack to work around a problem with cmt broadcast and CMTUSERCONTEXT. 00051 old_CMTUSERCONTEXT = None 00052 if "CMTUSERCONTEXT" in os.environ: 00053 old_CMTUSERCONTEXT = os.environ["CMTUSERCONTEXT"] 00054 del os.environ["CMTUSERCONTEXT"] 00055 00056 for l in os.popen("cmt broadcast","r"): 00057 m = cmt_br_header_re.match(l) 00058 if m: 00059 dirs.append(m.group(1)) 00060 00061 # Restore original CMTUSERCONTEXT, if it was set. 00062 if old_CMTUSERCONTEXT is not None: 00063 os.environ["CMTUSERCONTEXT"] = old_CMTUSERCONTEXT 00064 00065 # Find the results.qmr files 00066 results = filter(os.path.isfile,[ os.path.realpath(os.path.join(d,'..',os.environ["CMTCONFIG"],"results.qmr")) for d in dirs ]) 00067 00068 # Check if the result files have been found 00069 if len(results) == 0: 00070 print "Warning: no result file found! (Did you run the tests?)" 00071 sys.exit() 00072 00073 # parse and collect the summaries 00074 # FIXME: (MCl) with QMTest 2.3 we need a test database to be able to run "qmtest summarize", while it 00075 # is not needed with QMTest 2.4 00076 from tempfile import mkdtemp 00077 from shutil import rmtree 00078 tmpdir = mkdtemp() 00079 origdir = os.getcwd() 00080 report = None 00081 try: 00082 os.chdir(tmpdir) 00083 os.popen("qmtest create-tdb","r").read() 00084 00085 for r in results: 00086 out = os.popen("qmtest summarize -f brief %s"%r,"r").read() 00087 rep = parse_summary(out) 00088 if report is None: 00089 report = rep 00090 else: 00091 report["results"] += rep["results"] 00092 if rep["not_passed"]: 00093 report["not_passed"] += rep["not_passed"] 00094 for k in rep["statistics"]: 00095 if k in report["statistics"]: 00096 report["statistics"][k] += rep["statistics"][k] 00097 else: 00098 report["statistics"][k] = rep["statistics"][k] 00099 finally: 00100 os.chdir(origdir) 00101 rmtree(tmpdir,ignore_errors=True) 00102 00103 if report is None: 00104 print "Warning: I could not generate the report" 00105 sys.exit() 00106 00107 # Finalize the report 00108 report["results"].append('') 00109 if not report["not_passed"]: 00110 report["not_passed"] = ['',' None.'] 00111 report["not_passed"] += ['',''] 00112 00113 statistics_output = ['--- STATISTICS ---------------------------------------------------------------',''] 00114 # order: total, FAIL, UNTESTED, PASS 00115 #" 2 tests total" 00116 tot = report["statistics"]["total"] 00117 statistics_output.append("%8d tests total"%(tot)) 00118 for k in [ "ERROR", "FAIL", "UNTESTED", "PASS" ]: 00119 if k in report["statistics"]: 00120 n = report["statistics"][k] 00121 p = round(100. * n / tot) 00122 statistics_output.append("%8d (%3d%%) tests %s"%(n,p,k)) 00123 statistics_output.append('') 00124 00125 results_output = ['--- TEST RESULTS -------------------------------------------------------------'] 00126 results_output += report["results"] 00127 00128 not_passed_output = ['--- TESTS THAT DID NOT PASS --------------------------------------------------'] 00129 if not report["not_passed"]: 00130 not_passed_output 00131 not_passed_output += report["not_passed"] 00132 00133 output = statistics_output + not_passed_output + results_output + not_passed_output + statistics_output 00134 print '\n'.join(output) 00135 if __name__ == '__main__':
| def qmtest_summarize::parse_summary | ( | output | ) |
Definition at line 11 of file qmtest_summarize.py.
00011 : 00012 report = { "results":[], "not_passed":[], "statistics": {} } 00013 current_block = None 00014 for l in output.splitlines(): 00015 if l.startswith("--- TEST RESULTS"): 00016 current_block = "results" 00017 elif l.startswith("--- TESTS THAT DID NOT PASS"): 00018 current_block = "not_passed" 00019 elif l.startswith("--- STATISTICS"): 00020 current_block = "statistics" 00021 else: 00022 if current_block in ["results","not_passed"]: 00023 report[current_block].append(l) 00024 elif current_block == "statistics": 00025 tkns = l.split() 00026 if tkns: 00027 report["statistics"][tkns[-1]] = int(tkns[0]) 00028 00029 report["results"] = report["results"][:-1] 00030 report["not_passed"] = report["not_passed"][:-2] 00031 if report["not_passed"][-1].strip() == "None.": 00032 report["not_passed"] = [] 00033 return report 00034 def main():