OLD | NEW |
1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 os | 4 import os |
5 import unittest | 5 import unittest |
6 | 6 |
7 from telemetry import benchmark | 7 from telemetry import benchmark |
8 from telemetry.core import discover | |
9 from telemetry.core import util | 8 from telemetry.core import util |
10 from telemetry.story import story_set as story_set_module | 9 from telemetry.story import story_set as story_set_module |
11 from telemetry.testing import fakes | 10 from telemetry.testing import fakes |
| 11 from telemetry.util import classes_util |
12 | 12 |
13 util.AddDirToPythonPath(util.GetTelemetryDir(), 'third_party', 'mock') | 13 util.AddDirToPythonPath(util.GetTelemetryDir(), 'third_party', 'mock') |
14 import mock # pylint: disable=import-error | 14 import mock # pylint: disable=import-error |
15 | 15 |
16 import gpu_test_base | 16 import gpu_test_base |
17 | 17 |
18 def _GetGpuDir(*subdirs): | 18 def _GetGpuDir(*subdirs): |
19 gpu_dir = os.path.dirname(os.path.dirname(__file__)) | 19 gpu_dir = os.path.dirname(os.path.dirname(__file__)) |
20 return os.path.join(gpu_dir, *subdirs) | 20 return os.path.join(gpu_dir, *subdirs) |
21 | 21 |
22 # Unit tests verifying invariants of classes in GpuTestBase. | 22 # Unit tests verifying invariants of classes in GpuTestBase. |
23 | 23 |
24 class NoOverridesTest(unittest.TestCase): | 24 class NoOverridesTest(unittest.TestCase): |
25 def testValidatorBase(self): | 25 def testValidatorBase(self): |
26 all_validators = discover.DiscoverClasses( | 26 all_validators = classes_util.DiscoverClasses( |
27 _GetGpuDir('gpu_tests'), _GetGpuDir(), | 27 _GetGpuDir('gpu_tests'), _GetGpuDir(), gpu_test_base.ValidatorBase) |
28 gpu_test_base.ValidatorBase, | |
29 index_by_class_name=True).values() | |
30 self.assertGreater(len(all_validators), 0) | 28 self.assertGreater(len(all_validators), 0) |
31 for validator in all_validators: | 29 for validator in all_validators: |
32 self.assertEquals(gpu_test_base.ValidatorBase.ValidateAndMeasurePage, | 30 self.assertEquals(gpu_test_base.ValidatorBase.ValidateAndMeasurePage, |
33 validator.ValidateAndMeasurePage, | 31 validator.ValidateAndMeasurePage, |
34 'Class %s should not override ValidateAndMeasurePage' | 32 'Class %s should not override ValidateAndMeasurePage' |
35 % validator.__name__) | 33 % validator.__name__) |
36 | 34 |
37 def testPageBase(self): | 35 def testPageBase(self): |
38 all_pages = discover.DiscoverClasses( | 36 all_pages = classes_util.DiscoverClasses( |
39 _GetGpuDir(), _GetGpuDir(), | 37 _GetGpuDir(), _GetGpuDir(), gpu_test_base.PageBase) |
40 gpu_test_base.PageBase, | |
41 index_by_class_name=True).values() | |
42 self.assertGreater(len(all_pages), 0) | 38 self.assertGreater(len(all_pages), 0) |
43 for page in all_pages: | 39 for page in all_pages: |
44 self.assertEquals(gpu_test_base.PageBase.RunNavigateSteps, | 40 self.assertEquals(gpu_test_base.PageBase.RunNavigateSteps, |
45 page.RunNavigateSteps, | 41 page.RunNavigateSteps, |
46 'Class %s should not override ValidateAndMeasurePage' | 42 'Class %s should not override ValidateAndMeasurePage' |
47 % page.__name__) | 43 % page.__name__) |
48 self.assertEquals(gpu_test_base.PageBase.RunPageInteractions, | 44 self.assertEquals(gpu_test_base.PageBase.RunPageInteractions, |
49 page.RunPageInteractions, | 45 page.RunPageInteractions, |
50 'Class %s should not override RunPageInteractions' | 46 'Class %s should not override RunPageInteractions' |
51 % page.__name__) | 47 % page.__name__) |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 test.validator.ValidateAndMeasurePageInner = ( | 171 test.validator.ValidateAndMeasurePageInner = ( |
176 manager.validator.ValidateAndMeasurePageInner) | 172 manager.validator.ValidateAndMeasurePageInner) |
177 test.AddFakePage(page) | 173 test.AddFakePage(page) |
178 self.assertEqual(test.Run(finder_options), 0, | 174 self.assertEqual(test.Run(finder_options), 0, |
179 'Test should run with no errors') | 175 'Test should run with no errors') |
180 expected = [mock.call.page.RunNavigateStepsInner(mock.ANY), | 176 expected = [mock.call.page.RunNavigateStepsInner(mock.ANY), |
181 mock.call.page.RunPageInteractionsInner(mock.ANY), | 177 mock.call.page.RunPageInteractionsInner(mock.ANY), |
182 mock.call.validator.ValidateAndMeasurePageInner( | 178 mock.call.validator.ValidateAndMeasurePageInner( |
183 page, mock.ANY, mock.ANY)] | 179 page, mock.ANY, mock.ANY)] |
184 self.assertTrue(manager.mock_calls == expected) | 180 self.assertTrue(manager.mock_calls == expected) |
OLD | NEW |