OLD | NEW |
(Empty) | |
| 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 |
| 3 # found in the LICENSE file. |
| 4 from telemetry.page import page_runner |
| 5 from telemetry.page import page_set |
| 6 from telemetry.page import page_test |
| 7 |
| 8 |
| 9 class Test(object): |
| 10 """Base class for a Telemetry test or benchmark. |
| 11 |
| 12 A test packages a PageTest/PageMeasurement and a PageSet together. |
| 13 """ |
| 14 options = {} |
| 15 enabled = True |
| 16 |
| 17 def Run(self, options): |
| 18 """Run this test with the given options.""" |
| 19 assert hasattr(self, 'test'), 'This test has no "test" attribute.' |
| 20 assert issubclass(self.test, page_test.PageTest), ( |
| 21 '"%s" is not a PageTest.' % self.test.__name__) |
| 22 |
| 23 for key, value in self.options.iteritems(): |
| 24 setattr(options, key, value) |
| 25 |
| 26 test = self.test() |
| 27 ps = self.CreatePageSet(options) |
| 28 results = page_runner.Run(test, ps, options) |
| 29 results.PrintSummary() |
| 30 return len(results.failures) + len(results.errors) |
| 31 |
| 32 def CreatePageSet(self, options): # pylint: disable=W0613 |
| 33 """Get the page set this test will run on. |
| 34 |
| 35 By default, it will create a page set from the file at this test's |
| 36 page_set attribute. Override to generate a custom page set. |
| 37 """ |
| 38 assert hasattr(self, 'page_set'), 'This test has no "page_set" attribute.' |
| 39 return page_set.PageSet.FromFile(self.page_set) |
OLD | NEW |