d8c602a875b45621e6f0f35433c7602ec500f1c3
[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.system.outputcapture import OutputCapture
31 from webkitpy.tool.bot.queueengine import QueueEngine
32 from webkitpy.tool.commands.earlywarningsystem import *
33 from webkitpy.tool.commands.queuestest import QueuesTest
34 from webkitpy.tool.mocktool import MockTool, MockOptions
35
36
37 class AbstractEarlyWarningSystemTest(QueuesTest):
38     def test_failing_tests_message(self):
39         # Needed to define port_name, used in AbstractEarlyWarningSystem.__init__
40         class TestEWS(AbstractEarlyWarningSystem):
41             port_name = "win"  # Needs to be a port which port/factory understands.
42
43         ews = TestEWS()
44         ews.bind_to_tool(MockTool())
45         ews._options = MockOptions(port=None, confirm=False)
46         OutputCapture().assert_outputs(self, ews.begin_work_queue, expected_logs=self._default_begin_work_queue_logs(ews.name))
47         ews._expected_failures.unexpected_failures_observed = lambda results: set(["foo.html", "bar.html"])
48         task = Mock()
49         patch = ews._tool.bugs.fetch_attachment(10000)
50         self.assertMultiLineEqual(ews._failing_tests_message(task, patch), "New failing tests:\nbar.html\nfoo.html")
51
52
53 class EarlyWarningSystemTest(QueuesTest):
54     def _default_expected_logs(self, ews):
55         string_replacements = {
56             "name": ews.name,
57             "port": ews.port_name,
58         }
59         if ews._default_run_tests:
60             run_tests_line = "Running: webkit-patch --status-host=example.com build-and-test --no-clean --no-update --test --non-interactive --port=%(port)s\n" % string_replacements
61         else:
62             run_tests_line = ""
63         string_replacements['run_tests_line'] = run_tests_line
64
65         expected_logs = {
66             "begin_work_queue": self._default_begin_work_queue_logs(ews.name),
67             "process_work_item": """Running: webkit-patch --status-host=example.com clean --port=%(port)s
68 Running: webkit-patch --status-host=example.com update --port=%(port)s
69 Running: webkit-patch --status-host=example.com apply-attachment --no-update --non-interactive 10000 --port=%(port)s
70 Running: webkit-patch --status-host=example.com build --no-clean --no-update --build-style=release --port=%(port)s
71 %(run_tests_line)sMOCK: update_status: %(name)s Pass
72 MOCK: release_work_item: %(name)s 10000
73 """ % string_replacements,
74             "handle_unexpected_error": "Mock error message\n",
75             "handle_script_error": "ScriptError error message\n\nMOCK output\n",
76         }
77         return expected_logs
78
79     def _test_ews(self, ews):
80         ews.bind_to_tool(MockTool())
81         options = Mock()
82         options.port = None
83         options.run_tests = ews._default_run_tests
84         self.assert_queue_outputs(ews, expected_logs=self._default_expected_logs(ews), options=options)
85
86     def test_ewses(self):
87         self._test_ews(MacEWS())
88         self._test_ews(MacWK2EWS())
89         self._test_ews(QtEWS())
90         self._test_ews(QtWK2EWS())
91         self._test_ews(GtkEWS())
92         self._test_ews(EflEWS())