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