diff options
author | Aníbal Limón <anibal.limon@linux.intel.com> | 2017-05-26 15:37:44 -0500 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2017-06-02 13:36:14 +0100 |
commit | 49223c47fc20ed4215cf82831a07dae6a1793dd0 (patch) | |
tree | 0e88aaa39cda1c00483364e33d6facfebb40aeff /meta/lib/oeqa/core/runner.py | |
parent | adc434c0636b7dea2ef70c8d2c8e61cdb5c703b1 (diff) | |
download | poky-49223c47fc20ed4215cf82831a07dae6a1793dd0.tar.gz |
oeqa/core: Add list tests support in context and runner
A common operation is to list tests, currently only selftest
support it, this changes enables this functionality into the
core framework.
(From OE-Core rev: 7e803f1a855d3091a772b13efd3cc8e9c0c766e9)
Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oeqa/core/runner.py')
-rw-r--r-- | meta/lib/oeqa/core/runner.py | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/meta/lib/oeqa/core/runner.py b/meta/lib/oeqa/core/runner.py index 3ebffc7c4c..7ce718e784 100644 --- a/meta/lib/oeqa/core/runner.py +++ b/meta/lib/oeqa/core/runner.py | |||
@@ -134,6 +134,10 @@ class OETestResult(_TestResult): | |||
134 | self.tc.logger.info("RESULTS - %s - Testcase %s: %s" % (case.id(), | 134 | self.tc.logger.info("RESULTS - %s - Testcase %s: %s" % (case.id(), |
135 | oeid, 'PASSED')) | 135 | oeid, 'PASSED')) |
136 | 136 | ||
137 | class OEListTestsResult(object): | ||
138 | def wasSuccessful(self): | ||
139 | return True | ||
140 | |||
137 | class OETestRunner(_TestRunner): | 141 | class OETestRunner(_TestRunner): |
138 | streamLoggerClass = OEStreamLogger | 142 | streamLoggerClass = OEStreamLogger |
139 | 143 | ||
@@ -164,3 +168,97 @@ class OETestRunner(_TestRunner): | |||
164 | def _makeResult(self): | 168 | def _makeResult(self): |
165 | return self.resultclass(self.tc, self.stream, self.descriptions, | 169 | return self.resultclass(self.tc, self.stream, self.descriptions, |
166 | self.verbosity) | 170 | self.verbosity) |
171 | |||
172 | |||
173 | def _walk_suite(self, suite, func): | ||
174 | for obj in suite: | ||
175 | if isinstance(obj, unittest.suite.TestSuite): | ||
176 | if len(obj._tests): | ||
177 | self._walk_suite(obj, func) | ||
178 | elif isinstance(obj, unittest.case.TestCase): | ||
179 | func(self.tc.logger, obj) | ||
180 | self._walked_cases = self._walked_cases + 1 | ||
181 | |||
182 | def _list_tests_name(self, suite): | ||
183 | from oeqa.core.decorator.oeid import OETestID | ||
184 | from oeqa.core.decorator.oetag import OETestTag | ||
185 | |||
186 | self._walked_cases = 0 | ||
187 | |||
188 | def _list_cases_without_id(logger, case): | ||
189 | |||
190 | found_id = False | ||
191 | for d in case.decorators: | ||
192 | if isinstance(d, OETestID): | ||
193 | found_id = True | ||
194 | |||
195 | if not found_id: | ||
196 | logger.info('oeid missing for %s' % case.id()) | ||
197 | |||
198 | def _list_cases(logger, case): | ||
199 | oeid = None | ||
200 | oetag = None | ||
201 | |||
202 | for d in case.decorators: | ||
203 | if isinstance(d, OETestID): | ||
204 | oeid = d.oeid | ||
205 | elif isinstance(d, OETestTag): | ||
206 | oetag = d.oetag | ||
207 | |||
208 | logger.info("%s\t%s\t\t%s" % (oeid, oetag, case.id())) | ||
209 | |||
210 | self.tc.logger.info("Listing test cases that don't have oeid ...") | ||
211 | self._walk_suite(suite, _list_cases_without_id) | ||
212 | self.tc.logger.info("-" * 80) | ||
213 | |||
214 | self.tc.logger.info("Listing all available tests:") | ||
215 | self._walked_cases = 0 | ||
216 | self.tc.logger.info("id\ttag\t\ttest") | ||
217 | self.tc.logger.info("-" * 80) | ||
218 | self._walk_suite(suite, _list_cases) | ||
219 | self.tc.logger.info("-" * 80) | ||
220 | self.tc.logger.info("Total found:\t%s" % self._walked_cases) | ||
221 | |||
222 | def _list_tests_class(self, suite): | ||
223 | self._walked_cases = 0 | ||
224 | |||
225 | curr = {} | ||
226 | def _list_classes(logger, case): | ||
227 | if not 'module' in curr or curr['module'] != case.__module__: | ||
228 | curr['module'] = case.__module__ | ||
229 | logger.info(curr['module']) | ||
230 | |||
231 | if not 'class' in curr or curr['class'] != \ | ||
232 | case.__class__.__name__: | ||
233 | curr['class'] = case.__class__.__name__ | ||
234 | logger.info(" -- %s" % curr['class']) | ||
235 | |||
236 | logger.info(" -- -- %s" % case._testMethodName) | ||
237 | |||
238 | self.tc.logger.info("Listing all available test classes:") | ||
239 | self._walk_suite(suite, _list_classes) | ||
240 | |||
241 | def _list_tests_module(self, suite): | ||
242 | self._walked_cases = 0 | ||
243 | |||
244 | listed = [] | ||
245 | def _list_modules(logger, case): | ||
246 | if not case.__module__ in listed: | ||
247 | if case.__module__.startswith('_'): | ||
248 | logger.info("%s (hidden)" % case.__module__) | ||
249 | else: | ||
250 | logger.info(case.__module__) | ||
251 | listed.append(case.__module__) | ||
252 | |||
253 | self.tc.logger.info("Listing all available test modules:") | ||
254 | self._walk_suite(suite, _list_modules) | ||
255 | |||
256 | def list_tests(self, suite, display_type): | ||
257 | if display_type == 'name': | ||
258 | self._list_tests_name(suite) | ||
259 | elif display_type == 'class': | ||
260 | self._list_tests_class(suite) | ||
261 | elif display_type == 'module': | ||
262 | self._list_tests_module(suite) | ||
263 | |||
264 | return OEListTestsResult() | ||