The Gaudi Framework  v32r2 (46d42edc)
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 14 of file Run.py.

14 def basic_report(results):
15  '''
16  Report function taking the dictionary from BasicTest.run() and display
17  stdout and stderr from it.
18  '''
19  print('=== stdout ===')
20  print(results.get('stdout', ''))
21  print('=== stderr ===')
22  print(results.get('stderr', ''))
23  print('=== result ===')
24  print(results.get('Status'))
25  if results.get('Status') != 'passed' and 'Causes' in results:
26  print(' ', 'unexpected ' + ', '.join(results['Causes']))
27 
28 
def basic_report(results)
Definition: Run.py:14

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

36 def ctest_report(results):
37  '''
38  Report function taking the dictionary from BasicTest.run() and report data
39  from it in a CTest-friendly way.
40  '''
41  # It's weird, I know, but it tells CTest not to cut the output.
42  print('CTEST_FULL_OUTPUT')
43  print(results.get('stdout', ''))
44  handler = {'Environment': lambda v: '\n'.join('{0}={1}'.format(*item)
45  for item in sorted(v.items())),
46  'Causes': lambda v: 'unexpected ' + ', '.join(v)}
47 
48  def id_handler(v):
49  return str(v)
50 
51  ignore = set(['Status', 'Name', 'stdout', 'Exit Code'])
52  template = (
53  '<DartMeasurement type="text/string" name="{0}">{1}</DartMeasurement>')
54 
55  for key in results:
56  if key in ignore:
57  continue
58  hndlr = handler.get(key, id_handler)
59  data = XSS.escape(GT.sanitize_for_xml(hndlr(results[key])))
60  sys.stdout.write(template.format(key, data))
61 
62 
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:109
def ctest_report(results)
Definition: Run.py:36

◆ main()

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

Definition at line 72 of file Run.py.

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

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

63 def pprint_report(results):
64  '''
65  Report function taking the dictionary from BasicTest.run() and print it with
66  the pprint module.
67  '''
68  from pprint import pprint
69  pprint(results)
70 
71 
def pprint_report(results)
Definition: Run.py:63

◆ quiet_report()

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

Definition at line 29 of file Run.py.

29 def quiet_report(results):
30  '''
31  Do not report anything from the result of the test.
32  '''
33  pass
34 
35 
def quiet_report(results)
Definition: Run.py:29