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

Functions

def basic_report
 
def quiet_report
 
def ctest_report
 
def pprint_report
 
def main
 

Function Documentation

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

Definition at line 11 of file Run.py.

11 
12 def basic_report(results):
13  '''
14  Report function taking the dictionary from BasicTest.run() and display
15  stdout and stderr from it.
16  '''
17  print '=== stdout ==='
18  print results.get('stdout', '')
19  print '=== stderr ==='
20  print results.get('stderr', '')
21  print '=== result ==='
22  print results.get('Status')
23  if results.get('Status') != 'passed' and 'Causes' in results:
24  print ' ', 'unexpected ' + ', '.join(results['Causes'])
25 
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 33 of file Run.py.

33 
34 def ctest_report(results):
35  '''
36  Report function taking the dictionary from BasicTest.run() and report data
37  from it in a CTest-friendly way.
38  '''
39  # It's weird, I know, but it tells CTest not to cut the output.
40  print 'CTEST_FULL_OUTPUT'
41  print results.get('stdout', '')
42  handler = {'Environment': lambda v: '\n'.join('{0}={1}'.format(*item)
43  for item in sorted(v.iteritems())),
44  'Causes': lambda v: 'unexpected ' + ', '.join(v)}
45  id_handler = lambda v: str(v)
46  ignore = set(['Status', 'Name', 'stdout', 'Exit Code'])
47  template = ('<DartMeasurement type="text/string" name="{0}">{1}</DartMeasurement>')
48 
49  for key in results:
50  if key in ignore:
51  continue
52  hndlr = handler.get(key, id_handler)
53  data = XSS.escape(GT.sanitize_for_xml(hndlr(results[key])))
54  sys.stdout.write(template.format(key, data))
55 
def GaudiTesting.Run.main ( )
Main function of the script.

Definition at line 65 of file Run.py.

65 
66 def main():
67  '''
68  Main function of the script.
69  '''
70  from optparse import OptionParser, OptionGroup
71  parser = OptionParser()
72 
73  parser.add_option('--report', action='store',
74  choices=[n.replace('_report', '')
75  for n in globals() if n.endswith('_report')],
76  help='choose a report method [default %default]')
77  parser.add_option('--common-tmpdir', action='store',
78  help='directory to be used as common temporary directory')
79  parser.add_option('-C', '--workdir', action='store',
80  help='directory to change to before starting the test')
81 
82  parser.add_option('--skip-return-code', type='int',
83  help='return code to use to flag a test as skipped '
84  '[default %default]')
85 
86  verbosity_opts = OptionGroup(parser, 'Verbosity Level',
87  'set the verbosity level of messages')
88  verbosity_opts.add_option('--silent',
89  action='store_const', dest='log_level',
90  const=logging.CRITICAL,
91  help='only critical error messages')
92  verbosity_opts.add_option('--quiet',
93  action='store_const', dest='log_level',
94  const=logging.ERROR,
95  help='error messages')
96  verbosity_opts.add_option('--warning',
97  action='store_const', dest='log_level',
98  const=logging.WARNING,
99  help='warning and error messages')
100  verbosity_opts.add_option('--verbose',
101  action='store_const', dest='log_level',
102  const=logging.INFO,
103  help='progress information messages')
104  verbosity_opts.add_option('--debug',
105  action='store_const', dest='log_level',
106  const=logging.DEBUG,
107  help='debugging messages')
108  parser.add_option_group(verbosity_opts)
109 
110 
111  parser.set_defaults(log_level=logging.WARNING,
112  report='basic',
113  workdir=os.curdir,
114  skip_return_code=0)
115 
116 
117  opts, args = parser.parse_args()
118  if len(args) != 1:
119  parser.error('only one test allowed')
120  filename = args[0]
121 
122  logging.basicConfig(level=opts.log_level)
123 
124  if opts.common_tmpdir:
125  if not os.path.isdir(opts.common_tmpdir):
126  os.makedirs(opts.common_tmpdir)
127  GT.BaseTest._common_tmpdir = opts.common_tmpdir
128 
129  os.chdir(opts.workdir)
130 
131  # FIXME: whithout this, we get some spurious '\x1b[?1034' in the std out on SLC6
132  if "slc6" in (os.environ.get('BINARY_TAG', '') or
133  os.environ.get('CMTCONFIG', '')):
134  os.environ['TERM'] = 'dumb'
135 
136  # Testing the file beginning with "Test" or if it is a qmt file and doing the test
137  logging.debug('processing %s', filename)
138  if filename.endswith('_test.py') :
139  indexFilePart= filename.rfind("/")
140  fileToImport = filename[indexFilePart+1:]
141  sys.path.append(GT.RationalizePath(filename)[:-len(fileToImport)-1])
142  imp = __import__(fileToImport[:-3])
143  fileToExec = imp.Test()
144  results = fileToExec.run()
145  elif filename.endswith(".qmt"):
146  from QMTTest import QMTTest
147  fileToTest = QMTTest(filename)
148  results = fileToTest.run()
149 
150  report = globals()[opts.report + '_report']
151  report(results)
152 
153  if results.get('Status') == 'failed':
154  logging.debug('test failed: unexpected %s',
155  ', '.join(results['Causes']))
156  return int(results.get('Exit Code', '1'))
157  elif results.get('Status') == 'skipped':
158  return opts.skip_return_code
159  return 0
def GaudiTesting.Run.pprint_report (   results)
Report function taking the dictionary from BasicTest.run() and print it with
the pprint module.

Definition at line 56 of file Run.py.

56 
57 def pprint_report(results):
58  '''
59  Report function taking the dictionary from BasicTest.run() and print it with
60  the pprint module.
61  '''
62  from pprint import pprint
63  pprint(results)
64 
def GaudiTesting.Run.quiet_report (   results)
Do not report anything from the result of the test.

Definition at line 26 of file Run.py.

26 
27 def quiet_report(results):
28  '''
29  Do not report anything from the result of the test.
30  '''
31  pass
32