| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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 optparse |
| 6 |
| 5 from webkitpy.common.checkout.baselineoptimizer import BaselineOptimizer | 7 from webkitpy.common.checkout.baselineoptimizer import BaselineOptimizer |
| 6 from webkitpy.layout_tests.controllers.test_result_writer import TestResultWrite
r | |
| 7 from webkitpy.tool.commands.analyze_baselines import AnalyzeBaselines | 8 from webkitpy.tool.commands.analyze_baselines import AnalyzeBaselines |
| 8 from webkitpy.tool.commands.rebaseline_unittest import BaseTestCase | 9 from webkitpy.tool.commands.rebaseline_unittest import BaseTestCase |
| 9 from webkitpy.tool.mock_tool import MockOptions | |
| 10 | 10 |
| 11 | 11 |
| 12 class _FakeOptimizer(BaselineOptimizer): | 12 class _FakeOptimizer(BaselineOptimizer): |
| 13 | 13 |
| 14 def read_results_by_directory(self, baseline_name): | 14 def read_results_by_directory(self, baseline_name): |
| 15 if baseline_name.endswith('txt'): | 15 if baseline_name.endswith('txt'): |
| 16 return {'LayoutTests/passes/text.html': '123456'} | 16 return {'LayoutTests/passes/text.html': '123456'} |
| 17 return {} | 17 return {} |
| 18 | 18 |
| 19 | 19 |
| 20 class TestAnalyzeBaselines(BaseTestCase): | 20 class TestAnalyzeBaselines(BaseTestCase): |
| 21 command_constructor = AnalyzeBaselines | 21 command_constructor = AnalyzeBaselines |
| 22 | 22 |
| 23 def setUp(self): | 23 def setUp(self): |
| 24 super(TestAnalyzeBaselines, self).setUp() | 24 super(TestAnalyzeBaselines, self).setUp() |
| 25 self.port = self.tool.port_factory.get('test') | 25 self.port = self.tool.port_factory.get('test') |
| 26 self.tool.port_factory.get = (lambda port_name=None, options=None: self.
port) | 26 self.tool.port_factory.get = (lambda port_name=None, options=None: self.
port) |
| 27 self.lines = [] | 27 self.lines = [] |
| 28 self.command._optimizer_class = _FakeOptimizer | 28 self.command._optimizer_class = _FakeOptimizer |
| 29 self.command._write = (lambda msg: self.lines.append(msg)) | 29 self.command._write = (lambda msg: self.lines.append(msg)) |
| 30 | 30 |
| 31 def test_default(self): | 31 def test_default(self): |
| 32 self.command.execute(MockOptions(suffixes='txt', missing=False, platform
=None), ['passes/text.html'], self.tool) | 32 self.command.execute(optparse.Values(dict(suffixes='txt', missing=False,
platform=None)), ['passes/text.html'], self.tool) |
| 33 self.assertEqual(self.lines, | 33 self.assertEqual(self.lines, |
| 34 ['passes/text-expected.txt:', | 34 ['passes/text-expected.txt:', |
| 35 ' (generic): 123456']) | 35 ' (generic): 123456']) |
| 36 | 36 |
| 37 def test_missing_baselines(self): | 37 def test_missing_baselines(self): |
| 38 self.command.execute(MockOptions(suffixes='png,txt', missing=True, platf
orm=None), ['passes/text.html'], self.tool) | 38 self.command.execute(optparse.Values(dict(suffixes='png,txt', missing=Tr
ue, platform=None)), ['passes/text.html'], self.tool) |
| 39 self.assertEqual(self.lines, | 39 self.assertEqual(self.lines, |
| 40 ['passes/text-expected.png: (no baselines found)', | 40 ['passes/text-expected.png: (no baselines found)', |
| 41 'passes/text-expected.txt:', | 41 'passes/text-expected.txt:', |
| 42 ' (generic): 123456']) | 42 ' (generic): 123456']) |
| OLD | NEW |