Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 from expect_tests.type_definitions import Handler | 5 from expect_tests.type_definitions import Handler, Test, FakeTest, MultiTest |
|
dnj
2014/09/12 17:35:37
Since FakeTest is only generated/used here, it wou
pgervais
2014/09/12 21:28:30
True, but I'd rather keep all definitions together
dnj
2014/09/12 21:35:06
I see your your point. As a counterpoint, I think
| |
| 6 | 6 |
| 7 | 7 |
| 8 class ListHandler(Handler): | 8 class ListHandler(Handler): |
| 9 """List all of the tests instead of running them.""" | 9 """List all of the tests instead of running them.""" |
| 10 SKIP_RUNLOOP = True | 10 SKIP_RUNLOOP = True |
| 11 | 11 |
| 12 # Used to collect all bare test names for command line test name completion. | 12 # Used to collect all bare test names for command line test name completion. |
| 13 COMPLETION_LIST = None | 13 COMPLETION_LIST = None |
| 14 | 14 |
| 15 class ResultStageHandler(Handler.ResultStageHandler): | 15 class ResultStageHandler(Handler.ResultStageHandler): |
| 16 @staticmethod | 16 @staticmethod |
| 17 def handle_Test(test): | 17 def handle_FakeTest(test): |
| 18 if ListHandler.COMPLETION_LIST is not None: | 18 if ListHandler.COMPLETION_LIST is not None: |
| 19 ListHandler.COMPLETION_LIST.append(test.name) | 19 ListHandler.COMPLETION_LIST.append(test.name) |
| 20 else: | 20 else: |
| 21 print test.name | 21 print test.name |
| 22 | 22 |
| 23 @staticmethod | 23 @staticmethod |
| 24 def handle_MultiTest(multi_test): | 24 def handle_MultiTest(multi_test): |
| 25 print 'MultiTest(%r, atomic=%r)' % (multi_test.name, multi_test.atomic) | 25 print 'MultiTest(%r, atomic=%r)' % (multi_test.name, multi_test.atomic) |
| 26 for test in multi_test.tests: | 26 for test in multi_test.tests: |
| 27 if ListHandler.COMPLETION_LIST is not None: | 27 if ListHandler.COMPLETION_LIST is not None: |
| 28 ListHandler.COMPLETION_LIST.append(test.name) | 28 ListHandler.COMPLETION_LIST.append(test.name) |
| 29 else: | 29 else: |
| 30 print '|', test.name | 30 print '|', test.name |
| 31 | 31 |
| 32 # TODO(iannucci): group tests by dir? | 32 # TODO(iannucci): group tests by dir? |
| 33 # TODO(iannucci): print more data about the test in verbose mode? | 33 # TODO(iannucci): print more data about the test in verbose mode? |
| 34 | |
| 35 @classmethod | |
| 36 def gen_stage_loop(cls, _opts, tests, put_next_stage, _put_result_stage): | |
| 37 """Called in the GenStage portion of the pipeline. | |
| 38 | |
| 39 @param opts: Parsed CLI options | |
| 40 @param tests: | |
| 41 Iterable of type_definitions.Test or type_definitions.MultiTest | |
| 42 objects. | |
| 43 @param put_next_stage: | |
| 44 Function to push an object to the next stage of the pipeline (RunStage). | |
| 45 Note that you should push the item you got from |tests|, not the | |
| 46 subtests, in the case that the item is a MultiTest. | |
| 47 @param put_result_stage: | |
| 48 Function to push an object to the result stage of the pipeline. | |
| 49 """ | |
| 50 for test in tests: | |
| 51 if isinstance(test, Test): | |
| 52 test = FakeTest(name=test.name, | |
| 53 func_call=None, | |
| 54 expect_dir=test.expect_dir, | |
| 55 expect_base=test.expect_base, | |
| 56 ext=test.ext, | |
| 57 covers=None, | |
| 58 breakpoints=None) | |
| 59 | |
| 60 elif isinstance(test, MultiTest): | |
| 61 all_tests = [FakeTest(name=one_test.name, | |
| 62 func_call=None, | |
| 63 expect_dir=one_test.expect_dir, | |
| 64 expect_base=one_test.expect_base, | |
| 65 ext=one_test.ext, | |
| 66 covers=None, | |
| 67 breakpoints=None) | |
| 68 for one_test in test.tests] | |
| 69 | |
| 70 test = MultiTest(name=test.name, | |
| 71 make_ctx_call=None, | |
| 72 destroy_ctx_call=None, | |
| 73 tests=all_tests, | |
| 74 atomic=test.atomic | |
| 75 ) | |
|
dnj
2014/09/12 17:35:37
Maybe put a TypeError guard up in case someone cre
pgervais
2014/09/12 21:28:31
Done.
| |
| 76 | |
| 77 put_next_stage(test) | |
| OLD | NEW |