More debug queue build fixing.
[WebKit-https.git] / Tools / Scripts / webkitpy / tool / commands / earlywarningsystem_unittest.py
1 # Copyright (C) 2009 Google Inc. All rights reserved.
2 #
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are
5 # met:
6 #
7 #    * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
9 #    * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer
11 # in the documentation and/or other materials provided with the
12 # distribution.
13 #    * Neither the name of Google Inc. nor the names of its
14 # contributors may be used to endorse or promote products derived from
15 # this software without specific prior written permission.
16 #
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 from webkitpy.thirdparty.mock import Mock
30 from webkitpy.common.host import Host
31 from webkitpy.common.net.layouttestresults import LayoutTestResults
32 from webkitpy.common.system.outputcapture import OutputCapture
33 from webkitpy.layout_tests.models import test_results
34 from webkitpy.layout_tests.models import test_failures
35 from webkitpy.port.factory import PortFactory
36 from webkitpy.tool.bot.queueengine import QueueEngine
37 from webkitpy.tool.commands.earlywarningsystem import *
38 from webkitpy.tool.commands.queues import PatchProcessingQueue
39 from webkitpy.tool.commands.queuestest import QueuesTest
40 from webkitpy.tool.mocktool import MockTool, MockOptions
41
42
43 class AbstractEarlyWarningSystemTest(QueuesTest):
44     def test_failing_tests_message(self):
45         # Needed to define port_name, used in AbstractEarlyWarningSystem.__init__
46         class TestEWS(AbstractEarlyWarningSystem):
47             port_name = "win"  # Needs to be a port which port/factory understands.
48
49         ews = TestEWS()
50         ews.bind_to_tool(MockTool())
51         ews._options = MockOptions(port=None, confirm=False)
52         OutputCapture().assert_outputs(self, ews.begin_work_queue, expected_logs=self._default_begin_work_queue_logs(ews.name))
53         task = Mock()
54         task.results_from_patch_test_run = lambda a: LayoutTestResults([test_results.TestResult("foo.html", failures=[test_failures.FailureTextMismatch()]),
55                                                                           test_results.TestResult("bar.html", failures=[test_failures.FailureTextMismatch()])],
56                                                                           did_exceed_test_failure_limit=False)
57         patch = ews._tool.bugs.fetch_attachment(10000)
58         self.assertMultiLineEqual(ews._failing_tests_message(task, patch), "New failing tests:\nfoo.html\nbar.html")
59
60
61 class EarlyWarningSystemTest(QueuesTest):
62     def _default_expected_logs(self, ews):
63         string_replacements = {
64             "name": ews.name,
65             "port": ews.port_name,
66             "architecture": " --architecture=%s" % ews.architecture if ews.architecture else "",
67             "build_style": ews.build_style(),
68         }
69         if ews.run_tests:
70             run_tests_line = "Running: webkit-patch --status-host=example.com build-and-test --no-clean --no-update --test --non-interactive --build-style=%(build_style)s --port=%(port)s%(architecture)s\n" % string_replacements
71         else:
72             run_tests_line = ""
73         string_replacements['run_tests_line'] = run_tests_line
74
75         expected_logs = {
76             "begin_work_queue": self._default_begin_work_queue_logs(ews.name),
77             "process_work_item": """Running: webkit-patch --status-host=example.com clean --port=%(port)s%(architecture)s
78 Running: webkit-patch --status-host=example.com update --port=%(port)s%(architecture)s
79 Running: webkit-patch --status-host=example.com apply-attachment --no-update --non-interactive 10000 --port=%(port)s%(architecture)s
80 Running: webkit-patch --status-host=example.com build --no-clean --no-update --build-style=%(build_style)s --port=%(port)s%(architecture)s
81 %(run_tests_line)sMOCK: update_status: %(name)s Pass
82 MOCK: release_work_item: %(name)s 10000
83 """ % string_replacements,
84             "handle_unexpected_error": "Mock error message\n",
85             "handle_script_error": "ScriptError error message\n\nMOCK output\n",
86         }
87         return expected_logs
88
89     def _test_ews(self, ews):
90         ews.bind_to_tool(MockTool())
91         options = Mock()
92         options.port = None
93         options.run_tests = ews.run_tests
94         self.assert_queue_outputs(ews, expected_logs=self._default_expected_logs(ews), options=options)
95
96     def test_ewses(self):
97         classes = AbstractEarlyWarningSystem.load_ews_classes()
98         self.assertTrue(classes)
99         self.maxDiff = None
100         for ews_class in classes:
101             self._test_ews(ews_class())