| # Gaudi Framework, version v22r4 |

Home |  | Generated: Fri Sep 2 2011

Functions

# qmtest_summarize Namespace Reference

## Functions
def | parse_summary
def | main

## Function Documentation

def qmtest_summarize::main | ( | ) |

Definition at line 35 of file qmtest_summarize.py.

    00036           :
    00037     # I assume that this script is run from a CMT action, which implies few other
    00038     # things:
    00039     #   - we are in the cmt directory of a package
    00040     #   - CMTCONFIG etc. are correctly defined
    00041     #   - we can call cmt
    00042
    00043     # If the use specifies a directory where to collect all the results
    00044     # (e.g. because running from a read-only location) we must use it
    00045     if "QMTESTRESULTSDIR" in os.environ:
    00046         outputdir = os.path.normpath(os.path.expandvars(os.environ["QMTESTRESULTSDIR"]))
    00047     else:
    00048         outputdir = None
    00049
    00050     ## Directory where to store the report
    00051     #if "CMTINSTALLAREA" not in os.environ:
    00052     #    os.environ["CMTINSTALLAREA"] = os.popen("cmt show macro_value CMTINSTALLAREA","r").read().strip()
    00053
    00054     # Find the packages (their cmt dirs)
    00055     cmt_br_header_re = re.compile(r"^# Now trying.*in (.*) \([0-9]+/[0-9]+\)")
    00056     dirs = []
    00057
    00058     # Hack to work around a problem with cmt broadcast and CMTUSERCONTEXT.
    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     # Restore original CMTUSERCONTEXT, if it was set.
    00070     if old_CMTUSERCONTEXT is not None:
    00071         os.environ["CMTUSERCONTEXT"] = old_CMTUSERCONTEXT
    00072
    00073     # Find the results.qmr files
    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     # Check if the result files have been found
    00085     if len(results) == 0:
    00086         print "Warning: no result file found! (Did you run the tests?)"
    00087         sys.exit()
    00088
    00089     # parse and collect the summaries
    00090     # FIXME: (MCl) with QMTest 2.3 we need a test database to be able to run "qmtest summarize", while it
    00091     #              is not needed with QMTest 2.4
    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     # Finalize the report
    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     # order: total, FAIL, UNTESTED, PASS
    00131     #"       2        tests total"
    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

def qmtest_summarize::parse_summary | ( |  | output ) |

Definition at line 11 of file qmtest_summarize.py.

    00012                          :
    00013     report = { "results":[], "not_passed":[], "statistics": {} }
    00014     current_block = None
    00015     for l in output.splitlines():
    00016         if l.startswith("--- TEST RESULTS"):
    00017             current_block = "results"
    00018         elif l.startswith("--- TESTS THAT DID NOT PASS"):
    00019             current_block = "not_passed"
    00020         elif l.startswith("--- STATISTICS"):
    00021             current_block = "statistics"
    00022         else:
    00023             if current_block in ["results","not_passed"]:
    00024                 report[current_block].append(l)
    00025             elif current_block == "statistics":
    00026                 tkns = l.split()
    00027                 if tkns:
    00028                     report["statistics"][tkns[-1]] = int(tkns[0])
    00029
    00030     report["results"] = report["results"][:-1]
    00031     report["not_passed"] = report["not_passed"][:-2]
    00032     if report["not_passed"][-1].strip() == "None.":
    00033         report["not_passed"] = []
    00034     return report

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines