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
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".