| 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 python-driven tests.""" | 5 """Module containing information about the python-driven tests.""" |
| 6 | 6 |
| 7 import logging | 7 import logging |
| 8 import os | 8 import os |
| 9 | 9 |
| 10 import tests_annotations | 10 import tests_annotations |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 """Adds a set of tests to this collection. | 57 """Adds a set of tests to this collection. |
| 58 | 58 |
| 59 The user may then retrieve them, optionally according to criteria, via | 59 The user may then retrieve them, optionally according to criteria, via |
| 60 GetAvailableTests(). | 60 GetAvailableTests(). |
| 61 | 61 |
| 62 Args: | 62 Args: |
| 63 test_infos: a list of TestInfos representing test functions/methods. | 63 test_infos: a list of TestInfos representing test functions/methods. |
| 64 """ | 64 """ |
| 65 self.all_tests = test_infos | 65 self.all_tests = test_infos |
| 66 | 66 |
| 67 def GetAvailableTests(self, annotation, name_filter): | 67 def GetAvailableTests(self, annotations, exclude_annotations, name_filter): |
| 68 """Get a collection of TestInfos which match the supplied criteria. | 68 """Get a collection of TestInfos which match the supplied criteria. |
| 69 | 69 |
| 70 Args: | 70 Args: |
| 71 annotation: annotation which tests must match, if any | 71 annotations: List of annotations. Each test in the returned list is |
| 72 annotated with atleast one of these annotations. |
| 73 exlcude_annotations: List of annotations. The tests in the returned |
| 74 list are not annotated with any of these annotations. |
| 72 name_filter: name filter which tests must match, if any | 75 name_filter: name filter which tests must match, if any |
| 73 | 76 |
| 74 Returns: | 77 Returns: |
| 75 List of available tests. | 78 List of available tests. |
| 76 """ | 79 """ |
| 77 available_tests = self.all_tests | 80 available_tests = self.all_tests |
| 78 | 81 |
| 79 # Filter out tests which match neither the requested annotation, nor the | 82 # Filter out tests which match neither the requested annotation, nor the |
| 80 # requested name filter, if any. | 83 # requested name filter, if any. |
| 81 available_tests = [t for t in available_tests if | 84 available_tests = [t for t in available_tests if |
| 82 self._AnnotationIncludesTest(t, annotation)] | 85 self._AnnotationIncludesTest(t, annotations)] |
| 83 if annotation and len(annotation) == 1 and annotation[0] == 'SmallTest': | 86 if annotations and len(annotations) == 1 and annotations[0] == 'SmallTest': |
| 84 tests_without_annotation = [ | 87 tests_without_annotation = [ |
| 85 t for t in self.all_tests if | 88 t for t in self.all_tests if |
| 86 not tests_annotations.AnnotatedFunctions.GetTestAnnotations( | 89 not tests_annotations.AnnotatedFunctions.GetTestAnnotations( |
| 87 t.qualified_name)] | 90 t.qualified_name)] |
| 88 test_names = [t.qualified_name for t in tests_without_annotation] | 91 test_names = [t.qualified_name for t in tests_without_annotation] |
| 89 logging.warning('The following tests do not contain any annotation. ' | 92 logging.warning('The following tests do not contain any annotation. ' |
| 90 'Assuming "SmallTest":\n%s', | 93 'Assuming "SmallTest":\n%s', |
| 91 '\n'.join(test_names)) | 94 '\n'.join(test_names)) |
| 92 available_tests += tests_without_annotation | 95 available_tests += tests_without_annotation |
| 96 excluded_tests = [t for t in available_tests if |
| 97 self._AnnotationIncludesTest(t, exclude_annotations)] |
| 98 available_tests = list(set(available_tests) - set(excluded_tests)) |
| 93 available_tests = [t for t in available_tests if | 99 available_tests = [t for t in available_tests if |
| 94 self._NameFilterIncludesTest(t, name_filter)] | 100 self._NameFilterIncludesTest(t, name_filter)] |
| 95 | 101 |
| 96 return available_tests | 102 return available_tests |
| 97 | 103 |
| 98 def _AnnotationIncludesTest(self, test_info, annotation_filter_list): | 104 def _AnnotationIncludesTest(self, test_info, annotation_filter_list): |
| 99 """Checks whether a given test represented by test_info matches annotation. | 105 """Checks whether a given test represented by test_info matches annotation. |
| 100 | 106 |
| 101 Args: | 107 Args: |
| 102 test_info: TestInfo object representing the test | 108 test_info: TestInfo object representing the test |
| (...skipping 25 matching lines...) Expand all Loading... |
| 128 Foo.testBar and Bar.testFoo. 'foo' would not match either. | 134 Foo.testBar and Bar.testFoo. 'foo' would not match either. |
| 129 | 135 |
| 130 Args: | 136 Args: |
| 131 test_info: TestInfo object representing the test | 137 test_info: TestInfo object representing the test |
| 132 name_filter: substring to check for in the qualified name of the test | 138 name_filter: substring to check for in the qualified name of the test |
| 133 | 139 |
| 134 Returns: | 140 Returns: |
| 135 True if no name filter supplied or it matches; False otherwise. | 141 True if no name filter supplied or it matches; False otherwise. |
| 136 """ | 142 """ |
| 137 return not name_filter or name_filter in test_info.qualified_name | 143 return not name_filter or name_filter in test_info.qualified_name |
| OLD | NEW |