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 import inspect | 5 import inspect |
| 6 | 6 |
| 7 EXPECT_TESTS_COVER_FUNCTION = 'EXPECT_TESTS_COVER_FUNCTION' | 7 EXPECT_TESTS_COVER_FUNCTION = 'EXPECT_TESTS_COVER_FUNCTION' |
|
Vadim Sh.
2014/06/30 17:15:46
constant for this seems to be an overkill :) but a
| |
| 8 EXPECT_TESTS_GENERATOR = 'EXPECT_TESTS_GENERATOR' | |
| 8 | 9 |
| 9 def covers(coverage_path_function): | 10 def covers(coverage_path_function): |
| 10 """Allows annotation of a Test generator function with a function that will | 11 """Allows annotation of a Test generator function with a function that will |
| 11 return a list of coverage patterns which should be enabled during the use of | 12 return a list of coverage patterns which should be enabled during the use of |
| 12 the Test generator function. | 13 the Test generator function. |
| 13 """ | 14 """ |
| 14 def _decorator(func): | 15 def _decorator(func): |
| 15 setattr(func, EXPECT_TESTS_COVER_FUNCTION, coverage_path_function) | 16 setattr(func, EXPECT_TESTS_COVER_FUNCTION, coverage_path_function) |
| 16 return func | 17 return func |
| 17 return _decorator | 18 return _decorator |
| 18 | 19 |
| 19 | 20 |
| 20 def get_cover_list(test_gen_function): | 21 def get_cover_list(test_gen_function): |
| 21 """Given a Test generator, return the list of coverage globs that should | 22 """Given a Test generator, return the list of coverage globs that should |
| 22 be included while executing the Test generator.""" | 23 be included while executing the Test generator.""" |
| 23 if hasattr(test_gen_function, EXPECT_TESTS_COVER_FUNCTION): | 24 return getattr(test_gen_function, EXPECT_TESTS_COVER_FUNCTION, |
| 24 # decorated with expect_tests.covers | 25 lambda: [inspect.getabsfile(test_gen_function)])() |
| 25 return test_gen_function._covers() # pylint: disable=W0212 | 26 |
| 26 else: | 27 |
| 27 return [inspect.getabsfile(test_gen_function)] | 28 def test_generator(function): |
| 29 """Marks function as an expect_tests Test generator""" | |
| 30 setattr(function, EXPECT_TESTS_GENERATOR, True) | |
| 31 return function | |
| 32 | |
| 33 | |
| 34 def is_test_generator(function): | |
| 35 return getattr(function, EXPECT_TESTS_GENERATOR, False) | |
| OLD | NEW |