| 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 | 4 |
| 5 import unittest | 5 import unittest |
| 6 | 6 |
| 7 from telemetry import benchmark | 7 from telemetry import benchmark |
| 8 from telemetry import benchmark_runner | 8 from telemetry import benchmark_runner |
| 9 from telemetry.testing import stream | 9 from telemetry.testing import stream |
| 10 import mock | 10 import mock |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 class BenchmarkRunnerUnittest(unittest.TestCase): | 34 class BenchmarkRunnerUnittest(unittest.TestCase): |
| 35 def setUp(self): | 35 def setUp(self): |
| 36 self._stream = stream.TestOutputStream() | 36 self._stream = stream.TestOutputStream() |
| 37 self._mock_possible_browser = mock.MagicMock() | 37 self._mock_possible_browser = mock.MagicMock() |
| 38 self._mock_possible_browser.browser_type = 'TestBrowser' | 38 self._mock_possible_browser.browser_type = 'TestBrowser' |
| 39 | 39 |
| 40 def testPrintBenchmarkListWithNoDisabledBenchmark(self): | 40 def testPrintBenchmarkListWithNoDisabledBenchmark(self): |
| 41 expected_printed_stream = ( | 41 expected_printed_stream = ( |
| 42 'Available benchmarks for TestBrowser are:\n' | 42 'Available benchmarks for TestBrowser are:\n' |
| 43 ' BarBenchmarkkkkk Benchmark Bar for testing long description line.\n' |
| 43 ' FooBenchmark Benchmark Foo for testing.\n' | 44 ' FooBenchmark Benchmark Foo for testing.\n' |
| 44 ' BarBenchmarkkkkk Benchmark Bar for testing long description line.\n' | |
| 45 'Pass --browser to list benchmarks for another browser.\n\n') | 45 'Pass --browser to list benchmarks for another browser.\n\n') |
| 46 with mock.patch('telemetry.benchmark_runner.decorators') as mock_module: | 46 with mock.patch('telemetry.benchmark_runner.decorators') as mock_module: |
| 47 mock_module.IsEnabled.return_value = (True, None) | 47 mock_module.IsEnabled.return_value = (True, None) |
| 48 benchmark_runner.PrintBenchmarkList( | 48 benchmark_runner.PrintBenchmarkList( |
| 49 [BenchmarkFoo, BenchmarkBar], self._mock_possible_browser, self._stream) | 49 [BenchmarkFoo, BenchmarkBar], self._mock_possible_browser, self._stream) |
| 50 self.assertEquals(expected_printed_stream, self._stream.output_data) | 50 self.assertEquals(expected_printed_stream, self._stream.output_data) |
| 51 | 51 |
| 52 def testPrintBenchmarkListWithOneDisabledBenchmark(self): | 52 def testPrintBenchmarkListWithOneDisabledBenchmark(self): |
| 53 expected_printed_stream = ( | 53 expected_printed_stream = ( |
| 54 'Available benchmarks for TestBrowser are:\n' | 54 'Available benchmarks for TestBrowser are:\n' |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 expected_printed_stream = ( | 91 expected_printed_stream = ( |
| 92 # Expected output for 'TestBrowser': | 92 # Expected output for 'TestBrowser': |
| 93 'Available benchmarks for TestBrowser are:\n' | 93 'Available benchmarks for TestBrowser are:\n' |
| 94 ' FooBenchmark Benchmark Foo for testing.\n' | 94 ' FooBenchmark Benchmark Foo for testing.\n' |
| 95 '\n' | 95 '\n' |
| 96 'Disabled benchmarks for TestBrowser are (force run with -d):\n' | 96 'Disabled benchmarks for TestBrowser are (force run with -d):\n' |
| 97 ' BarBenchmarkkkkk Benchmark Bar for testing long description line.\n' | 97 ' BarBenchmarkkkkk Benchmark Bar for testing long description line.\n' |
| 98 'Pass --browser to list benchmarks for another browser.\n\n' | 98 'Pass --browser to list benchmarks for another browser.\n\n' |
| 99 # Expected output for 'MockBrowser': | 99 # Expected output for 'MockBrowser': |
| 100 'Available benchmarks for MockBrowser are:\n' | 100 'Available benchmarks for MockBrowser are:\n' |
| 101 ' BarBenchmarkkkkk Benchmark Bar for testing long description line.\n' |
| 101 ' FooBenchmark Benchmark Foo for testing.\n' | 102 ' FooBenchmark Benchmark Foo for testing.\n' |
| 102 ' BarBenchmarkkkkk Benchmark Bar for testing long description line.\n' | |
| 103 'Pass --browser to list benchmarks for another browser.\n\n') | 103 'Pass --browser to list benchmarks for another browser.\n\n') |
| 104 @classmethod | 104 @classmethod |
| 105 def FakeShouldDisable(cls, possible_browser): | 105 def FakeShouldDisable(cls, possible_browser): |
| 106 return cls is BenchmarkBar and not 'Mock' in possible_browser.browser_type | 106 return cls is BenchmarkBar and not 'Mock' in possible_browser.browser_type |
| 107 BenchmarkFoo.ShouldDisable = FakeShouldDisable | 107 BenchmarkFoo.ShouldDisable = FakeShouldDisable |
| 108 BenchmarkBar.ShouldDisable = FakeShouldDisable | 108 BenchmarkBar.ShouldDisable = FakeShouldDisable |
| 109 benchmark_runner.PrintBenchmarkList( | 109 benchmark_runner.PrintBenchmarkList( |
| 110 [BenchmarkFoo, BenchmarkBar], self._mock_possible_browser, self._stream) | 110 [BenchmarkFoo, BenchmarkBar], self._mock_possible_browser, self._stream) |
| 111 self._mock_possible_browser.browser_type = 'MockBrowser' | 111 self._mock_possible_browser.browser_type = 'MockBrowser' |
| 112 benchmark_runner.PrintBenchmarkList( | 112 benchmark_runner.PrintBenchmarkList( |
| 113 [BenchmarkFoo, BenchmarkBar], self._mock_possible_browser, self._stream) | 113 [BenchmarkFoo, BenchmarkBar], self._mock_possible_browser, self._stream) |
| 114 self.assertEquals(expected_printed_stream, self._stream.output_data) | 114 self.assertEquals(expected_printed_stream, self._stream.output_data) |
| OLD | NEW |