12 from __future__
import print_function
18 import xml.sax.saxutils
as XSS
20 from GaudiTesting
import BaseTest
as GT
23 sys.modules[
"GaudiTest"] = GT
28 Report function taking the dictionary from BasicTest.run() and display
29 stdout and stderr from it.
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"]))
43 Do not report anything from the result of the test.
50 Report function taking the dictionary from BasicTest.run() and report data
51 from it in a CTest-friendly way.
54 print(
"CTEST_FULL_OUTPUT")
55 print(results.get(
"stdout",
""))
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),
65 ignore = set([
"Status",
"Name",
"stdout",
"Exit Code"])
66 template =
'<DartMeasurement type="text/string" name="{0}">{1}</DartMeasurement>'
71 hndlr = handler.get(key, id_handler)
72 data = XSS.escape(GT.sanitize_for_xml(hndlr(results[key])))
73 print(template.format(key, data))
78 Report function taking the dictionary from BasicTest.run() and print it with
81 from pprint
import pprint
88 Main function of the script.
90 from optparse
import OptionGroup, OptionParser
92 parser = OptionParser()
97 choices=[n.replace(
"_report",
"")
for n
in globals()
if n.endswith(
"_report")],
98 help=
"choose a report method [default %default]",
103 help=
"directory to be used as common temporary directory",
109 help=
"directory to change to before starting the test",
113 "--skip-return-code",
115 help=
"return code to use to flag a test as skipped " "[default %default]",
118 verbosity_opts = OptionGroup(
119 parser,
"Verbosity Level",
"set the verbosity level of messages"
121 verbosity_opts.add_option(
123 action=
"store_const",
125 const=logging.CRITICAL,
126 help=
"only critical error messages",
128 verbosity_opts.add_option(
130 action=
"store_const",
133 help=
"error messages",
135 verbosity_opts.add_option(
137 action=
"store_const",
139 const=logging.WARNING,
140 help=
"warning and error messages",
142 verbosity_opts.add_option(
144 action=
"store_const",
147 help=
"progress information messages",
149 verbosity_opts.add_option(
151 action=
"store_const",
154 help=
"debugging messages",
156 parser.add_option_group(verbosity_opts)
159 log_level=logging.WARNING, report=
"basic", workdir=os.curdir, skip_return_code=0
162 opts, args = parser.parse_args()
164 parser.error(
"only one test allowed")
167 logging.basicConfig(level=opts.log_level)
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
174 os.chdir(opts.workdir)
177 if "slc6" in (os.environ.get(
"BINARY_TAG",
"")
or os.environ.get(
"CMTCONFIG",
"")):
178 os.environ[
"TERM"] =
"dumb"
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:
185 os.environ[
"LD_PRELOAD"] = sanitizer +
" " + ld_preload
187 os.environ[
"LD_PRELOAD"] = sanitizer
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"):
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()
207 report = globals()[opts.report +
"_report"]
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
218 if __name__ ==
"__main__":