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

Side by Side Diff: expect_tests/type_definitions.py

Issue 560173002: Simplify objects passed to the result stage (Closed) Base URL: https://chromium.googlesource.com/infra/testing/expect_tests@subprocess
Patch Set: Fixed one line length Created 6 years, 3 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 | « expect_tests/handle_list.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 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 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 os 6 import os
7 import re 7 import re
8 8
9 from collections import namedtuple 9 from collections import namedtuple
10 10
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 assert f.fully_bound 144 assert f.fully_bound
145 return f.func(*f.args, **f.kwargs) 145 return f.func(*f.args, **f.kwargs)
146 146
147 def __repr__(self): 147 def __repr__(self):
148 return 'FuncCall(%r, *%r, **%r)' % (self.func, self.args, self.kwargs) 148 return 'FuncCall(%r, *%r, **%r)' % (self.func, self.args, self.kwargs)
149 149
150 150
151 _Test = namedtuple( 151 _Test = namedtuple(
152 'Test', 'name func_call expect_dir expect_base ext covers breakpoints') 152 'Test', 'name func_call expect_dir expect_base ext covers breakpoints')
153 153
154 TestInfo = namedtuple(
155 'TestInfo', 'name expect_dir expect_base ext')
156
157
154 class Test(_Test): 158 class Test(_Test):
155 TEST_COVERS_MATCH = re.compile('.*/test/([^/]*)_test\.py$') 159 TEST_COVERS_MATCH = re.compile('.*/test/([^/]*)_test\.py$')
156 160
157 def __new__(cls, name, func_call, expect_dir=None, expect_base=None, 161 def __new__(cls, name, func_call, expect_dir=None, expect_base=None,
158 ext='json', covers=None, breakpoints=None, break_funcs=()): 162 ext='json', covers=None, breakpoints=None, break_funcs=()):
159 """Create a new test. 163 """Create a new test.
160 164
161 @param name: The name of the test. Will be used as the default expect_base 165 @param name: The name of the test. Will be used as the default expect_base
162 166
163 @param func_call: A FuncCall object 167 @param func_call: A FuncCall object
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 """ 242 """
239 yield self, func(self.bind(context=None)) 243 yield self, func(self.bind(context=None))
240 244
241 def bind(self, *args, **kwargs): 245 def bind(self, *args, **kwargs):
242 return self._replace(func_call=self.func_call.bind(*args, **kwargs)) 246 return self._replace(func_call=self.func_call.bind(*args, **kwargs))
243 247
244 def restrict(self, tests): 248 def restrict(self, tests):
245 assert tests[0] is self 249 assert tests[0] is self
246 return self 250 return self
247 251
252 def get_info(self):
253 """Strips test instance of hard-to-pickle stuff
254
255 Returns a TestInfo instance.
256 """
257 return TestInfo(self.name, self.expect_dir, self.expect_base, self.ext)
258
248 259
249 _MultiTest = namedtuple( 260 _MultiTest = namedtuple(
250 'MultiTest', 'name make_ctx_call destroy_ctx_call tests atomic') 261 'MultiTest', 'name make_ctx_call destroy_ctx_call tests atomic')
251 262
263 MultiTestInfo = namedtuple('MultiTestInfo', 'name tests atomic')
264
265
252 class MultiTest(_MultiTest): 266 class MultiTest(_MultiTest):
253 """A wrapper around one or more Test instances. 267 """A wrapper around one or more Test instances.
254 268
255 Allows the entire group to have common pre- and post- actions and an optional 269 Allows the entire group to have common pre- and post- actions and an optional
256 shared context between the Test methods (represented by Bind(name='context')). 270 shared context between the Test methods (represented by Bind(name='context')).
257 271
258 Args: 272 Args:
259 name - The name of the MultiTest. Each Test's name should be prefixed with 273 name - The name of the MultiTest. Each Test's name should be prefixed with
260 this name, though this is not enforced. 274 this name, though this is not enforced.
261 make_ctx_call - A FuncCall which will be called once before any test in this 275 make_ctx_call - A FuncCall which will be called once before any test in this
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 try: 317 try:
304 for test in self.tests: 318 for test in self.tests:
305 yield test, func(test.bind(context=ctx_object)) 319 yield test, func(test.bind(context=ctx_object))
306 finally: 320 finally:
307 self.destroy_ctx_call.bind(context=ctx_object)() 321 self.destroy_ctx_call.bind(context=ctx_object)()
308 322
309 @staticmethod 323 @staticmethod
310 def expect_path(_ext=None): 324 def expect_path(_ext=None):
311 return None 325 return None
312 326
327 def get_info(self):
328 """Strips MultiTest instance of hard-to-pickle stuff
329
330 Returns a MultiTestInfo instance.
331 """
332 all_tests = [test.get_restricted() for test in self.tests]
333 test = MultiTestInfo(name=self.name,
334 tests=all_tests,
335 atomic=self.atomic
336 )
337 return test
338
313 339
314 class Handler(object): 340 class Handler(object):
315 """Handler object. 341 """Handler object.
316 342
317 Defines 3 handler methods for each stage of the test pipeline. The pipeline 343 Defines 3 handler methods for each stage of the test pipeline. The pipeline
318 looks like: 344 looks like:
319 345
320 -> -> 346 -> ->
321 -> jobs -> (main) 347 -> jobs -> (main)
322 GenStage -> test_queue -> * -> result_queue -> ResultStage 348 GenStage -> test_queue -> * -> result_queue -> ResultStage
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 print 'UNHANDLED:', obj 451 print 'UNHANDLED:', obj
426 return Failure() 452 return Failure()
427 453
428 def finalize(self, aborted): 454 def finalize(self, aborted):
429 """Called after __call__() has been called for all results. 455 """Called after __call__() has been called for all results.
430 456
431 @param aborted: True if the user aborted the run. 457 @param aborted: True if the user aborted the run.
432 @type aborted: bool 458 @type aborted: bool
433 """ 459 """
434 pass 460 pass
OLDNEW
« no previous file with comments | « expect_tests/handle_list.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698