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