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

Side by Side Diff: tools/telemetry/telemetry/test.py

Issue 311193003: [telemetry] Cleanups for benchmarks importing page sets. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
OLDNEW
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2013 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 logging 5 import logging
6 import optparse 6 import optparse
7 import os 7 import os
8 import shutil 8 import shutil
9 import sys 9 import sys
10 import zipfile 10 import zipfile
(...skipping 19 matching lines...) Expand all
30 30
31 A test packages a PageTest/PageMeasurement and a PageSet together. 31 A test packages a PageTest/PageMeasurement and a PageSet together.
32 """ 32 """
33 options = {} 33 options = {}
34 34
35 @classmethod 35 @classmethod
36 def Name(cls): 36 def Name(cls):
37 name = cls.__module__.split('.')[-1] 37 name = cls.__module__.split('.')[-1]
38 if hasattr(cls, 'tag'): 38 if hasattr(cls, 'tag'):
39 name += '.' + cls.tag 39 name += '.' + cls.tag
40 page_set_name = None 40 if hasattr(cls, 'page_set'):
41 if hasattr(cls, 'page_set') and isinstance(cls.page_set, page_set.PageSet): 41 if isinstance(cls.page_set, basestring):
42 page_set_name = os.path.basename( 42 # TODO(dtu): Remove this code path after crbug.com/362293.
43 os.path.splitext(cls.page_set.file_path)[0]) 43 name += '.' + os.path.basename(os.path.splitext(cls.page_set)[0])
44 elif hasattr(cls, 'page_set') and isinstance(cls.page_set, str): 44 else:
45 page_set_name = os.path.basename(os.path.splitext(cls.page_set)[0]) 45 name += '.' + cls.page_set.Name()
46 if page_set_name:
47 name += '.' + page_set_name
48 return name 46 return name
49 47
50 @classmethod 48 @classmethod
51 def AddCommandLineArgs(cls, parser): 49 def AddCommandLineArgs(cls, parser):
52 cls.PageTestClass().AddCommandLineArgs(parser) 50 cls.PageTestClass().AddCommandLineArgs(parser)
53 51
54 if hasattr(cls, 'AddTestCommandLineArgs'): 52 if hasattr(cls, 'AddTestCommandLineArgs'):
55 group = optparse.OptionGroup(parser, '%s test options' % cls.Name()) 53 group = optparse.OptionGroup(parser, '%s test options' % cls.Name())
56 cls.AddTestCommandLineArgs(group) 54 cls.AddTestCommandLineArgs(group)
57 parser.add_option_group(group) 55 parser.add_option_group(group)
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 161
164 If the Test has no PageTest, raises NotImplementedError. 162 If the Test has no PageTest, raises NotImplementedError.
165 """ 163 """
166 if not hasattr(cls, 'test'): 164 if not hasattr(cls, 'test'):
167 raise NotImplementedError('This test has no "test" attribute.') 165 raise NotImplementedError('This test has no "test" attribute.')
168 if not issubclass(cls.test, page_test.PageTest): 166 if not issubclass(cls.test, page_test.PageTest):
169 raise TypeError('"%s" is not a PageTest.' % cls.test.__name__) 167 raise TypeError('"%s" is not a PageTest.' % cls.test.__name__)
170 return cls.test 168 return cls.test
171 169
172 @classmethod 170 @classmethod
171 def PageSetClass(cls):
172 """Get the PageSet for this Test.
173
174 If the Test has no PageSet, raises NotImplementedError.
175 """
176 if not hasattr(cls, 'page_set'):
177 raise NotImplementedError('This test has no "page_set" attribute.')
178 if not issubclass(cls.page_set, page_set.PageSet):
179 raise TypeError('"%s" is not a PageSet.' % cls.page_set.__name__)
180 return cls.page_set
181
182 @classmethod
173 def CreatePageSet(cls, options): # pylint: disable=W0613 183 def CreatePageSet(cls, options): # pylint: disable=W0613
174 """Get the page set this test will run on. 184 """Get the page set this test will run on.
175 185
176 By default, it will create a page set from the file at this test's 186 By default, it will create a page set from the file at this test's
177 page_set attribute. Override to generate a custom page set. 187 page_set attribute. Override to generate a custom page set.
178 """ 188 """
179 if not hasattr(cls, 'page_set'): 189 if not hasattr(cls, 'page_set'):
180 raise NotImplementedError('This test has no "page_set" attribute.') 190 raise NotImplementedError('This test has no "page_set" attribute.')
181 191 if isinstance(cls.page_set, basestring):
182 if isinstance(cls.page_set, str): 192 # TODO(dtu): Remove this code path after crbug.com/362293.
183 return page_set.PageSet.FromFile( 193 return page_set.PageSet.FromFile(
184 file_path=os.path.join(util.GetBaseDir(), cls.page_set)) 194 file_path=os.path.join(util.GetBaseDir(), cls.page_set))
185 elif isinstance(cls.page_set, page_set.PageSet):
186 return cls.page_set
187 else: 195 else:
188 raise TypeError('The page_set field of %s has unsupported type.' % 196 return cls.PageSetClass()()
tonyg 2014/06/04 21:05:08 Really like initializing lazily :)
189 cls.Name)
190 197
191 @classmethod 198 @classmethod
192 def CreateExpectations(cls, ps): # pylint: disable=W0613 199 def CreateExpectations(cls, ps): # pylint: disable=W0613
193 """Get the expectations this test will run with. 200 """Get the expectations this test will run with.
194 201
195 By default, it will create an empty expectations set. Override to generate 202 By default, it will create an empty expectations set. Override to generate
196 custom expectations. 203 custom expectations.
197 """ 204 """
198 if hasattr(cls, 'expectations'): 205 if hasattr(cls, 'expectations'):
199 return cls.expectations 206 return cls.expectations
200 else: 207 else:
201 return test_expectations.TestExpectations() 208 return test_expectations.TestExpectations()
202 209
203 210
204 def AddCommandLineArgs(parser): 211 def AddCommandLineArgs(parser):
205 page_runner.AddCommandLineArgs(parser) 212 page_runner.AddCommandLineArgs(parser)
206 213
207 214
208 def ProcessCommandLineArgs(parser, args): 215 def ProcessCommandLineArgs(parser, args):
209 page_runner.ProcessCommandLineArgs(parser, args) 216 page_runner.ProcessCommandLineArgs(parser, args)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698