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

Side by Side Diff: telemetry/telemetry/testing/serially_executed_browser_test_case.py

Issue 2662193004: Revert of [Telemetry] Migrate browser_test_runner to use typ as the test runner (Closed)
Patch Set: Created 3 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 | « telemetry/telemetry/testing/run_browser_tests.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2016 The Chromium Authors. All rights reserved. 1 # Copyright 2016 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 import inspect 5 import inspect
6 import re 6 import re
7 import unittest 7 import unittest
8 8
9 from py_utils import cloud_storage 9 from py_utils import cloud_storage
10 from telemetry.internal.browser import browser_finder 10 from telemetry.internal.browser import browser_finder
11 from telemetry.testing import browser_test_context 11 from telemetry.testing import options_for_unittests
12 from telemetry.util import wpr_modes 12 from telemetry.util import wpr_modes
13 13
14 14
15 class SeriallyExecutedBrowserTestCase(unittest.TestCase): 15 class SeriallyExecutedBrowserTestCase(unittest.TestCase):
16 def __init__(self, methodName): 16 def __init__(self, methodName):
17 super(SeriallyExecutedBrowserTestCase, self).__init__(methodName) 17 super(SeriallyExecutedBrowserTestCase, self).__init__(methodName)
18 self._private_methodname = methodName 18 self._private_methodname = methodName
19 19
20 def shortName(self): 20 def shortName(self):
21 """Returns the method name this test runs, without the package prefix.""" 21 """Returns the method name this test runs, without the package prefix."""
22 return self._private_methodname 22 return self._private_methodname
23 23
24 @classmethod 24 @classmethod
25 def Name(cls): 25 def Name(cls):
26 return cls.__name__ 26 return cls.__name__
27 27
28 @classmethod 28 @classmethod
29 def AddCommandlineArgs(cls, parser): 29 def AddCommandlineArgs(cls, parser):
30 pass 30 pass
31 31
32 @classmethod 32 @classmethod
33 def setUpClass(cls): 33 def setUpClass(cls):
34 cls._finder_options = browser_test_context.GetCopy().finder_options 34 cls._finder_options = options_for_unittests.GetCopy()
35 cls.platform = None 35 cls.platform = None
36 cls.browser = None 36 cls.browser = None
37 cls._browser_to_create = None 37 cls._browser_to_create = None
38 cls._browser_options = None 38 cls._browser_options = None
39 39
40 @classmethod 40 @classmethod
41 def SetBrowserOptions(cls, browser_options): 41 def SetBrowserOptions(cls, browser_options):
42 """Sets the browser option for the browser to create. 42 """Sets the browser option for the browser to create.
43 43
44 Args: 44 Args:
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 ################################################################# 135 #################################################################
136 136
137 Args: 137 Args:
138 module: the module which contains test cases classes. 138 module: the module which contains test cases classes.
139 139
140 Returns: 140 Returns:
141 an instance of unittest.TestSuite, which contains all the tests & generated 141 an instance of unittest.TestSuite, which contains all the tests & generated
142 test cases to be run. 142 test cases to be run.
143 """ 143 """
144 suite = unittest.TestSuite() 144 suite = unittest.TestSuite()
145 test_context = browser_test_context.GetCopy() 145 finder_options = options_for_unittests.GetCopy()
146 if not test_context: 146 if not hasattr(finder_options, 'browser_test_runner_running'):
147 return suite 147 return suite
148 for _, obj in inspect.getmembers(module): 148 for _, obj in inspect.getmembers(module):
149 if (inspect.isclass(obj) and 149 if (inspect.isclass(obj) and
150 issubclass(obj, SeriallyExecutedBrowserTestCase)): 150 issubclass(obj, SeriallyExecutedBrowserTestCase)):
151 # We bail out early if the test class's name doesn't match the targeted
152 # test_class_name in test_context to avoid calling GenerateTestCases for
153 # tests that we don't intend to run. This is to avoid possible errors in
154 # GenerateTestCases as the test class may define custom options in
155 # the finder_options object, and hence would raise error if they can't
156 # find their custom options in finder_options object.
157 if test_context.test_class_name != obj.Name():
158 continue
159 for test in GenerateTestCases( 151 for test in GenerateTestCases(
160 test_class=obj, finder_options=test_context.finder_options): 152 test_class=obj, finder_options=finder_options):
161 if test.id() in test_context.test_case_ids_to_run: 153 suite.addTest(test)
162 suite.addTest(test)
163 return suite 154 return suite
164 155
165 156
166 def _GenerateTestMethod(based_method, args): 157 def _GenerateTestMethod(based_method, args):
167 return lambda self: based_method(self, *args) 158 return lambda self: based_method(self, *args)
168 159
169 160
170 _TEST_GENERATOR_PREFIX = 'GenerateTestCases_' 161 _TEST_GENERATOR_PREFIX = 'GenerateTestCases_'
171 _INVALID_TEST_NAME_RE = re.compile(r'[^a-zA-Z0-9_]') 162 _INVALID_TEST_NAME_RE = re.compile(r'[^a-zA-Z0-9_]')
172 163
(...skipping 19 matching lines...) Expand all
192 assert hasattr(test_class, based_method_name), ( 183 assert hasattr(test_class, based_method_name), (
193 '%s is specified but based method %s does not exist' % 184 '%s is specified but based method %s does not exist' %
194 (name, based_method_name)) 185 (name, based_method_name))
195 based_method = getattr(test_class, based_method_name) 186 based_method = getattr(test_class, based_method_name)
196 for generated_test_name, args in method(finder_options): 187 for generated_test_name, args in method(finder_options):
197 _ValidateTestMethodname(generated_test_name) 188 _ValidateTestMethodname(generated_test_name)
198 setattr(test_class, generated_test_name, _GenerateTestMethod( 189 setattr(test_class, generated_test_name, _GenerateTestMethod(
199 based_method, args)) 190 based_method, args))
200 test_cases.append(test_class(generated_test_name)) 191 test_cases.append(test_class(generated_test_name))
201 return test_cases 192 return test_cases
OLDNEW
« no previous file with comments | « telemetry/telemetry/testing/run_browser_tests.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698