diff options
-rw-r--r-- | meta/lib/oeqa/core/context.py | 22 | ||||
-rw-r--r-- | meta/lib/oeqa/core/runner.py | 98 |
2 files changed, 115 insertions, 5 deletions
diff --git a/meta/lib/oeqa/core/context.py b/meta/lib/oeqa/core/context.py index 54958add07..bc958d0dfe 100644 --- a/meta/lib/oeqa/core/context.py +++ b/meta/lib/oeqa/core/context.py | |||
@@ -58,6 +58,10 @@ class OETestContext(object): | |||
58 | 58 | ||
59 | return result | 59 | return result |
60 | 60 | ||
61 | def listTests(self, display_type): | ||
62 | self.runner = self.runnerClass(self, verbosity=2) | ||
63 | return self.runner.list_tests(self.suites, display_type) | ||
64 | |||
61 | class OETestContextExecutor(object): | 65 | class OETestContextExecutor(object): |
62 | _context_class = OETestContext | 66 | _context_class = OETestContext |
63 | 67 | ||
@@ -79,9 +83,14 @@ class OETestContextExecutor(object): | |||
79 | self.parser.add_argument('--output-log', action='store', | 83 | self.parser.add_argument('--output-log', action='store', |
80 | default=self.default_output_log, | 84 | default=self.default_output_log, |
81 | help="results output log, default: %s" % self.default_output_log) | 85 | help="results output log, default: %s" % self.default_output_log) |
82 | self.parser.add_argument('--run-tests', action='store', | 86 | |
87 | group = self.parser.add_mutually_exclusive_group() | ||
88 | group.add_argument('--run-tests', action='store', | ||
83 | default=self.default_tests, | 89 | default=self.default_tests, |
84 | help="tests to run in <module>[.<class>[.<name>]] format. Just works for modules now") | 90 | help="tests to run in <module>[.<class>[.<name>]] format. Just works for modules now") |
91 | group.add_argument('--list-tests', action='store', | ||
92 | choices=('module', 'class', 'name'), | ||
93 | help="lists available tests") | ||
85 | 94 | ||
86 | if self.default_test_data: | 95 | if self.default_test_data: |
87 | self.parser.add_argument('--test-data-file', action='store', | 96 | self.parser.add_argument('--test-data-file', action='store', |
@@ -126,7 +135,6 @@ class OETestContextExecutor(object): | |||
126 | else: | 135 | else: |
127 | self.tc_kwargs['init']['td'] = {} | 136 | self.tc_kwargs['init']['td'] = {} |
128 | 137 | ||
129 | |||
130 | if args.run_tests: | 138 | if args.run_tests: |
131 | self.tc_kwargs['load']['modules'] = args.run_tests.split() | 139 | self.tc_kwargs['load']['modules'] = args.run_tests.split() |
132 | else: | 140 | else: |
@@ -139,9 +147,13 @@ class OETestContextExecutor(object): | |||
139 | 147 | ||
140 | self.tc = self._context_class(**self.tc_kwargs['init']) | 148 | self.tc = self._context_class(**self.tc_kwargs['init']) |
141 | self.tc.loadTests(self.module_paths, **self.tc_kwargs['load']) | 149 | self.tc.loadTests(self.module_paths, **self.tc_kwargs['load']) |
142 | rc = self.tc.runTests(**self.tc_kwargs['run']) | 150 | |
143 | rc.logSummary(self.name) | 151 | if args.list_tests: |
144 | rc.logDetails() | 152 | rc = self.tc.listTests(args.list_tests, **self.tc_kwargs['run']) |
153 | else: | ||
154 | rc = self.tc.runTests(**self.tc_kwargs['run']) | ||
155 | rc.logSummary(self.name) | ||
156 | rc.logDetails() | ||
145 | 157 | ||
146 | output_link = os.path.join(os.path.dirname(args.output_log), | 158 | output_link = os.path.join(os.path.dirname(args.output_log), |
147 | "%s-results.log" % self.name) | 159 | "%s-results.log" % self.name) |
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() | ||