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

Side by Side Diff: tools/telemetry/telemetry/page/page_test.py

Issue 22981005: [telemetry] Move Results options out of PageTest/Measurement into their own module. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge and lint. Created 7 years, 4 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
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 import logging 4 import logging
5 5
6 from telemetry.core import util 6 from telemetry.core import util
7 from telemetry.page import gtest_test_results
8 from telemetry.page import test_expectations 7 from telemetry.page import test_expectations
9 from telemetry.page import page_test_results
10 from telemetry.page.actions import all_page_actions 8 from telemetry.page.actions import all_page_actions
11 from telemetry.page.actions import navigate 9 from telemetry.page.actions import navigate
12 from telemetry.page.actions import page_action 10 from telemetry.page.actions import page_action
13 11
12
14 def _GetActionFromData(action_data): 13 def _GetActionFromData(action_data):
15 action_name = action_data['action'] 14 action_name = action_data['action']
16 action = all_page_actions.FindClassWithName(action_name) 15 action = all_page_actions.FindClassWithName(action_name)
17 if not action: 16 if not action:
18 logging.critical('Could not find an action named %s.', action_name) 17 logging.critical('Could not find an action named %s.', action_name)
19 logging.critical('Check the page set for a typo and check the error ' 18 logging.critical('Check the page set for a typo and check the error '
20 'log for possible Python loading/compilation errors.') 19 'log for possible Python loading/compilation errors.')
21 raise Exception('Action "%s" not found.' % action_name) 20 raise Exception('Action "%s" not found.' % action_name)
22 return action(action_data) 21 return action(action_data)
23 22
23
24 def GetCompoundActionFromPage(page, action_name): 24 def GetCompoundActionFromPage(page, action_name):
25 if not action_name: 25 if not action_name:
26 return [] 26 return []
27 27
28 action_data_list = getattr(page, action_name) 28 action_data_list = getattr(page, action_name)
29 if not isinstance(action_data_list, list): 29 if not isinstance(action_data_list, list):
30 action_data_list = [action_data_list] 30 action_data_list = [action_data_list]
31 31
32 action_list = [] 32 action_list = []
33 for subaction_data in action_data_list: 33 for subaction_data in action_data_list:
34 subaction_name = subaction_data['action'] 34 subaction_name = subaction_data['action']
35 if hasattr(page, subaction_name): 35 if hasattr(page, subaction_name):
36 subaction = GetCompoundActionFromPage(page, subaction_name) 36 subaction = GetCompoundActionFromPage(page, subaction_name)
37 else: 37 else:
38 subaction = [_GetActionFromData(subaction_data)] 38 subaction = [_GetActionFromData(subaction_data)]
39 action_list += subaction * subaction_data.get('repeat', 1) 39 action_list += subaction * subaction_data.get('repeat', 1)
40 return action_list 40 return action_list
41 41
42
42 class Failure(Exception): 43 class Failure(Exception):
43 """Exception that can be thrown from PageMeasurement to indicate an 44 """Exception that can be thrown from PageMeasurement to indicate an
44 undesired but designed-for problem.""" 45 undesired but designed-for problem."""
45 pass 46 pass
46 47
48
47 class PageTest(object): 49 class PageTest(object):
48 """A class styled on unittest.TestCase for creating page-specific tests.""" 50 """A class styled on unittest.TestCase for creating page-specific tests."""
49 51
50 def __init__(self, 52 def __init__(self,
51 test_method_name, 53 test_method_name,
52 action_name_to_run='', 54 action_name_to_run='',
53 needs_browser_restart_after_each_run=False, 55 needs_browser_restart_after_each_run=False,
54 discard_first_result=False, 56 discard_first_result=False,
55 clear_cache_before_each_run=False): 57 clear_cache_before_each_run=False):
56 self.options = None 58 self.options = None
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 def CreatePageSet(self, args, options): # pylint: disable=W0613 162 def CreatePageSet(self, args, options): # pylint: disable=W0613
161 """Override to make this test generate its own page set instead of 163 """Override to make this test generate its own page set instead of
162 allowing arbitrary page sets entered from the command-line.""" 164 allowing arbitrary page sets entered from the command-line."""
163 return None 165 return None
164 166
165 def CreateExpectations(self, page_set): # pylint: disable=W0613 167 def CreateExpectations(self, page_set): # pylint: disable=W0613
166 """Override to make this test generate its own expectations instead of 168 """Override to make this test generate its own expectations instead of
167 any that may have been defined in the page set.""" 169 any that may have been defined in the page set."""
168 return test_expectations.TestExpectations() 170 return test_expectations.TestExpectations()
169 171
170 def AddOutputOptions(self, parser):
171 parser.add_option('--output-format',
172 default=self.output_format_choices[0],
173 choices=self.output_format_choices,
174 help='Output format. Defaults to "%%default". '
175 'Can be %s.' % ', '.join(self.output_format_choices))
176
177 @property
178 def output_format_choices(self):
179 """Allowed output formats. The default is the first item in the list."""
180 return ['gtest', 'none']
181
182 def PrepareResults(self, options):
183 if not hasattr(options, 'output_format'):
184 options.output_format = self.output_format_choices[0]
185
186 if options.output_format == 'gtest':
187 return gtest_test_results.GTestTestResults()
188 elif options.output_format == 'none':
189 return page_test_results.PageTestResults()
190 else:
191 # Should never be reached. The parser enforces the choices.
192 raise Exception('Invalid --output-format "%s". Valid choices are: %s'
193 % (options.output_format,
194 ', '.join(self.output_format_choices)))
195
196 def Run(self, options, page, tab, results): 172 def Run(self, options, page, tab, results):
197 self.options = options 173 self.options = options
198 compound_action = GetCompoundActionFromPage(page, self._action_name_to_run) 174 compound_action = GetCompoundActionFromPage(page, self._action_name_to_run)
199 self._RunCompoundAction(page, tab, compound_action) 175 self._RunCompoundAction(page, tab, compound_action)
200 try: 176 try:
201 self._test_method(page, tab, results) 177 self._test_method(page, tab, results)
202 finally: 178 finally:
203 self.options = None 179 self.options = None
204 180
205 def _RunCompoundAction(self, page, tab, actions, run_setup_methods=True): 181 def _RunCompoundAction(self, page, tab, actions, run_setup_methods=True):
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 else: 218 else:
243 # TODO(edmundyan): Make a default navigate_steps action on the page object 219 # TODO(edmundyan): Make a default navigate_steps action on the page object
244 # once we can deprecate page.WaitToLoad() 220 # once we can deprecate page.WaitToLoad()
245 i = navigate.NavigateAction() 221 i = navigate.NavigateAction()
246 i.RunAction(page, tab, None) 222 i.RunAction(page, tab, None)
247 page.WaitToLoad(tab, 60) 223 page.WaitToLoad(tab, 60)
248 224
249 @property 225 @property
250 def action_name_to_run(self): 226 def action_name_to_run(self):
251 return self._action_name_to_run 227 return self._action_name_to_run
OLDNEW
« no previous file with comments | « tools/telemetry/telemetry/page/page_runner.py ('k') | tools/telemetry/telemetry/page/page_test_runner.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698