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

Side by Side Diff: build/util/lib/common/unittest_util.py

Issue 14882007: Android: support glob-style gtest filters with content browser tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use DIR_SOURCE_ROOT. Created 7 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « build/util/lib/common/__init__.py ('k') | build/util/lib/common/util.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 """Utilities for dealing with the python unittest module.""" 5 """Utilities for dealing with the python unittest module."""
6 6
7 import fnmatch 7 import fnmatch
8 import sys 8 import sys
9 import unittest 9 import unittest
10 10
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 def FilterTestSuite(suite, gtest_filter): 94 def FilterTestSuite(suite, gtest_filter):
95 """Returns a new filtered tests suite based on the given gtest filter. 95 """Returns a new filtered tests suite based on the given gtest filter.
96 96
97 See http://code.google.com/p/googletest/wiki/AdvancedGuide 97 See http://code.google.com/p/googletest/wiki/AdvancedGuide
98 for gtest_filter specification. 98 for gtest_filter specification.
99 """ 99 """
100 return unittest.TestSuite(FilterTests(GetTestsFromSuite(suite), gtest_filter)) 100 return unittest.TestSuite(FilterTests(GetTestsFromSuite(suite), gtest_filter))
101 101
102 102
103 def FilterTests(all_tests, gtest_filter): 103 def FilterTests(all_tests, gtest_filter):
104 """Returns a filtered list of tests based on the given gtest filter. 104 """Filter a list of tests based on the given gtest filter.
105
106 Args:
107 all_tests: List of tests (unittest.TestSuite)
108 gtest_filter: Filter to apply.
109
110 Returns:
111 Filtered subset of the given list of tests.
112 """
113 test_names = [GetTestName(test) for test in all_tests]
114 filtered_names = FilterTestNames(test_names, gtest_filter)
115 return [test for test in all_tests if GetTestName(test) in filtered_names]
116
117
118 def FilterTestNames(all_tests, gtest_filter):
119 """Filter a list of test names based on the given gtest filter.
105 120
106 See http://code.google.com/p/googletest/wiki/AdvancedGuide 121 See http://code.google.com/p/googletest/wiki/AdvancedGuide
107 for gtest_filter specification. 122 for gtest_filter specification.
123
124 Args:
125 all_tests: List of test names.
126 gtest_filter: Filter to apply.
127
128 Returns:
129 Filtered subset of the given list of test names.
108 """ 130 """
109 pattern_groups = gtest_filter.split('-') 131 pattern_groups = gtest_filter.split('-')
110 positive_patterns = pattern_groups[0].split(':') 132 positive_patterns = pattern_groups[0].split(':')
111 negative_patterns = None 133 negative_patterns = None
112 if len(pattern_groups) > 1: 134 if len(pattern_groups) > 1:
113 negative_patterns = pattern_groups[1].split(':') 135 negative_patterns = pattern_groups[1].split(':')
114 136
115 tests = [] 137 tests = []
116 for test in all_tests: 138 for test in all_tests:
117 test_name = GetTestName(test)
118 # Test name must by matched by one positive pattern. 139 # Test name must by matched by one positive pattern.
119 for pattern in positive_patterns: 140 for pattern in positive_patterns:
120 if fnmatch.fnmatch(test_name, pattern): 141 if fnmatch.fnmatch(test, pattern):
121 break 142 break
122 else: 143 else:
123 continue 144 continue
124 # Test name must not be matched by any negative patterns. 145 # Test name must not be matched by any negative patterns.
125 for pattern in negative_patterns or []: 146 for pattern in negative_patterns or []:
126 if fnmatch.fnmatch(test_name, pattern): 147 if fnmatch.fnmatch(test, pattern):
127 break 148 break
128 else: 149 else:
129 tests += [test] 150 tests += [test]
130 return tests 151 return tests
OLDNEW
« no previous file with comments | « build/util/lib/common/__init__.py ('k') | build/util/lib/common/util.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698