The Gaudi Framework  master (37c0b60a)
GaudiTesting.Run Namespace Reference

Functions

def basic_report (results)
 
def quiet_report (results)
 
def ctest_report (results)
 
def pprint_report (results)
 
def main ()
 

Function Documentation

◆ basic_report()

def GaudiTesting.Run.basic_report (   results)
Report function taking the dictionary from BasicTest.run() and display
stdout and stderr from it.

Definition at line 24 of file Run.py.

24 def basic_report(results):
25  """
26  Report function taking the dictionary from BasicTest.run() and display
27  stdout and stderr from it.
28  """
29  print("=== stdout ===")
30  print(results.get("stdout", ""))
31  print("=== stderr ===")
32  print(results.get("stderr", ""))
33  print("=== result ===")
34  print(results.get("Status"))
35  if results.get("Status") != "passed" and "Causes" in results:
36  print(" ", "unexpected " + ", ".join(results["Causes"]))
37 
38 

◆ ctest_report()

def GaudiTesting.Run.ctest_report (   results)
Report function taking the dictionary from BasicTest.run() and report data
from it in a CTest-friendly way.

Definition at line 46 of file Run.py.

46 def ctest_report(results):
47  """
48  Report function taking the dictionary from BasicTest.run() and report data
49  from it in a CTest-friendly way.
50  """
51  # It's weird, I know, but it tells CTest not to cut the output.
52  print("CTEST_FULL_OUTPUT")
53  print(results.get("stdout", ""))
54  handler = {
55  "Runtime Environment": lambda v: "<pre>%s</pre>"
56  % "\n".join("{0}={1}".format(*item) for item in sorted(v.items())),
57  "Causes": lambda v: "unexpected " + ", ".join(v),
58  }
59 
60  def id_handler(v):
61  return str(v)
62 
63  ignore = set(["Status", "Name", "stdout", "Exit Code"])
64  template = '<DartMeasurement type="text/string" name="{0}">{1}</DartMeasurement>'
65 
66  for key in results:
67  if key in ignore:
68  continue
69  hndlr = handler.get(key, id_handler)
70  data = XSS.escape(GT.sanitize_for_xml(hndlr(results[key])))
71  print(template.format(key, data))
72 
73 

◆ main()

def GaudiTesting.Run.main ( )
Main function of the script.

Definition at line 84 of file Run.py.

