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

Side by Side Diff: third_party/WebKit/Tools/Scripts/webkitpy/tool/commands/flakytests_unittest.py

Issue 1939843002: Replace webkitpy standalone builders functions with instantiable class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved builders out of port, updated comment Created 4 years, 7 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
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 flakytests 5 import flakytests
6 6
7 from webkitpy.common.checkout.scm.scm_mock import MockSCM 7 from webkitpy.common.checkout.scm.scm_mock import MockSCM
8 from webkitpy.layout_tests.layout_package import bot_test_expectations 8 from webkitpy.layout_tests.layout_package import bot_test_expectations
9 from webkitpy.layout_tests.port import builders 9 from webkitpy.layout_tests.builders import Builders
10 from webkitpy.tool.commands.commandtest import CommandsTest 10 from webkitpy.tool.commands.commandtest import CommandsTest
11 from webkitpy.tool.mocktool import MockTool, MockOptions 11 from webkitpy.tool.mocktool import MockTool, MockOptions
12 12
13 13
14 class FakeBuilders(Builders):
15
16 def __init__(self):
17 super(FakeBuilders, self).__init__()
18 self._exact_matches = {
19 "foo-builder": {"port_name": "dummy-port", "specifiers": ['Linux', ' Release']},
20 "bar-builder": {"port_name": "dummy-port", "specifiers": ['Mac', 'De bug']},
21 }
22
23
14 class FakeBotTestExpectations(object): 24 class FakeBotTestExpectations(object):
15 25
16 def expectation_lines(self, only_ignore_very_flaky=False): 26 def expectation_lines(self, only_ignore_very_flaky=False):
17 return [] 27 return []
18 28
19 29
20 class FakeBotTestExpectationsFactory(object): 30 class FakeBotTestExpectationsFactory(object):
21 FAILURE_MAP = {"A": "AUDIO", "C": "CRASH", "F": "TEXT", "I": "IMAGE", "O": " MISSING", 31 FAILURE_MAP = {"A": "AUDIO", "C": "CRASH", "F": "TEXT", "I": "IMAGE", "O": " MISSING",
22 "N": "NO DATA", "P": "PASS", "T": "TIMEOUT", "Y": "NOTRUN", " X": "SKIP", 32 "N": "NO DATA", "P": "PASS", "T": "TIMEOUT", "Y": "NOTRUN", " X": "SKIP",
23 "Z": "IMAGE+TEXT", "K": "LEAK"} 33 "Z": "IMAGE+TEXT", "K": "LEAK"}
24 34
35 def __init__(self, builders):
36 self.builders = builders
37
25 def _expectations_from_test_data(self, builder, test_data): 38 def _expectations_from_test_data(self, builder, test_data):
26 test_data[bot_test_expectations.ResultsJSON.FAILURE_MAP_KEY] = self.FAIL URE_MAP 39 test_data[bot_test_expectations.ResultsJSON.FAILURE_MAP_KEY] = self.FAIL URE_MAP
27 json_dict = { 40 json_dict = {
28 builder: test_data, 41 builder: test_data,
29 } 42 }
30 results = bot_test_expectations.ResultsJSON(builder, json_dict) 43 results = bot_test_expectations.ResultsJSON(builder, json_dict)
31 return bot_test_expectations.BotTestExpectations(results, builders._exac t_matches[builder]["specifiers"]) 44 return bot_test_expectations.BotTestExpectations(results, self.builders, self.builders._exact_matches[builder]["specifiers"])
32 45
33 def expectations_for_builder(self, builder): 46 def expectations_for_builder(self, builder):
34 if builder == 'foo-builder': 47 if builder == 'foo-builder':
35 return self._expectations_from_test_data(builder, { 48 return self._expectations_from_test_data(builder, {
36 'tests': { 49 'tests': {
37 'pass.html': {'results': [[2, 'FFFP']], 'expected': 'PASS'}, 50 'pass.html': {'results': [[2, 'FFFP']], 'expected': 'PASS'},
38 } 51 }
39 }) 52 })
40 53
41 if builder == 'bar-builder': 54 if builder == 'bar-builder':
42 return self._expectations_from_test_data(builder, { 55 return self._expectations_from_test_data(builder, {
43 'tests': { 56 'tests': {
44 'pass.html': {'results': [[2, 'TTTP']], 'expected': 'PASS'}, 57 'pass.html': {'results': [[2, 'TTTP']], 'expected': 'PASS'},
45 } 58 }
46 }) 59 })
47 60
48 return FakeBotTestExpectations() 61 return FakeBotTestExpectations()
49 62
50 63
51 class FlakyTestsTest(CommandsTest): 64 class FlakyTestsTest(CommandsTest):
52 65
53 def test_merge_lines(self): 66 def test_merge_lines(self):
54 command = flakytests.FlakyTests() 67 command = flakytests.FlakyTests()
55 factory = FakeBotTestExpectationsFactory() 68 factory = FakeBotTestExpectationsFactory(FakeBuilders())
56 69
57 old_builders = builders._exact_matches 70 lines = command._collect_expectation_lines(['foo-builder', 'bar-builder' ], factory)
58 builders._exact_matches = { 71 self.assertEqual(len(lines), 1)
59 "foo-builder": {"port_name": "dummy-port", "specifiers": ['Linux', ' Release']}, 72 self.assertEqual(lines[0].expectations, ['TEXT', 'TIMEOUT', 'PASS'])
60 "bar-builder": {"port_name": "dummy-port", "specifiers": ['Mac', 'De bug']}, 73 self.assertEqual(lines[0].specifiers, ['Mac', 'Linux'])
61 }
62
63 try:
64 lines = command._collect_expectation_lines(['foo-builder', 'bar-buil der'], factory)
65 self.assertEqual(len(lines), 1)
66 self.assertEqual(lines[0].expectations, ['TEXT', 'TIMEOUT', 'PASS'])
67 self.assertEqual(lines[0].specifiers, ['Mac', 'Linux'])
68 finally:
69 builders._exact_matches = old_builders
70 74
71 def test_integration(self): 75 def test_integration(self):
72 command = flakytests.FlakyTests() 76 command = flakytests.FlakyTests()
73 tool = MockTool() 77 tool = MockTool()
78 tool.builders = FakeBuilders()
74 command.expectations_factory = FakeBotTestExpectationsFactory 79 command.expectations_factory = FakeBotTestExpectationsFactory
75 options = MockOptions(upload=True) 80 options = MockOptions(upload=True)
76 expected_stdout = flakytests.FlakyTests.OUTPUT % ( 81 expected_stdout = flakytests.FlakyTests.OUTPUT % (
77 flakytests.FlakyTests.HEADER, 82 flakytests.FlakyTests.HEADER,
78 '', 83 '',
79 flakytests.FlakyTests.FLAKINESS_DASHBOARD_URL % '') + '\n' 84 flakytests.FlakyTests.FLAKINESS_DASHBOARD_URL % '') + '\n'
80 85
81 self.assert_execute_outputs(command, options=options, tool=tool, expecte d_stdout=expected_stdout) 86 self.assert_execute_outputs(command, options=options, tool=tool, expecte d_stdout=expected_stdout)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698