OLD | NEW |
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2013 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 """Helper class for instrumenation test jar.""" | 5 """Helper class for instrumenation test jar.""" |
6 | 6 |
7 import collections | 7 import collections |
8 import logging | 8 import logging |
9 import os | 9 import os |
10 import pickle | 10 import pickle |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 logging.info('Storing proguard output to %s', self._pickled_proguard_name) | 120 logging.info('Storing proguard output to %s', self._pickled_proguard_name) |
121 d = {'VERSION': PICKLE_FORMAT_VERSION, | 121 d = {'VERSION': PICKLE_FORMAT_VERSION, |
122 'ANNOTATION_MAP': self._annotation_map, | 122 'ANNOTATION_MAP': self._annotation_map, |
123 'TEST_METHODS': self._test_methods} | 123 'TEST_METHODS': self._test_methods} |
124 with open(self._pickled_proguard_name, 'w') as f: | 124 with open(self._pickled_proguard_name, 'w') as f: |
125 f.write(pickle.dumps(d)) | 125 f.write(pickle.dumps(d)) |
126 | 126 |
127 def _GetAnnotationMap(self): | 127 def _GetAnnotationMap(self): |
128 return self._annotation_map | 128 return self._annotation_map |
129 | 129 |
130 def _IsTestMethod(self, test): | 130 @staticmethod |
| 131 def _IsTestMethod(test): |
131 class_name, method = test.split('#') | 132 class_name, method = test.split('#') |
132 return class_name.endswith('Test') and method.startswith('test') | 133 return class_name.endswith('Test') and method.startswith('test') |
133 | 134 |
134 def GetTestAnnotations(self, test): | 135 def GetTestAnnotations(self, test): |
135 """Returns a list of all annotations for the given |test|. May be empty.""" | 136 """Returns a list of all annotations for the given |test|. May be empty.""" |
136 if not self._IsTestMethod(test): | 137 if not self._IsTestMethod(test): |
137 return [] | 138 return [] |
138 return self._GetAnnotationMap()[test] | 139 return self._GetAnnotationMap()[test] |
139 | 140 |
140 def _AnnotationsMatchFilters(self, annotation_filter_list, annotations): | 141 @staticmethod |
| 142 def _AnnotationsMatchFilters(annotation_filter_list, annotations): |
141 """Checks if annotations match any of the filters.""" | 143 """Checks if annotations match any of the filters.""" |
142 if not annotation_filter_list: | 144 if not annotation_filter_list: |
143 return True | 145 return True |
144 for annotation_filter in annotation_filter_list: | 146 for annotation_filter in annotation_filter_list: |
145 filters = annotation_filter.split('=') | 147 filters = annotation_filter.split('=') |
146 if len(filters) == 2: | 148 if len(filters) == 2: |
147 key = filters[0] | 149 key = filters[0] |
148 value_list = filters[1].split(',') | 150 value_list = filters[1].split(',') |
149 for value in value_list: | 151 for value in value_list: |
150 if key + ':' + value in annotations: | 152 if key + ':' + value in annotations: |
(...skipping 15 matching lines...) Expand all Loading... |
166 def _GetTestsMissingAnnotation(self): | 168 def _GetTestsMissingAnnotation(self): |
167 """Get a list of test methods with no known annotations.""" | 169 """Get a list of test methods with no known annotations.""" |
168 tests_missing_annotations = [] | 170 tests_missing_annotations = [] |
169 for test_method in self.GetTestMethods(): | 171 for test_method in self.GetTestMethods(): |
170 annotations_ = frozenset(self.GetTestAnnotations(test_method)) | 172 annotations_ = frozenset(self.GetTestAnnotations(test_method)) |
171 if (annotations_.isdisjoint(self._ANNOTATIONS) and | 173 if (annotations_.isdisjoint(self._ANNOTATIONS) and |
172 not self.IsHostDrivenTest(test_method)): | 174 not self.IsHostDrivenTest(test_method)): |
173 tests_missing_annotations.append(test_method) | 175 tests_missing_annotations.append(test_method) |
174 return sorted(tests_missing_annotations) | 176 return sorted(tests_missing_annotations) |
175 | 177 |
176 def _GetAllMatchingTests(self, annotation_filter_list, | 178 def GetAllMatchingTests(self, annotation_filter_list, |
177 exclude_annotation_list, test_filter): | 179 exclude_annotation_list, test_filter): |
178 """Get a list of tests matching any of the annotations and the filter. | 180 """Get a list of tests matching any of the annotations and the filter. |
179 | 181 |
180 Args: | 182 Args: |
181 annotation_filter_list: List of test annotations. A test must have at | 183 annotation_filter_list: List of test annotations. A test must have at |
182 least one of these annotations. A test without any annotations is | 184 least one of these annotations. A test without any annotations is |
183 considered to be SmallTest. | 185 considered to be SmallTest. |
184 exclude_annotation_list: List of test annotations. A test must not have | 186 exclude_annotation_list: List of test annotations. A test must not have |
185 any of these annotations. | 187 any of these annotations. |
186 test_filter: Filter used for partial matching on the test method names. | 188 test_filter: Filter used for partial matching on the test method names. |
(...skipping 24 matching lines...) Expand all Loading... |
211 tests = [t for t in available_tests | 213 tests = [t for t in available_tests |
212 if filter_without_hash in t.replace('#', '.')] | 214 if filter_without_hash in t.replace('#', '.')] |
213 else: | 215 else: |
214 tests = available_tests | 216 tests = available_tests |
215 | 217 |
216 return tests | 218 return tests |
217 | 219 |
218 @staticmethod | 220 @staticmethod |
219 def IsHostDrivenTest(test): | 221 def IsHostDrivenTest(test): |
220 return 'pythonDrivenTests' in test | 222 return 'pythonDrivenTests' in test |
OLD | NEW |