| OLD | NEW |
| 1 # Copyright (C) 2012 Google, Inc. | 1 # Copyright (C) 2012 Google, Inc. |
| 2 # Copyright (C) 2010 Chris Jerdonek (cjerdonek@webkit.org) | 2 # Copyright (C) 2010 Chris Jerdonek (cjerdonek@webkit.org) |
| 3 # | 3 # |
| 4 # Redistribution and use in source and binary forms, with or without | 4 # Redistribution and use in source and binary forms, with or without |
| 5 # modification, are permitted provided that the following conditions | 5 # modification, are permitted provided that the following conditions |
| 6 # are met: | 6 # are met: |
| 7 # 1. Redistributions of source code must retain the above copyright | 7 # 1. Redistributions of source code must retain the above copyright |
| 8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
| 9 # 2. Redistributions in binary form must reproduce the above copyright | 9 # 2. Redistributions in binary form must reproduce the above copyright |
| 10 # notice, this list of conditions and the following disclaimer in the | 10 # notice, this list of conditions and the following disclaimer in the |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 exit_code = self.executive.call(prefix_cmd + ['report', '--omit', 'w
ebkitpy/thirdparty/*,/usr/*,/Library/*'], cwd=script_dir, env=env) | 158 exit_code = self.executive.call(prefix_cmd + ['report', '--omit', 'w
ebkitpy/thirdparty/*,/usr/*,/Library/*'], cwd=script_dir, env=env) |
| 159 return (exit_code == 0) | 159 return (exit_code == 0) |
| 160 | 160 |
| 161 def _run_tests(self, names): | 161 def _run_tests(self, names): |
| 162 self.printer.write_update("Checking imports ...") | 162 self.printer.write_update("Checking imports ...") |
| 163 if not self._check_imports(names): | 163 if not self._check_imports(names): |
| 164 return False | 164 return False |
| 165 | 165 |
| 166 self.printer.write_update("Finding the individual test methods ...") | 166 self.printer.write_update("Finding the individual test methods ...") |
| 167 loader = _Loader() | 167 loader = _Loader() |
| 168 parallel_tests, serial_tests = self._test_names(loader, names) | 168 parallel_tests = self._test_names(loader, names) |
| 169 | 169 |
| 170 self.printer.write_update("Running the tests ...") | 170 self.printer.write_update("Running the tests ...") |
| 171 self.printer.num_tests = len(parallel_tests) + len(serial_tests) | 171 self.printer.num_tests = len(parallel_tests) |
| 172 start = time.time() | 172 start = time.time() |
| 173 test_runner = Runner(self.printer, loader, self.webkit_finder) | 173 test_runner = Runner(self.printer, loader, self.webkit_finder) |
| 174 test_runner.run(parallel_tests, self._options.child_processes) | 174 test_runner.run(parallel_tests, self._options.child_processes) |
| 175 test_runner.run(serial_tests, 1) | |
| 176 | 175 |
| 177 self.printer.print_result(time.time() - start) | 176 self.printer.print_result(time.time() - start) |
| 178 | 177 |
| 179 return not self.printer.num_errors and not self.printer.num_failures | 178 return not self.printer.num_errors and not self.printer.num_failures |
| 180 | 179 |
| 181 def _check_imports(self, names): | 180 def _check_imports(self, names): |
| 182 for name in names: | 181 for name in names: |
| 183 if self.finder.is_module(name): | 182 if self.finder.is_module(name): |
| 184 # if we failed to load a name and it looks like a module, | 183 # if we failed to load a name and it looks like a module, |
| 185 # try importing it directly, because loadTestsFromName() | 184 # try importing it directly, because loadTestsFromName() |
| 186 # produces lousy error messages for bad modules. | 185 # produces lousy error messages for bad modules. |
| 187 try: | 186 try: |
| 188 __import__(name) | 187 __import__(name) |
| 189 except ImportError: | 188 except ImportError: |
| 190 _log.fatal('Failed to import %s:' % name) | 189 _log.fatal('Failed to import %s:' % name) |
| 191 self._log_exception() | 190 self._log_exception() |
| 192 return False | 191 return False |
| 193 return True | 192 return True |
| 194 | 193 |
| 195 def _test_names(self, loader, names): | 194 def _test_names(self, loader, names): |
| 196 parallel_test_method_prefixes = ['test_'] | 195 parallel_test_method_prefixes = ['test_'] |
| 197 serial_test_method_prefixes = ['serial_test_'] | |
| 198 | 196 |
| 199 parallel_tests = [] | 197 parallel_tests = [] |
| 200 loader.test_method_prefixes = parallel_test_method_prefixes | 198 loader.test_method_prefixes = parallel_test_method_prefixes |
| 201 for name in names: | 199 for name in names: |
| 202 parallel_tests.extend(self._all_test_names(loader.loadTestsFromName(
name, None))) | 200 parallel_tests.extend(self._all_test_names(loader.loadTestsFromName(
name, None))) |
| 203 | 201 |
| 204 serial_tests = [] | 202 return parallel_tests |
| 205 loader.test_method_prefixes = serial_test_method_prefixes | |
| 206 for name in names: | |
| 207 serial_tests.extend(self._all_test_names(loader.loadTestsFromName(na
me, None))) | |
| 208 | |
| 209 # loader.loadTestsFromName() will not verify that names begin with one o
f the test_method_prefixes | |
| 210 # if the names were explicitly provided (e.g., MainTest.test_basic), so
this means that any individual | |
| 211 # tests will be included in both parallel_tests and serial_tests, and we
need to de-dup them. | |
| 212 serial_tests = list(set(serial_tests).difference(set(parallel_tests))) | |
| 213 | |
| 214 return (parallel_tests, serial_tests) | |
| 215 | 203 |
| 216 def _all_test_names(self, suite): | 204 def _all_test_names(self, suite): |
| 217 names = [] | 205 names = [] |
| 218 if hasattr(suite, '_tests'): | 206 if hasattr(suite, '_tests'): |
| 219 for t in suite._tests: | 207 for t in suite._tests: |
| 220 names.extend(self._all_test_names(t)) | 208 names.extend(self._all_test_names(t)) |
| 221 else: | 209 else: |
| 222 names.append(unit_test_name(suite)) | 210 names.append(unit_test_name(suite)) |
| 223 return names | 211 return names |
| 224 | 212 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 237 if not hasattr(getattr(testCaseClass, attrname), '__call__'): | 225 if not hasattr(getattr(testCaseClass, attrname), '__call__'): |
| 238 return False | 226 return False |
| 239 return (any(attrname.startswith(prefix) for prefix in self.test_meth
od_prefixes)) | 227 return (any(attrname.startswith(prefix) for prefix in self.test_meth
od_prefixes)) |
| 240 testFnNames = filter(isTestMethod, dir(testCaseClass)) | 228 testFnNames = filter(isTestMethod, dir(testCaseClass)) |
| 241 testFnNames.sort() | 229 testFnNames.sort() |
| 242 return testFnNames | 230 return testFnNames |
| 243 | 231 |
| 244 | 232 |
| 245 if __name__ == '__main__': | 233 if __name__ == '__main__': |
| 246 sys.exit(main()) | 234 sys.exit(main()) |
| OLD | NEW |