4 import xml.sax.saxutils
as XSS
9 sys.modules[
'GaudiTest'] = GT
14 Report function taking the dictionary from BasicTest.run() and display 15 stdout and stderr from it. 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'])
29 Do not report anything from the result of the test. 36 Report function taking the dictionary from BasicTest.run() and report data 37 from it in a CTest-friendly way. 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)}
46 def id_handler(v):
return str(v)
47 ignore = set([
'Status',
'Name',
'stdout',
'Exit Code'])
49 '<DartMeasurement type="text/string" name="{0}">{1}</DartMeasurement>')
54 hndlr = handler.get(key, id_handler)
55 data = XSS.escape(GT.sanitize_for_xml(hndlr(results[key])))
56 sys.stdout.write(template.format(key, data))
61 Report function taking the dictionary from BasicTest.run() and print it with 64 from pprint
import pprint
70 Main function of the script. 72 from optparse
import OptionParser, OptionGroup
73 parser = OptionParser()
75 parser.add_option(
'--report', action=
'store',
76 choices=[n.replace(
'_report',
'')
77 for n
in globals()
if n.endswith(
'_report')],
78 help=
'choose a report method [default %default]')
79 parser.add_option(
'--common-tmpdir', action=
'store',
80 help=
'directory to be used as common temporary directory')
81 parser.add_option(
'-C',
'--workdir', action=
'store',
82 help=
'directory to change to before starting the test')
84 parser.add_option(
'--skip-return-code', type=
'int',
85 help=
'return code to use to flag a test as skipped ' 88 verbosity_opts = OptionGroup(parser,
'Verbosity Level',
89 'set the verbosity level of messages')
90 verbosity_opts.add_option(
'--silent',
91 action=
'store_const', dest=
'log_level',
92 const=logging.CRITICAL,
93 help=
'only critical error messages')
94 verbosity_opts.add_option(
'--quiet',
95 action=
'store_const', dest=
'log_level',
97 help=
'error messages')
98 verbosity_opts.add_option(
'--warning',
99 action=
'store_const', dest=
'log_level',
100 const=logging.WARNING,
101 help=
'warning and error messages')
102 verbosity_opts.add_option(
'--verbose',
103 action=
'store_const', dest=
'log_level',
105 help=
'progress information messages')
106 verbosity_opts.add_option(
'--debug',
107 action=
'store_const', dest=
'log_level',
109 help=
'debugging messages')
110 parser.add_option_group(verbosity_opts)
112 parser.set_defaults(log_level=logging.WARNING,
117 opts, args = parser.parse_args()
119 parser.error(
'only one test allowed')
122 logging.basicConfig(level=opts.log_level)
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
129 os.chdir(opts.workdir)
132 if "slc6" in (os.environ.get(
'BINARY_TAG',
'')
or 133 os.environ.get(
'CMTCONFIG',
'')):
134 os.environ[
'TERM'] =
'dumb' 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"):
149 test_module = os.environ.get(
150 'GAUDI_QMTEST_MODULE',
'GaudiTesting.QMTTest')
151 test_class = os.environ.get(
'GAUDI_QMTEST_CLASS',
'QMTTest')
152 exec
'from {} import {} as test_class'.
format(
153 test_module, test_class)
154 fileToTest = test_class(filename)
155 results = fileToTest.run()
158 'Exception caught when trying to instantiate qmt test python object')
162 report = globals()[opts.report +
'_report']
165 if results.get(
'Status') ==
'failed':
166 logging.debug(
'test failed: unexpected %s',
167 ', '.join(results[
'Causes']))
168 return int(results.get(
'Exit Code',
'1'))
169 elif results.get(
'Status') ==
'skipped':
170 return opts.skip_return_code
174 if __name__ ==
'__main__':
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
def pprint_report(results)
def basic_report(results)
def ctest_report(results)
def quiet_report(results)