Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(256)

Side by Side Diff: typ/runner.py

Issue 2322963004: Clean up formatting, rework run wrapper script to not use globals. (Closed)
Patch Set: update w/ review feedback, lint Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « typ/fakes/test_result_server_fake.py ('k') | typ/tests/main_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2014 Google Inc. All rights reserved. 1 # Copyright 2014 Google Inc. All rights reserved.
2 # 2 #
3 # Licensed under the Apache License, Version 2.0 (the "License"); 3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License. 4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at 5 # You may obtain a copy of the License at
6 # 6 #
7 # http://www.apache.org/licenses/LICENSE-2.0 7 # http://www.apache.org/licenses/LICENSE-2.0
8 # 8 #
9 # Unless required by applicable law or agreed to in writing, software 9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, 10 # distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 except _AddTestsError as e: 350 except _AddTestsError as e:
351 self.print_(str(e)) 351 self.print_(str(e))
352 return 1, None 352 return 1, None
353 353
354 # TODO: Add support for discovering setupProcess/teardownProcess? 354 # TODO: Add support for discovering setupProcess/teardownProcess?
355 355
356 shard_index = args.shard_index 356 shard_index = args.shard_index
357 total_shards = args.total_shards 357 total_shards = args.total_shards
358 assert total_shards >= 1 358 assert total_shards >= 1
359 assert shard_index >= 0 and shard_index < total_shards, ( 359 assert shard_index >= 0 and shard_index < total_shards, (
360 'shard_index (%d) must be >= 0 and < total_shards (%d)' % 360 'shard_index (%d) must be >= 0 and < total_shards (%d)' %
361 (shard_index, total_shards)) 361 (shard_index, total_shards))
362 test_set.parallel_tests = _sort_inputs( 362 test_set.parallel_tests = _sort_inputs(
363 test_set.parallel_tests)[shard_index::total_shards] 363 test_set.parallel_tests)[shard_index::total_shards]
364 test_set.isolated_tests = _sort_inputs( 364 test_set.isolated_tests = _sort_inputs(
365 test_set.isolated_tests)[shard_index::total_shards] 365 test_set.isolated_tests)[shard_index::total_shards]
366 test_set.tests_to_skip = _sort_inputs( 366 test_set.tests_to_skip = _sort_inputs(
367 test_set.tests_to_skip)[shard_index::total_shards] 367 test_set.tests_to_skip)[shard_index::total_shards]
368 return 0, test_set 368 return 0, test_set
369 finally: 369 finally:
370 unittest.skip = orig_skip 370 unittest.skip = orig_skip
371 unittest.skipIf = orig_skip_if 371 unittest.skipIf = orig_skip_if
(...skipping 28 matching lines...) Expand all
400 add_tests(loader.discover(name, suffix, top_level_dir)) 400 add_tests(loader.discover(name, suffix, top_level_dir))
401 else: 401 else:
402 possible_dir = name.replace('.', h.sep) 402 possible_dir = name.replace('.', h.sep)
403 if h.isdir(top_level_dir, possible_dir): 403 if h.isdir(top_level_dir, possible_dir):
404 for suffix in suffixes: 404 for suffix in suffixes:
405 path = h.join(top_level_dir, possible_dir) 405 path = h.join(top_level_dir, possible_dir)
406 suite = loader.discover(path, suffix, top_level_dir) 406 suite = loader.discover(path, suffix, top_level_dir)
407 add_tests(suite) 407 add_tests(suite)
408 else: 408 else:
409 add_tests(loader.loadTestsFromName(name)) 409 add_tests(loader.loadTestsFromName(name))
410
411 # pylint: disable=no-member
410 if hasattr(loader, 'errors') and loader.errors: 412 if hasattr(loader, 'errors') and loader.errors:
411 # In Python3's version of unittest, loader failures get converted 413 # In Python3's version of unittest, loader failures get converted
412 # into failed test cases, rather than raising exceptions. However, 414 # into failed test cases, rather than raising exceptions. However,
413 # the errors also get recorded so you can err out immediately. 415 # the errors also get recorded so you can err out immediately.
414 raise ImportError(loader.errors) 416 raise ImportError(loader.errors)
415 417
416 def _run_tests(self, result_set, test_set): 418 def _run_tests(self, result_set, test_set):
417 h = self.host 419 h = self.host
418 if not test_set.parallel_tests and not test_set.isolated_tests: 420 if not test_set.parallel_tests and not test_set.isolated_tests:
419 self.print_('No tests to run.') 421 self.print_('No tests to run.')
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 return new_suite 945 return new_suite
944 946
945 947
946 def _sort_inputs(inps): 948 def _sort_inputs(inps):
947 return sorted(inps, key=lambda inp: inp.name) 949 return sorted(inps, key=lambda inp: inp.name)
948 950
949 951
950 if __name__ == '__main__': # pragma: no cover 952 if __name__ == '__main__': # pragma: no cover
951 sys.modules['__main__'].__file__ = path_to_file 953 sys.modules['__main__'].__file__ = path_to_file
952 sys.exit(main(win_multiprocessing=WinMultiprocessing.importable)) 954 sys.exit(main(win_multiprocessing=WinMultiprocessing.importable))
OLDNEW
« no previous file with comments | « typ/fakes/test_result_server_fake.py ('k') | typ/tests/main_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698