The Gaudi Framework  v36r7 (7f57a304)
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 26 of file Run.py.

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

◆ 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 48 of file Run.py.

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

◆ main()

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

Definition at line 86 of file Run.py.

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

◆ 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 76 of file Run.py.

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

◆ quiet_report()

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

Definition at line 41 of file Run.py.

41 def quiet_report(results):
42  """
43  Do not report anything from the result of the test.
44  """
45  pass
46 
47 
GaudiTesting.Run.main
def main()
Definition: Run.py:86
GaudiTesting.Run.quiet_report
def quiet_report(results)
Definition: Run.py:41
GaudiTesting.Run.basic_report
def basic_report(results)
Definition: Run.py:26
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:76
GaudiTesting.Run.ctest_report
def ctest_report(results)
Definition: Run.py:48