WebKitTools/Scripts/webkitpy/tool/commands/earlywarningsystem_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 os
       
    30 
       
    31 from webkitpy.thirdparty.mock import Mock
       
    32 from webkitpy.tool.commands.earlywarningsystem import *
       
    33 from webkitpy.tool.commands.queuestest import QueuesTest
       
    34 
       
    35 class EarlyWarningSytemTest(QueuesTest):
       
    36     def test_failed_builds(self):
       
    37         ews = ChromiumLinuxEWS()
       
    38         ews._build = lambda patch, first_run=False: False
       
    39         ews._can_build = lambda: True
       
    40         ews.review_patch(Mock())
       
    41 
       
    42     def _default_expected_stderr(self, ews):
       
    43         string_replacemnts = {
       
    44             "name": ews.name,
       
    45             "checkout_dir": os.getcwd(),  # FIXME: Use of os.getcwd() is wrong, should be scm.checkout_root
       
    46             "port": ews.port_name,
       
    47             "watchers": ews.watchers,
       
    48         }
       
    49         expected_stderr = {
       
    50             "begin_work_queue": "CAUTION: %(name)s will discard all local changes in \"%(checkout_dir)s\"\nRunning WebKit %(name)s.\n" % string_replacemnts,
       
    51             "handle_unexpected_error": "Mock error message\n",
       
    52             "next_work_item": "MOCK: update_work_items: %(name)s [103]\n" % string_replacemnts,
       
    53             "process_work_item": "MOCK: update_status: %(name)s Pass\n" % string_replacemnts,
       
    54             "handle_script_error": "MOCK: update_status: %(name)s ScriptError error message\nMOCK bug comment: bug_id=345, cc=%(watchers)s\n--- Begin comment ---\\Attachment 1234 did not build on %(port)s:\nBuild output: http://dummy_url\n--- End comment ---\n\n" % string_replacemnts,
       
    55         }
       
    56         return expected_stderr
       
    57 
       
    58     def _test_ews(self, ews):
       
    59         expected_exceptions = {
       
    60             "handle_script_error": SystemExit,
       
    61         }
       
    62         self.assert_queue_outputs(ews, expected_stderr=self._default_expected_stderr(ews), expected_exceptions=expected_exceptions)
       
    63 
       
    64     # FIXME: If all EWSes are going to output the same text, we
       
    65     # could test them all in one method with a for loop over an array.
       
    66     def test_chromium_linux_ews(self):
       
    67         self._test_ews(ChromiumLinuxEWS())
       
    68 
       
    69     def test_chromium_windows_ews(self):
       
    70         self._test_ews(ChromiumWindowsEWS())
       
    71 
       
    72     def test_qt_ews(self):
       
    73         self._test_ews(QtEWS())
       
    74 
       
    75     def test_gtk_ews(self):
       
    76         self._test_ews(GtkEWS())
       
    77 
       
    78     def test_mac_ews(self):
       
    79         ews = MacEWS()
       
    80         expected_stderr = self._default_expected_stderr(ews)
       
    81         expected_stderr["process_work_item"] = "MOCK: update_status: mac-ews Error: mac-ews cannot process patches from non-committers :(\n"
       
    82         expected_exceptions = {
       
    83             "handle_script_error": SystemExit,
       
    84         }
       
    85         self.assert_queue_outputs(ews, expected_stderr=expected_stderr, expected_exceptions=expected_exceptions)