Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Side by Side Diff: build/android/pylib/host_driven/test_info_collection.py

Issue 144183004: Convert to gtest-style filtering in instrumentation tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | build/android/pylib/instrumentation/test_jar.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 from pylib.host_driven import tests_annotations 11 from pylib.host_driven 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 t.qualified_name)] 99 t.qualified_name)]
92 test_names = [t.qualified_name for t in tests_without_annotation] 100 test_names = [t.qualified_name for t in tests_without_annotation]
93 logging.warning('The following tests do not contain any annotation. ' 101 logging.warning('The following tests do not contain any annotation. '
94 'Assuming "SmallTest":\n%s', 102 'Assuming "SmallTest":\n%s',
95 '\n'.join(test_names)) 103 '\n'.join(test_names))
96 available_tests += tests_without_annotation 104 available_tests += tests_without_annotation
97 if exclude_annotations: 105 if exclude_annotations:
98 excluded_tests = [t for t in available_tests if 106 excluded_tests = [t for t in available_tests if
99 self._AnnotationIncludesTest(t, exclude_annotations)] 107 self._AnnotationIncludesTest(t, exclude_annotations)]
100 available_tests = list(set(available_tests) - set(excluded_tests)) 108 available_tests = list(set(available_tests) - set(excluded_tests))
101 available_tests = [t for t in available_tests if
102 self._NameFilterIncludesTest(t, name_filter)]
103 109
110 if name_filter:
111 available_test_names = unittest_util.FilterTestNames(
112 [t.qualified_name for t in available_tests], name_filter)
113 available_tests = [
114 t for t in available_tests if
115 t.qualified_name in available_test_names]
104 return available_tests 116 return available_tests
105 117
106 @staticmethod 118 @staticmethod
107 def _AnnotationIncludesTest(test_info, annotation_filter_list): 119 def _AnnotationIncludesTest(test_info, annotation_filter_list):
108 """Checks whether a given test represented by test_info matches annotation. 120 """Checks whether a given test represented by test_info matches annotation.
109 121
110 Args: 122 Args:
111 test_info: TestInfo object representing the test 123 test_info: TestInfo object representing the test
112 annotation_filter_list: list of annotation filters to match (e.g. Smoke) 124 annotation_filter_list: list of annotation filters to match (e.g. Smoke)
113 125
114 Returns: 126 Returns:
115 True if no annotation was supplied or the test matches; false otherwise. 127 True if no annotation was supplied or the test matches; false otherwise.
116 """ 128 """
117 if not annotation_filter_list: 129 if not annotation_filter_list:
118 return True 130 return True
119 for annotation_filter in annotation_filter_list: 131 for annotation_filter in annotation_filter_list:
120 filters = annotation_filter.split('=') 132 filters = annotation_filter.split('=')
121 if len(filters) == 2: 133 if len(filters) == 2:
122 key = filters[0] 134 key = filters[0]
123 value_list = filters[1].split(',') 135 value_list = filters[1].split(',')
124 for value in value_list: 136 for value in value_list:
125 if tests_annotations.AnnotatedFunctions.IsAnnotated( 137 if tests_annotations.AnnotatedFunctions.IsAnnotated(
126 key + ':' + value, test_info.qualified_name): 138 key + ':' + value, test_info.qualified_name):
127 return True 139 return True
128 elif tests_annotations.AnnotatedFunctions.IsAnnotated( 140 elif tests_annotations.AnnotatedFunctions.IsAnnotated(
129 annotation_filter, test_info.qualified_name): 141 annotation_filter, test_info.qualified_name):
130 return True 142 return True
131 return False 143 return False
132 144
133 @staticmethod
134 def _NameFilterIncludesTest(test_info, name_filter):
135 """Checks whether a name filter matches a given test_info's method name.
136
137 This is a case-sensitive, substring comparison: 'Foo' will match methods
138 Foo.testBar and Bar.testFoo. 'foo' would not match either.
139
140 Args:
141 test_info: TestInfo object representing the test
142 name_filter: substring to check for in the qualified name of the test
143
144 Returns:
145 True if no name filter supplied or it matches; False otherwise.
146 """
147 return not name_filter or name_filter in test_info.qualified_name
OLDNEW
« no previous file with comments | « no previous file | build/android/pylib/instrumentation/test_jar.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698