84 def main():
85  """
86  Main function of the script.
87  """
88  from optparse import OptionGroup, OptionParser
89 
90  parser = OptionParser()
91 
92  parser.add_option(
93  "--report",
94  action="store",
95  choices=[n.replace("_report", "") for n in globals() if n.endswith("_report")],
96  help="choose a report method [default %default]",
97  )
98  parser.add_option(
99  "--common-tmpdir",
100  action="store",
101  help="directory to be used as common temporary directory",
102  )
103  parser.add_option(
104  "-C",
105  "--workdir",
106  action="store",
107  help="directory to change to before starting the test",
108  )
109 
110  parser.add_option(
111  "--skip-return-code",
112  type="int",
113  help="return code to use to flag a test as skipped " "[default %default]",
114  )
115 
116  verbosity_opts = OptionGroup(
117  parser, "Verbosity Level", "set the verbosity level of messages"
118  )
119  verbosity_opts.add_option(
120  "--silent",
121  action="store_const",
122  dest="log_level",
123  const=logging.CRITICAL,
124  help="only critical error messages",
125  )
126  verbosity_opts.add_option(
127  "--quiet",
128  action="store_const",
129  dest="log_level",
130  const=logging.ERROR,
131  help="error messages",
132  )
133  verbosity_opts.add_option(
134  "--warning",
135  action="store_const",
136  dest="log_level",
137  const=logging.WARNING,
138  help="warning and error messages",
139  )
140  verbosity_opts.add_option(
141  "--verbose",
142  action="store_const",
143  dest="log_level",
144  const=logging.INFO,
145  help="progress information messages",
146  )
147  verbosity_opts.add_option(
148  "--debug",
149  action="store_const",
150  dest="log_level",
151  const=logging.DEBUG,
152  help="debugging messages",
153  )
154  parser.add_option_group(verbosity_opts)
155 
156  parser.set_defaults(
157  log_level=logging.WARNING, report="basic", workdir=os.curdir, skip_return_code=0
158  )
159 
160  opts, args = parser.parse_args()
161  if len(args) != 1:
162  parser.error("only one test allowed")
163  filename = args[0]
164 
165  logging.basicConfig(level=opts.log_level)
166 
167  if opts.common_tmpdir:
168  if not os.path.isdir(opts.common_tmpdir):
169  os.makedirs(opts.common_tmpdir)
170  GT.BaseTest._common_tmpdir = opts.common_tmpdir
171 
172  os.chdir(opts.workdir)
173 
174  # FIXME: whithout this, we get some spurious '\x1b[?1034' in the std out on SLC6
175  if "slc6" in (os.environ.get("BINARY_TAG", "") or os.environ.get("CMTCONFIG", "")):
176  os.environ["TERM"] = "dumb"
177 
178  # If running sanitizer builds, set LD_PRELOAD in environment
179  sanitizer = os.environ.get("PRELOAD_SANITIZER_LIB", "")
180  ld_preload = os.environ.get("LD_PRELOAD", "")
181  if sanitizer and sanitizer not in ld_preload:
182  if ld_preload:
183  os.environ["LD_PRELOAD"] = sanitizer + " " + ld_preload
184  else:
185  os.environ["LD_PRELOAD"] = sanitizer
186 
187  # Testing the file beginning with "Test" or if it is a qmt file and doing the test
188  logging.debug("processing %s", filename)
189  if filename.endswith("_test.py"):
190  indexFilePart = filename.rfind("/")
191  fileToImport = filename[indexFilePart + 1 :]
192  sys.path.append(GT.RationalizePath(filename)[: -len(fileToImport) - 1])
193  imp = __import__(fileToImport[:-3])
194  fileToExec = imp.Test()
195  results = fileToExec.run()
196  elif filename.endswith(".qmt"):
197  # Check which class should be used to instantiate QMTests
198  # by default it is QMTTest but this can be overwritten via the environment
199  test_module = os.environ.get("GAUDI_QMTEST_MODULE", "GaudiTesting.QMTTest")
200  test_class = os.environ.get("GAUDI_QMTEST_CLASS", "QMTTest")
201  test_class = getattr(importlib.import_module(test_module), test_class)
202  fileToTest = test_class(filename)
203  results = fileToTest.run()
204 
205  report = globals()[opts.report + "_report"]
206  report(results)
207 
208  if results.get("Status") == "failed":
209  logging.debug("test failed: unexpected %s", ", ".join(results["Causes"]))
210  return int(results.get("Exit Code", "1"))
211  elif results.get("Status") == "skipped":
212  return opts.skip_return_code
213  return 0
214 
215 

◆ pprint_report()

def GaudiTesting.Run.pprint_report (   results)
Report function taking the dictionary from BasicTest.run() and print it with
the pprint module.

Definition at line 74 of file Run.py.

74 def pprint_report(results):
75  """
76  Report function taking the dictionary from BasicTest.run() and print it with
77  the pprint module.
78  """
79  from pprint import pprint
80 
81  pprint(results)
82 
83 

◆ quiet_report()

def GaudiTesting.Run.quiet_report (   results)
Do not report anything from the result of the test.

Definition at line 39 of file Run.py.

39 def quiet_report(results):
40  """
41  Do not report anything from the result of the test.
42  """
43  pass
44 
45 
GaudiTesting.Run.main
def main()
Definition: Run.py:84
GaudiTesting.Run.quiet_report
def quiet_report(results)
Definition: Run.py:39
GaudiTesting.Run.basic_report
def basic_report(results)
Definition: Run.py:24
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
GaudiTesting.Run.pprint_report
def pprint_report(results)
Definition: Run.py:74
GaudiTesting.Run.ctest_report
def ctest_report(results)
Definition: Run.py:46