OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 """Module containing information about the host-driven tests.""" | 5 """Module containing information about the host-driven tests.""" |
6 | 6 |
7 import logging | 7 import logging |
8 import os | 8 import os |
| 9 import sys |
9 | 10 |
10 import tests_annotations | 11 import tests_annotations |
11 | 12 |
| 13 from pylib import constants |
| 14 |
| 15 sys.path.insert(0, |
| 16 os.path.join(constants.DIR_SOURCE_ROOT, |
| 17 'build', 'util', 'lib', 'common')) |
| 18 |
| 19 import unittest_util |
12 | 20 |
13 class TestInfo(object): | 21 class TestInfo(object): |
14 """An object containing and representing a test function, plus metadata.""" | 22 """An object containing and representing a test function, plus metadata.""" |
15 | 23 |
16 def __init__(self, runnable, set_up=None, tear_down=None): | 24 def __init__(self, runnable, set_up=None, tear_down=None): |
17 # The actual test function/method. | 25 # The actual test function/method. |
18 self.runnable = runnable | 26 self.runnable = runnable |
19 # Qualified name of test function/method (e.g. FooModule.testBar). | 27 # Qualified name of test function/method (e.g. FooModule.testBar). |
20 self.qualified_name = self._GetQualifiedName(runnable) | 28 self.qualified_name = self._GetQualifiedName(runnable) |
21 # setUp and teardown functions, if any. | 29 # setUp and teardown functions, if any. |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 t.qualified_name)] | 98 t.qualified_name)] |
91 test_names = [t.qualified_name for t in tests_without_annotation] | 99 test_names = [t.qualified_name for t in tests_without_annotation] |
92 logging.warning('The following tests do not contain any annotation. ' | 100 logging.warning('The following tests do not contain any annotation. ' |
93 'Assuming "SmallTest":\n%s', | 101 'Assuming "SmallTest":\n%s', |
94 '\n'.join(test_names)) | 102 '\n'.join(test_names)) |
95 available_tests += tests_without_annotation | 103 available_tests += tests_without_annotation |
96 if exclude_annotations: | 104 if exclude_annotations: |
97 excluded_tests = [t for t in available_tests if | 105 excluded_tests = [t for t in available_tests if |
98 self._AnnotationIncludesTest(t, exclude_annotations)] | 106 self._AnnotationIncludesTest(t, exclude_annotations)] |
99 available_tests = list(set(available_tests) - set(excluded_tests)) | 107 available_tests = list(set(available_tests) - set(excluded_tests)) |
100 available_tests = [t for t in available_tests if | |
101 self._NameFilterIncludesTest(t, name_filter)] | |
102 | 108 |
| 109 if name_filter: |
| 110 available_test_names = unittest_util.FilterTestNames( |
| 111 [t.qualified_name for t in available_tests], name_filter) |
| 112 available_tests = [ |
| 113 t for t in available_tests if |
| 114 t.qualified_name in available_test_names] |
103 return available_tests | 115 return available_tests |
104 | 116 |
105 def _AnnotationIncludesTest(self, test_info, annotation_filter_list): | 117 def _AnnotationIncludesTest(self, test_info, annotation_filter_list): |
106 """Checks whether a given test represented by test_info matches annotation. | 118 """Checks whether a given test represented by test_info matches annotation. |
107 | 119 |
108 Args: | 120 Args: |
109 test_info: TestInfo object representing the test | 121 test_info: TestInfo object representing the test |
110 annotation_filter_list: list of annotation filters to match (e.g. Smoke) | 122 annotation_filter_list: list of annotation filters to match (e.g. Smoke) |
111 | 123 |
112 Returns: | 124 Returns: |
113 True if no annotation was supplied or the test matches; false otherwise. | 125 True if no annotation was supplied or the test matches; false otherwise. |
114 """ | 126 """ |
115 if not annotation_filter_list: | 127 if not annotation_filter_list: |
116 return True | 128 return True |
117 for annotation_filter in annotation_filter_list: | 129 for annotation_filter in annotation_filter_list: |
118 filters = annotation_filter.split('=') | 130 filters = annotation_filter.split('=') |
119 if len(filters) == 2: | 131 if len(filters) == 2: |
120 key = filters[0] | 132 key = filters[0] |
121 value_list = filters[1].split(',') | 133 value_list = filters[1].split(',') |
122 for value in value_list: | 134 for value in value_list: |
123 if tests_annotations.AnnotatedFunctions.IsAnnotated( | 135 if tests_annotations.AnnotatedFunctions.IsAnnotated( |
124 key + ':' + value, test_info.qualified_name): | 136 key + ':' + value, test_info.qualified_name): |
125 return True | 137 return True |
126 elif tests_annotations.AnnotatedFunctions.IsAnnotated( | 138 elif tests_annotations.AnnotatedFunctions.IsAnnotated( |
127 annotation_filter, test_info.qualified_name): | 139 annotation_filter, test_info.qualified_name): |
128 return True | 140 return True |
129 return False | 141 return False |
130 | 142 |
131 def _NameFilterIncludesTest(self, test_info, name_filter): | |
132 """Checks whether a name filter matches a given test_info's method name. | |
133 | |
134 This is a case-sensitive, substring comparison: 'Foo' will match methods | |
135 Foo.testBar and Bar.testFoo. 'foo' would not match either. | |
136 | |
137 Args: | |
138 test_info: TestInfo object representing the test | |
139 name_filter: substring to check for in the qualified name of the test | |
140 | |
141 Returns: | |
142 True if no name filter supplied or it matches; False otherwise. | |
143 """ | |
144 return not name_filter or name_filter in test_info.qualified_name | |
OLD | NEW |