16 import xml.sax.saxutils
as XSS
18 from GaudiTesting
import BaseTest
as GT
21 sys.modules[
"GaudiTest"] = GT
26 Report function taking the dictionary from BasicTest.run() and display
27 stdout and stderr from it.
29 print(
"=== stdout ===")
30 print(results.get(
"stdout",
""))
31 print(
"=== stderr ===")
32 print(results.get(
"stderr",
""))
33 print(
"=== result ===")
34 print(results.get(
"Status"))
35 if results.get(
"Status") !=
"passed" and "Causes" in results:
36 print(
" ",
"unexpected " +
", ".join(results[
"Causes"]))
41 Do not report anything from the result of the test.
48 Report function taking the dictionary from BasicTest.run() and report data
49 from it in a CTest-friendly way.
52 print(
"CTEST_FULL_OUTPUT")
53 print(results.get(
"stdout",
""))
55 "Runtime Environment":
lambda v:
"<pre>%s</pre>"
56 %
"\n".join(
"{0}={1}".
format(*item)
for item
in sorted(v.items())),
57 "Causes":
lambda v:
"unexpected " +
", ".join(v),
63 ignore = set([
"Status",
"Name",
"stdout",
"Exit Code"])
64 template =
'<DartMeasurement type="text/string" name="{0}">{1}</DartMeasurement>'
69 hndlr = handler.get(key, id_handler)
70 data = XSS.escape(GT.sanitize_for_xml(hndlr(results[key])))
71 print(template.format(key, data))
76 Report function taking the dictionary from BasicTest.run() and print it with
79 from pprint
import pprint
86 Main function of the script.
88 from optparse
import OptionGroup, OptionParser
90 parser = OptionParser()
95 choices=[n.replace(
"_report",
"")
for n
in globals()
if n.endswith(
"_report")],
96 help=
"choose a report method [default %default]",
101 help=
"directory to be used as common temporary directory",
107 help=
"directory to change to before starting the test",
111 "--skip-return-code",
113 help=
"return code to use to flag a test as skipped " "[default %default]",
116 verbosity_opts = OptionGroup(
117 parser,
"Verbosity Level",
"set the verbosity level of messages"
119 verbosity_opts.add_option(
121 action=
"store_const",
123 const=logging.CRITICAL,
124 help=
"only critical error messages",
126 verbosity_opts.add_option(
128 action=
"store_const",
131 help=
"error messages",
133 verbosity_opts.add_option(
135 action=
"store_const",
137 const=logging.WARNING,
138 help=
"warning and error messages",
140 verbosity_opts.add_option(
142 action=
"store_const",
145 help=
"progress information messages",
147 verbosity_opts.add_option(
149 action=
"store_const",
152 help=
"debugging messages",
154 parser.add_option_group(verbosity_opts)
157 log_level=logging.WARNING, report=
"basic", workdir=os.curdir, skip_return_code=0
160 opts, args = parser.parse_args()
162 parser.error(
"only one test allowed")
165 logging.basicConfig(level=opts.log_level)
167 if opts.common_tmpdir:
168 if not os.path.isdir(opts.common_tmpdir):
169 os.makedirs(opts.common_tmpdir)
170 GT.BaseTest._common_tmpdir = opts.common_tmpdir
172 os.chdir(opts.workdir)
175 if "slc6" in (os.environ.get(
"BINARY_TAG",
"")
or os.environ.get(
"CMTCONFIG",
"")):
176 os.environ[
"TERM"] =
"dumb"
179 sanitizer = os.environ.get(
"PRELOAD_SANITIZER_LIB",
"")
180 ld_preload = os.environ.get(
"LD_PRELOAD",
"")
181 if sanitizer
and sanitizer
not in ld_preload:
183 os.environ[
"LD_PRELOAD"] = sanitizer +
" " + ld_preload
185 os.environ[
"LD_PRELOAD"] = sanitizer
188 logging.debug(
"processing %s", filename)
189 if filename.endswith(
"_test.py"):
190 indexFilePart = filename.rfind(
"/")
191 fileToImport = filename[indexFilePart + 1 :]
192 sys.path.append(GT.RationalizePath(filename)[: -len(fileToImport) - 1])
193 imp = __import__(fileToImport[:-3])
194 fileToExec = imp.Test()
195 results = fileToExec.run()
196 elif filename.endswith(
".qmt"):
199 test_module = os.environ.get(
"GAUDI_QMTEST_MODULE",
"GaudiTesting.QMTTest")
200 test_class = os.environ.get(
"GAUDI_QMTEST_CLASS",
"QMTTest")
201 test_class = getattr(importlib.import_module(test_module), test_class)
202 fileToTest = test_class(filename)
203 results = fileToTest.run()
205 report = globals()[opts.report +
"_report"]
208 if results.get(
"Status") ==
"failed":
209 logging.debug(
"test failed: unexpected %s",
", ".join(results[
"Causes"]))
210 return int(results.get(
"Exit Code",
"1"))
211 elif results.get(
"Status") ==
"skipped":
212 return opts.skip_return_code
216 if __name__ ==
"__main__":