Clean up ChunkedUpdateDrawingAreaProxy
[WebKit-https.git] / Tools / Scripts / webkitpy / tool / commands / download_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 import unittest
30
31 from webkitpy.common.system.outputcapture import OutputCapture
32 from webkitpy.thirdparty.mock import Mock
33 from webkitpy.tool.commands.commandtest import CommandsTest
34 from webkitpy.tool.commands.download import *
35 from webkitpy.tool.mocktool import MockCheckout, MockOptions, MockTool
36
37
38 class AbstractRolloutPrepCommandTest(unittest.TestCase):
39     def test_commit_info(self):
40         command = AbstractRolloutPrepCommand()
41         tool = MockTool()
42         command.bind_to_tool(tool)
43         output = OutputCapture()
44
45         expected_stderr = "Preparing rollout for bug 42.\n"
46         commit_info = output.assert_outputs(self, command._commit_info, [1234], expected_stderr=expected_stderr)
47         self.assertTrue(commit_info)
48
49         mock_commit_info = Mock()
50         mock_commit_info.bug_id = lambda: None
51         tool._checkout.commit_info_for_revision = lambda revision: mock_commit_info
52         expected_stderr = "Unable to parse bug number from diff.\n"
53         commit_info = output.assert_outputs(self, command._commit_info, [1234], expected_stderr=expected_stderr)
54         self.assertEqual(commit_info, mock_commit_info)
55
56     def test_prepare_state(self):
57         command = AbstractRolloutPrepCommand()
58         mock_commit_info = MockCheckout().commit_info_for_revision(123)
59         command._commit_info = lambda revision: mock_commit_info
60
61         state = command._prepare_state(None, ["124 123 125", "Reason"], None)
62         self.assertEqual(123, state["revision"])
63         self.assertEqual([123, 124, 125], state["revision_list"])
64
65         self.assertRaises(ScriptError, command._prepare_state, options=None, args=["125 r122  123", "Reason"], tool=None)
66         self.assertRaises(ScriptError, command._prepare_state, options=None, args=["125 foo 123", "Reason"], tool=None)
67
68
69 class DownloadCommandsTest(CommandsTest):
70     def _default_options(self):
71         options = MockOptions()
72         options.build = True
73         options.build_style = True
74         options.check_builders = True
75         options.check_style = True
76         options.clean = True
77         options.close_bug = True
78         options.force_clean = False
79         options.force_patch = True
80         options.non_interactive = False
81         options.parent_command = 'MOCK parent command'
82         options.quiet = False
83         options.test = True
84         options.update = True
85         return options
86
87     def test_build(self):
88         expected_stderr = "Updating working directory\nBuilding WebKit\n"
89         self.assert_execute_outputs(Build(), [], options=self._default_options(), expected_stderr=expected_stderr)
90
91     def test_build_and_test(self):
92         expected_stderr = "Updating working directory\nBuilding WebKit\nRunning Python unit tests\nRunning Perl unit tests\nRunning JavaScriptCore tests\nRunning run-webkit-tests\n"
93         self.assert_execute_outputs(BuildAndTest(), [], options=self._default_options(), expected_stderr=expected_stderr)
94
95     def test_apply_attachment(self):
96         options = self._default_options()
97         options.update = True
98         options.local_commit = True
99         expected_stderr = "Updating working directory\nProcessing 1 patch from 1 bug.\nProcessing patch 197 from bug 42.\n"
100         self.assert_execute_outputs(ApplyAttachment(), [197], options=options, expected_stderr=expected_stderr)
101
102     def test_apply_patches(self):
103         options = self._default_options()
104         options.update = True
105         options.local_commit = True
106         expected_stderr = "Updating working directory\n2 reviewed patches found on bug 42.\nProcessing 2 patches from 1 bug.\nProcessing patch 197 from bug 42.\nProcessing patch 128 from bug 42.\n"
107         self.assert_execute_outputs(ApplyFromBug(), [42], options=options, expected_stderr=expected_stderr)
108
109     def test_land_diff(self):
110         expected_stderr = "Building WebKit\nRunning Python unit tests\nRunning Perl unit tests\nRunning JavaScriptCore tests\nRunning run-webkit-tests\nCommitted r49824: <http://trac.webkit.org/changeset/49824>\nUpdating bug 42\n"
111         mock_tool = MockTool()
112         mock_tool.scm().create_patch = Mock()
113         mock_tool.checkout().modified_changelogs = Mock(return_value=[])
114         self.assert_execute_outputs(Land(), [42], options=self._default_options(), expected_stderr=expected_stderr, tool=mock_tool)
115         # Make sure we're not calling expensive calls too often.
116         self.assertEqual(mock_tool.scm().create_patch.call_count, 0)
117         self.assertEqual(mock_tool.checkout().modified_changelogs.call_count, 1)
118
119     def test_land_red_builders(self):
120         expected_stderr = '\nWARNING: Builders ["Builder2"] are red, please watch your commit carefully.\nSee http://dummy_buildbot_host/console?category=core\n\nBuilding WebKit\nRunning Python unit tests\nRunning Perl unit tests\nRunning JavaScriptCore tests\nRunning run-webkit-tests\nCommitted r49824: <http://trac.webkit.org/changeset/49824>\nUpdating bug 42\n'
121         mock_tool = MockTool()
122         mock_tool.buildbot.light_tree_on_fire()
123         self.assert_execute_outputs(Land(), [42], options=self._default_options(), expected_stderr=expected_stderr, tool=mock_tool)
124
125     def test_check_style(self):
126         expected_stderr = "Processing 1 patch from 1 bug.\nUpdating working directory\nProcessing patch 197 from bug 42.\nRunning check-webkit-style\n"
127         self.assert_execute_outputs(CheckStyle(), [197], options=self._default_options(), expected_stderr=expected_stderr)
128
129     def test_build_attachment(self):
130         expected_stderr = "Processing 1 patch from 1 bug.\nUpdating working directory\nProcessing patch 197 from bug 42.\nBuilding WebKit\n"
131         self.assert_execute_outputs(BuildAttachment(), [197], options=self._default_options(), expected_stderr=expected_stderr)
132
133     def test_land_attachment(self):
134         # FIXME: This expected result is imperfect, notice how it's seeing the same patch as still there after it thought it would have cleared the flags.
135         expected_stderr = """Processing 1 patch from 1 bug.
136 Updating working directory
137 Processing patch 197 from bug 42.
138 Building WebKit
139 Running Python unit tests
140 Running Perl unit tests
141 Running JavaScriptCore tests
142 Running run-webkit-tests
143 Committed r49824: <http://trac.webkit.org/changeset/49824>
144 Not closing bug 42 as attachment 197 has review=+.  Assuming there are more patches to land from this bug.
145 """
146         self.assert_execute_outputs(LandAttachment(), [197], options=self._default_options(), expected_stderr=expected_stderr)
147
148     def test_land_patches(self):
149         # FIXME: This expected result is imperfect, notice how it's seeing the same patch as still there after it thought it would have cleared the flags.
150         expected_stderr = """2 reviewed patches found on bug 42.
151 Processing 2 patches from 1 bug.
152 Updating working directory
153 Processing patch 197 from bug 42.
154 Building WebKit
155 Running Python unit tests
156 Running Perl unit tests
157 Running JavaScriptCore tests
158 Running run-webkit-tests
159 Committed r49824: <http://trac.webkit.org/changeset/49824>
160 Not closing bug 42 as attachment 197 has review=+.  Assuming there are more patches to land from this bug.
161 Updating working directory
162 Processing patch 128 from bug 42.
163 Building WebKit
164 Running Python unit tests
165 Running Perl unit tests
166 Running JavaScriptCore tests
167 Running run-webkit-tests
168 Committed r49824: <http://trac.webkit.org/changeset/49824>
169 Not closing bug 42 as attachment 197 has review=+.  Assuming there are more patches to land from this bug.
170 """
171         self.assert_execute_outputs(LandFromBug(), [42], options=self._default_options(), expected_stderr=expected_stderr)
172
173     def test_prepare_rollout(self):
174         expected_stderr = "Preparing rollout for bug 42.\nUpdating working directory\nRunning prepare-ChangeLog\n"
175         self.assert_execute_outputs(PrepareRollout(), [852, "Reason"], options=self._default_options(), expected_stderr=expected_stderr)
176
177     def test_create_rollout(self):
178         expected_stderr = """Preparing rollout for bug 42.
179 Updating working directory
180 MOCK create_bug
181 bug_title: REGRESSION(r852): Reason
182 bug_description: http://trac.webkit.org/changeset/852 broke the build:
183 Reason
184 component: MOCK component
185 cc: MOCK cc
186 blocked: 42
187 Running prepare-ChangeLog
188 MOCK add_patch_to_bug: bug_id=78, description=ROLLOUT of r852, mark_for_review=False, mark_for_commit_queue=True, mark_for_landing=False
189 -- Begin comment --
190 Any committer can land this patch automatically by marking it commit-queue+.  The commit-queue will build and test the patch before landing to ensure that the rollout will be successful.  This process takes approximately 15 minutes.
191
192 If you would like to land the rollout faster, you can use the following command:
193
194   webkit-patch land-attachment ATTACHMENT_ID --ignore-builders
195
196 where ATTACHMENT_ID is the ID of this attachment.
197 -- End comment --
198 """
199         self.assert_execute_outputs(CreateRollout(), [852, "Reason"], options=self._default_options(), expected_stderr=expected_stderr)
200         self.assert_execute_outputs(CreateRollout(), ["855 852 854", "Reason"], options=self._default_options(), expected_stderr=expected_stderr)
201
202     def test_rollout(self):
203         expected_stderr = "Preparing rollout for bug 42.\nUpdating working directory\nRunning prepare-ChangeLog\nMOCK: user.open_url: file://...\nBuilding WebKit\nCommitted r49824: <http://trac.webkit.org/changeset/49824>\n"
204         expected_stdout = "Was that diff correct?\n"
205         self.assert_execute_outputs(Rollout(), [852, "Reason"], options=self._default_options(), expected_stdout=expected_stdout, expected_stderr=expected_stderr)
206