All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qmtest_summarize Namespace Reference

Functions

def parse_summary
 
def find_results_cmt
 
def find_results_cmake
 
def find_results
 
def main
 

Function Documentation

def qmtest_summarize.find_results ( )

Definition at line 93 of file qmtest_summarize.py.

93 
94 def find_results():
95  if os.path.exists('CMakeCache.txt'):
96  return find_results_cmake()
97  else:
98  return find_results_cmt()
def qmtest_summarize.find_results_cmake ( )

Definition at line 85 of file qmtest_summarize.py.

85 
86 def find_results_cmake():
87  results = []
88  for r, ds, fs in os.walk(os.getcwd()):
89  for f in fs:
90  if f.endswith('.qmr'):
91  results.append(os.path.join(r, f))
92  return results
def qmtest_summarize.find_results_cmt ( )

Definition at line 35 of file qmtest_summarize.py.

35 
36 def find_results_cmt():
37  # I assume that this script is run from a CMT action, which implies few other
38  # things:
39  # - we are in the cmt directory of a package
40  # - CMTCONFIG etc. are correctly defined
41  # - we can call cmt
42 
43  # If the use specifies a directory where to collect all the results
44  # (e.g. because running from a read-only location) we must use it
45  if "QMTESTRESULTSDIR" in os.environ:
46  outputdir = os.path.normpath(os.path.expandvars(os.environ["QMTESTRESULTSDIR"]))
47  else:
48  outputdir = None
49 
50  ## Directory where to store the report
51  #if "CMTINSTALLAREA" not in os.environ:
52  # os.environ["CMTINSTALLAREA"] = os.popen("cmt show macro_value CMTINSTALLAREA","r").read().strip()
53 
54  # Find the packages (their cmt dirs)
55  cmt_br_header_re = re.compile(r"^# Now trying.*in (.*) \([0-9]+/[0-9]+\)")
56  dirs = []
57 
58  # Hack to work around a problem with cmt broadcast and CMTUSERCONTEXT.
59  old_CMTUSERCONTEXT = None
60  if "CMTUSERCONTEXT" in os.environ:
61  old_CMTUSERCONTEXT = os.environ["CMTUSERCONTEXT"]
62  del os.environ["CMTUSERCONTEXT"]
63 
64  for l in os.popen("cmt broadcast","r"):
65  m = cmt_br_header_re.match(l)
66  if m:
67  dirs.append(m.group(1))
68 
69  # Restore original CMTUSERCONTEXT, if it was set.
70  if old_CMTUSERCONTEXT is not None:
71  os.environ["CMTUSERCONTEXT"] = old_CMTUSERCONTEXT
72 
73  # Find the results.qmr files
74  if not outputdir:
75  results = filter(os.path.isfile,[ os.path.realpath(os.path.join(d,'..',os.environ["CMTCONFIG"],"results.qmr")) for d in dirs ])
76  else:
77  results = []
78  for d in dirs:
79  pkg = os.path.basename(os.path.dirname(d))
80  r = os.path.join(outputdir, "%s.%s.qmr" % (pkg, os.environ.get("CMTCONFIG", "noConfig")))
81  if os.path.isfile(r):
82  results.append(r)
83 
84  return results
def qmtest_summarize.main ( )

Definition at line 99 of file qmtest_summarize.py.

99 
100 def main():
101  results = find_results()
102 
103  # Check if the result files have been found
104  if not results:
105  print "Warning: no result file found! (Did you run the tests?)"
106  sys.exit()
107 
108  # parse and collect the summaries
109  # FIXME: (MCl) with QMTest 2.3 we need a test database to be able to run "qmtest summarize", while it
110  # is not needed with QMTest 2.4
111  from tempfile import mkdtemp
112  from shutil import rmtree
113  tmpdir = mkdtemp()
114  origdir = os.getcwd()
115  report = None
116  try:
117  os.chdir(tmpdir)
118  os.popen("qmtest create-tdb","r").read()
119 
120  for r in results:
121  out = os.popen("qmtest summarize -f brief %s"%r,"r").read()
122  rep = parse_summary(out)
123  if report is None:
124  report = rep
125  else:
126  report["results"] += rep["results"]
127  if rep["not_passed"]:
128  report["not_passed"] += rep["not_passed"]
129  for k in rep["statistics"]:
130  if k in report["statistics"]:
131  report["statistics"][k] += rep["statistics"][k]
132  else:
133  report["statistics"][k] = rep["statistics"][k]
134  finally:
135  os.chdir(origdir)
136  rmtree(tmpdir,ignore_errors=True)
137 
138  if report is None:
139  print "Warning: I could not generate the report"
140  sys.exit()
141 
142  # Finalize the report
143  report["results"].append('')
144  if not report["not_passed"]:
145  report["not_passed"] = ['',' None.']
146  report["not_passed"] += ['','']
147 
148  statistics_output = ['--- STATISTICS ---------------------------------------------------------------','']
149  # order: total, FAIL, UNTESTED, PASS
150  #" 2 tests total"
151  tot = report["statistics"]["total"]
152  statistics_output.append("%8d tests total"%(tot))
153  success = True
154  for k in [ "ERROR", "FAIL", "UNTESTED", "PASS" ]:
155  if k in report["statistics"]:
156  n = report["statistics"][k]
157  p = round(100. * n / tot)
158  statistics_output.append("%8d (%3d%%) tests %s"%(n,p,k))
159  if k in ["ERROR", "FAIL"]:
160  success = False
161  statistics_output.append('')
162 
163  results_output = ['--- TEST RESULTS -------------------------------------------------------------']
164  results_output += report["results"]
165 
166  not_passed_output = ['--- TESTS THAT DID NOT PASS --------------------------------------------------']
167  if not report["not_passed"]:
168  not_passed_output
169  not_passed_output += report["not_passed"]
170 
171  output = statistics_output + not_passed_output + results_output + not_passed_output + statistics_output
172  print '\n'.join(output)
173  return success
174 
def qmtest_summarize.parse_summary (   output)

Definition at line 11 of file qmtest_summarize.py.

11 
12 def parse_summary(output):
13  report = { "results":[], "not_passed":[], "statistics": {} }
14  current_block = None
15  for l in output.splitlines():
16  if l.startswith("--- TEST RESULTS"):
17  current_block = "results"
18  elif l.startswith("--- TESTS THAT DID NOT PASS"):
19  current_block = "not_passed"
20  elif l.startswith("--- STATISTICS"):
21  current_block = "statistics"
22  else:
23  if current_block in ["results","not_passed"]:
24  report[current_block].append(l)
25  elif current_block == "statistics":
26  tkns = l.split()
27  if tkns:
28  report["statistics"][tkns[-1]] = int(tkns[0])
29 
30  report["results"] = report["results"][:-1]
31  report["not_passed"] = report["not_passed"][:-2]
32  if report["not_passed"][-1].strip() == "None.":
33  report["not_passed"] = []
34  return report