11 from __future__
import print_function
17 import xml.sax.saxutils
as XSS
19 from GaudiTesting
import BaseTest
as GT
22 sys.modules[
"GaudiTest"] = GT
27 Report function taking the dictionary from BasicTest.run() and display
28 stdout and stderr from it.
30 print(
"=== stdout ===")
31 print(results.get(
"stdout",
""))
32 print(
"=== stderr ===")
33 print(results.get(
"stderr",
""))
34 print(
"=== result ===")
35 print(results.get(
"Status"))
36 if results.get(
"Status") !=
"passed" and "Causes" in results:
37 print(
" ",
"unexpected " +
", ".join(results[
"Causes"]))
42 Do not report anything from the result of the test.
49 Report function taking the dictionary from BasicTest.run() and report data
50 from it in a CTest-friendly way.
53 print(
"CTEST_FULL_OUTPUT")
54 print(results.get(
"stdout",
""))
56 "Runtime Environment":
lambda v:
"<pre>%s</pre>"
57 %
"\n".join(
"{0}={1}".
format(*item)
for item
in sorted(v.items())),
58 "Causes":
lambda v:
"unexpected " +
", ".join(v),
64 ignore = set([
"Status",
"Name",
"stdout",
"Exit Code"])
65 template =
'<DartMeasurement type="text/string" name="{0}">{1}</DartMeasurement>'
70 hndlr = handler.get(key, id_handler)
71 data = XSS.escape(GT.sanitize_for_xml(hndlr(results[key])))
72 print(template.format(key, data))
77 Report function taking the dictionary from BasicTest.run() and print it with
80 from pprint
import pprint
87 Main function of the script.
89 from optparse
import OptionGroup, OptionParser
91 parser = OptionParser()
96 choices=[n.replace(
"_report",
"")
for n
in globals()
if n.endswith(
"_report")],
97 help=
"choose a report method [default %default]",
102 help=
"directory to be used as common temporary directory",
108 help=
"directory to change to before starting the test",
112 "--skip-return-code",
114 help=
"return code to use to flag a test as skipped " "[default %default]",
117 verbosity_opts = OptionGroup(
118 parser,
"Verbosity Level",
"set the verbosity level of messages"
120 verbosity_opts.add_option(
122 action=
"store_const",
124 const=logging.CRITICAL,
125 help=
"only critical error messages",
127 verbosity_opts.add_option(
129 action=
"store_const",
132 help=
"error messages",
134 verbosity_opts.add_option(
136 action=
"store_const",
138 const=logging.WARNING,
139 help=
"warning and error messages",
141 verbosity_opts.add_option(
143 action=
"store_const",
146 help=
"progress information messages",
148 verbosity_opts.add_option(
150 action=
"store_const",
153 help=
"debugging messages",
155 parser.add_option_group(verbosity_opts)
158 log_level=logging.WARNING, report=
"basic", workdir=os.curdir, skip_return_code=0
161 opts, args = parser.parse_args()
163 parser.error(
"only one test allowed")
166 logging.basicConfig(level=opts.log_level)
168 if opts.common_tmpdir:
169 if not os.path.isdir(opts.common_tmpdir):
170 os.makedirs(opts.common_tmpdir)
171 GT.BaseTest._common_tmpdir = opts.common_tmpdir
173 os.chdir(opts.workdir)
176 if "slc6" in (os.environ.get(
"BINARY_TAG",
"")
or os.environ.get(
"CMTCONFIG",
"")):
177 os.environ[
"TERM"] =
"dumb"
180 sanitizer = os.environ.get(
"PRELOAD_SANITIZER_LIB",
"")
181 ld_preload = os.environ.get(
"LD_PRELOAD",
"")
182 if sanitizer
and sanitizer
not in ld_preload:
184 os.environ[
"LD_PRELOAD"] = sanitizer +
" " + ld_preload
186 os.environ[
"LD_PRELOAD"] = sanitizer
189 logging.debug(
"processing %s", filename)
190 if filename.endswith(
"_test.py"):
191 indexFilePart = filename.rfind(
"/")
192 fileToImport = filename[indexFilePart + 1 :]
193 sys.path.append(GT.RationalizePath(filename)[: -len(fileToImport) - 1])
194 imp = __import__(fileToImport[:-3])
195 fileToExec = imp.Test()
196 results = fileToExec.run()
197 elif filename.endswith(
".qmt"):
200 test_module = os.environ.get(
"GAUDI_QMTEST_MODULE",
"GaudiTesting.QMTTest")
201 test_class = os.environ.get(
"GAUDI_QMTEST_CLASS",
"QMTTest")
202 test_class = getattr(importlib.import_module(test_module), test_class)
203 fileToTest = test_class(filename)
204 results = fileToTest.run()
206 report = globals()[opts.report +
"_report"]
209 if results.get(
"Status") ==
"failed":
210 logging.debug(
"test failed: unexpected %s",
", ".join(results[
"Causes"]))
211 return int(results.get(
"Exit Code",
"1"))
212 elif results.get(
"Status") ==
"skipped":
213 return opts.skip_return_code
217 if __name__ ==
"__main__":