WebKitTools/Scripts/webkitpy/tool/commands/download_unittest.py
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     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 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 
       
    57 class DownloadCommandsTest(CommandsTest):
       
    58     def _default_options(self):
       
    59         options = MockOptions()
       
    60         options.force_clean = False
       
    61         options.clean = True
       
    62         options.check_builders = True
       
    63         options.quiet = False
       
    64         options.non_interactive = False
       
    65         options.update = True
       
    66         options.build = True
       
    67         options.test = True
       
    68         options.close_bug = True
       
    69         return options
       
    70 
       
    71     def test_build(self):
       
    72         expected_stderr = "Updating working directory\nBuilding WebKit\n"
       
    73         self.assert_execute_outputs(Build(), [], options=self._default_options(), expected_stderr=expected_stderr)
       
    74 
       
    75     def test_build_and_test(self):
       
    76         expected_stderr = "Updating working directory\nBuilding WebKit\nRunning Python unit tests\nRunning Perl unit tests\nRunning JavaScriptCore tests\nRunning run-webkit-tests\n"
       
    77         self.assert_execute_outputs(BuildAndTest(), [], options=self._default_options(), expected_stderr=expected_stderr)
       
    78 
       
    79     def test_apply_attachment(self):
       
    80         options = self._default_options()
       
    81         options.update = True
       
    82         options.local_commit = True
       
    83         expected_stderr = "Updating working directory\nProcessing 1 patch from 1 bug.\nProcessing patch 197 from bug 42.\n"
       
    84         self.assert_execute_outputs(ApplyAttachment(), [197], options=options, expected_stderr=expected_stderr)
       
    85 
       
    86     def test_apply_patches(self):
       
    87         options = self._default_options()
       
    88         options.update = True
       
    89         options.local_commit = True
       
    90         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"
       
    91         self.assert_execute_outputs(ApplyFromBug(), [42], options=options, expected_stderr=expected_stderr)
       
    92 
       
    93     def test_land_diff(self):
       
    94         expected_stderr = "Building WebKit\nRunning Python unit tests\nRunning Perl unit tests\nRunning JavaScriptCore tests\nRunning run-webkit-tests\nUpdating bug 42\n"
       
    95         mock_tool = MockTool()
       
    96         mock_tool.scm().create_patch = Mock()
       
    97         mock_tool.checkout().modified_changelogs = Mock(return_value=[])
       
    98         self.assert_execute_outputs(Land(), [42], options=self._default_options(), expected_stderr=expected_stderr, tool=mock_tool)
       
    99         # Make sure we're not calling expensive calls too often.
       
   100         self.assertEqual(mock_tool.scm().create_patch.call_count, 0)
       
   101         self.assertEqual(mock_tool.checkout().modified_changelogs.call_count, 1)
       
   102 
       
   103     def test_check_style(self):
       
   104         expected_stderr = "Processing 1 patch from 1 bug.\nUpdating working directory\nProcessing patch 197 from bug 42.\nRunning check-webkit-style\n"
       
   105         self.assert_execute_outputs(CheckStyle(), [197], options=self._default_options(), expected_stderr=expected_stderr)
       
   106 
       
   107     def test_build_attachment(self):
       
   108         expected_stderr = "Processing 1 patch from 1 bug.\nUpdating working directory\nProcessing patch 197 from bug 42.\nBuilding WebKit\n"
       
   109         self.assert_execute_outputs(BuildAttachment(), [197], options=self._default_options(), expected_stderr=expected_stderr)
       
   110 
       
   111     def test_post_attachment_to_rietveld(self):
       
   112         expected_stderr = "Processing 1 patch from 1 bug.\nUpdating working directory\nProcessing patch 197 from bug 42.\nMOCK: Uploading patch to rietveld\nMOCK setting flag 'in-rietveld' to '+' on attachment '197' with comment 'None' and additional comment 'None'\n"
       
   113         self.assert_execute_outputs(PostAttachmentToRietveld(), [197], options=self._default_options(), expected_stderr=expected_stderr)
       
   114 
       
   115     def test_land_attachment(self):
       
   116         # 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.
       
   117         expected_stderr = """Processing 1 patch from 1 bug.
       
   118 Updating working directory
       
   119 Processing patch 197 from bug 42.
       
   120 Building WebKit
       
   121 Running Python unit tests
       
   122 Running Perl unit tests
       
   123 Running JavaScriptCore tests
       
   124 Running run-webkit-tests
       
   125 Not closing bug 42 as attachment 197 has review=+.  Assuming there are more patches to land from this bug.
       
   126 """
       
   127         self.assert_execute_outputs(LandAttachment(), [197], options=self._default_options(), expected_stderr=expected_stderr)
       
   128 
       
   129     def test_land_patches(self):
       
   130         # 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.
       
   131         expected_stderr = """2 reviewed patches found on bug 42.
       
   132 Processing 2 patches from 1 bug.
       
   133 Updating working directory
       
   134 Processing patch 197 from bug 42.
       
   135 Building WebKit
       
   136 Running Python unit tests
       
   137 Running Perl unit tests
       
   138 Running JavaScriptCore tests
       
   139 Running run-webkit-tests
       
   140 Not closing bug 42 as attachment 197 has review=+.  Assuming there are more patches to land from this bug.
       
   141 Updating working directory
       
   142 Processing patch 128 from bug 42.
       
   143 Building WebKit
       
   144 Running Python unit tests
       
   145 Running Perl unit tests
       
   146 Running JavaScriptCore tests
       
   147 Running run-webkit-tests
       
   148 Not closing bug 42 as attachment 197 has review=+.  Assuming there are more patches to land from this bug.
       
   149 """
       
   150         self.assert_execute_outputs(LandFromBug(), [42], options=self._default_options(), expected_stderr=expected_stderr)
       
   151 
       
   152     def test_prepare_rollout(self):
       
   153         expected_stderr = "Preparing rollout for bug 42.\nUpdating working directory\nRunning prepare-ChangeLog\n"
       
   154         self.assert_execute_outputs(PrepareRollout(), [852, "Reason"], options=self._default_options(), expected_stderr=expected_stderr)
       
   155 
       
   156     def test_create_rollout(self):
       
   157         expected_stderr = """Preparing rollout for bug 42.
       
   158 Updating working directory
       
   159 MOCK create_bug
       
   160 bug_title: REGRESSION(r852): Reason
       
   161 bug_description: http://trac.webkit.org/changeset/852 broke the build:
       
   162 Reason
       
   163 Running prepare-ChangeLog
       
   164 MOCK add_patch_to_bug: bug_id=None, description=ROLLOUT of r852, mark_for_review=False, mark_for_commit_queue=True, mark_for_landing=False
       
   165 -- Begin comment --
       
   166 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.
       
   167 
       
   168 If you would like to land the rollout faster, you can use the following command:
       
   169 
       
   170   webkit-patch land-attachment ATTACHMENT_ID --ignore-builders
       
   171 
       
   172 where ATTACHMENT_ID is the ID of this attachment.
       
   173 -- End comment --
       
   174 """
       
   175         self.assert_execute_outputs(CreateRollout(), [852, "Reason"], options=self._default_options(), expected_stderr=expected_stderr)
       
   176 
       
   177     def test_rollout(self):
       
   178         expected_stderr = "Preparing rollout for bug 42.\nUpdating working directory\nRunning prepare-ChangeLog\nMOCK: user.open_url: file://...\nBuilding WebKit\n"
       
   179         self.assert_execute_outputs(Rollout(), [852, "Reason"], options=self._default_options(), expected_stderr=expected_stderr)
       
   180