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 | 9 |
10 import tests_annotations | 10 from pylib.host_driven import tests_annotations |
11 | 11 |
12 | 12 |
13 class TestInfo(object): | 13 class TestInfo(object): |
14 """An object containing and representing a test function, plus metadata.""" | 14 """An object containing and representing a test function, plus metadata.""" |
15 | 15 |
16 def __init__(self, runnable, set_up=None, tear_down=None): | 16 def __init__(self, runnable, set_up=None, tear_down=None): |
17 # The actual test function/method. | 17 # The actual test function/method. |
18 self.runnable = runnable | 18 self.runnable = runnable |
19 # Qualified name of test function/method (e.g. FooModule.testBar). | 19 # Qualified name of test function/method (e.g. FooModule.testBar). |
20 self.qualified_name = self._GetQualifiedName(runnable) | 20 self.qualified_name = self._GetQualifiedName(runnable) |
21 # setUp and teardown functions, if any. | 21 # setUp and teardown functions, if any. |
22 self.set_up = set_up | 22 self.set_up = set_up |
23 self.tear_down = tear_down | 23 self.tear_down = tear_down |
24 | 24 |
25 def _GetQualifiedName(self, runnable): | 25 @staticmethod |
| 26 def _GetQualifiedName(runnable): |
26 """Helper method to infer a runnable's name and module name. | 27 """Helper method to infer a runnable's name and module name. |
27 | 28 |
28 Many filters and lists presuppose a format of module_name.testMethodName. | 29 Many filters and lists presuppose a format of module_name.testMethodName. |
29 To make this easy on everyone, we use some reflection magic to infer this | 30 To make this easy on everyone, we use some reflection magic to infer this |
30 name automatically. | 31 name automatically. |
31 | 32 |
32 Args: | 33 Args: |
33 runnable: the test method to get the qualified name for | 34 runnable: the test method to get the qualified name for |
34 | 35 |
35 Returns: | 36 Returns: |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 available_tests += tests_without_annotation | 96 available_tests += tests_without_annotation |
96 if exclude_annotations: | 97 if exclude_annotations: |
97 excluded_tests = [t for t in available_tests if | 98 excluded_tests = [t for t in available_tests if |
98 self._AnnotationIncludesTest(t, exclude_annotations)] | 99 self._AnnotationIncludesTest(t, exclude_annotations)] |
99 available_tests = list(set(available_tests) - set(excluded_tests)) | 100 available_tests = list(set(available_tests) - set(excluded_tests)) |
100 available_tests = [t for t in available_tests if | 101 available_tests = [t for t in available_tests if |
101 self._NameFilterIncludesTest(t, name_filter)] | 102 self._NameFilterIncludesTest(t, name_filter)] |
102 | 103 |
103 return available_tests | 104 return available_tests |
104 | 105 |
105 def _AnnotationIncludesTest(self, test_info, annotation_filter_list): | 106 @staticmethod |
| 107 def _AnnotationIncludesTest(test_info, annotation_filter_list): |
106 """Checks whether a given test represented by test_info matches annotation. | 108 """Checks whether a given test represented by test_info matches annotation. |
107 | 109 |
108 Args: | 110 Args: |
109 test_info: TestInfo object representing the test | 111 test_info: TestInfo object representing the test |
110 annotation_filter_list: list of annotation filters to match (e.g. Smoke) | 112 annotation_filter_list: list of annotation filters to match (e.g. Smoke) |
111 | 113 |
112 Returns: | 114 Returns: |
113 True if no annotation was supplied or the test matches; false otherwise. | 115 True if no annotation was supplied or the test matches; false otherwise. |
114 """ | 116 """ |
115 if not annotation_filter_list: | 117 if not annotation_filter_list: |
116 return True | 118 return True |
117 for annotation_filter in annotation_filter_list: | 119 for annotation_filter in annotation_filter_list: |
118 filters = annotation_filter.split('=') | 120 filters = annotation_filter.split('=') |
119 if len(filters) == 2: | 121 if len(filters) == 2: |
120 key = filters[0] | 122 key = filters[0] |
121 value_list = filters[1].split(',') | 123 value_list = filters[1].split(',') |
122 for value in value_list: | 124 for value in value_list: |
123 if tests_annotations.AnnotatedFunctions.IsAnnotated( | 125 if tests_annotations.AnnotatedFunctions.IsAnnotated( |
124 key + ':' + value, test_info.qualified_name): | 126 key + ':' + value, test_info.qualified_name): |
125 return True | 127 return True |
126 elif tests_annotations.AnnotatedFunctions.IsAnnotated( | 128 elif tests_annotations.AnnotatedFunctions.IsAnnotated( |
127 annotation_filter, test_info.qualified_name): | 129 annotation_filter, test_info.qualified_name): |
128 return True | 130 return True |
129 return False | 131 return False |
130 | 132 |
131 def _NameFilterIncludesTest(self, test_info, name_filter): | 133 @staticmethod |
| 134 def _NameFilterIncludesTest(test_info, name_filter): |
132 """Checks whether a name filter matches a given test_info's method name. | 135 """Checks whether a name filter matches a given test_info's method name. |
133 | 136 |
134 This is a case-sensitive, substring comparison: 'Foo' will match methods | 137 This is a case-sensitive, substring comparison: 'Foo' will match methods |
135 Foo.testBar and Bar.testFoo. 'foo' would not match either. | 138 Foo.testBar and Bar.testFoo. 'foo' would not match either. |
136 | 139 |
137 Args: | 140 Args: |
138 test_info: TestInfo object representing the test | 141 test_info: TestInfo object representing the test |
139 name_filter: substring to check for in the qualified name of the test | 142 name_filter: substring to check for in the qualified name of the test |
140 | 143 |
141 Returns: | 144 Returns: |
142 True if no name filter supplied or it matches; False otherwise. | 145 True if no name filter supplied or it matches; False otherwise. |
143 """ | 146 """ |
144 return not name_filter or name_filter in test_info.qualified_name | 147 return not name_filter or name_filter in test_info.qualified_name |
OLD | NEW |