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