WebKitTools/Scripts/webkitpy/tool/commands/queuestest.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.net.bugzilla import Attachment
       
    32 from webkitpy.common.system.outputcapture import OutputCapture
       
    33 from webkitpy.common.system.executive import ScriptError
       
    34 from webkitpy.thirdparty.mock import Mock
       
    35 from webkitpy.tool.mocktool import MockTool
       
    36 
       
    37 
       
    38 class MockQueueEngine(object):
       
    39     def __init__(self, name, queue, wakeup_event):
       
    40         pass
       
    41 
       
    42     def run(self):
       
    43         pass
       
    44 
       
    45 
       
    46 class MockPatch():
       
    47     def id(self):
       
    48         return 1234
       
    49 
       
    50     def bug_id(self):
       
    51         return 345
       
    52 
       
    53 
       
    54 class QueuesTest(unittest.TestCase):
       
    55     mock_work_item = Attachment({
       
    56         "id": 1234,
       
    57         "bug_id": 345,
       
    58         "name": "Patch",
       
    59         "attacher_email": "adam@example.com",
       
    60     }, None)
       
    61 
       
    62     def assert_outputs(self, func, func_name, args, expected_stdout, expected_stderr, expected_exceptions):
       
    63         exception = None
       
    64         if expected_exceptions and func_name in expected_exceptions:
       
    65             exception = expected_exceptions[func_name]
       
    66 
       
    67         OutputCapture().assert_outputs(self,
       
    68                 func,
       
    69                 args=args,
       
    70                 expected_stdout=expected_stdout.get(func_name, ""),
       
    71                 expected_stderr=expected_stderr.get(func_name, ""),
       
    72                 expected_exception=exception)
       
    73 
       
    74     def assert_queue_outputs(self, queue, args=None, work_item=None, expected_stdout=None, expected_stderr=None, expected_exceptions=None, options=Mock(), tool=MockTool()):
       
    75         if not expected_stdout:
       
    76             expected_stdout = {}
       
    77         if not expected_stderr:
       
    78             expected_stderr = {}
       
    79         if not args:
       
    80             args = []
       
    81         if not work_item:
       
    82             work_item = self.mock_work_item
       
    83         tool.user.prompt = lambda message: "yes"
       
    84 
       
    85         queue.execute(options, args, tool, engine=MockQueueEngine)
       
    86 
       
    87         self.assert_outputs(queue.queue_log_path, "queue_log_path", [], expected_stdout, expected_stderr, expected_exceptions)
       
    88         self.assert_outputs(queue.work_item_log_path, "work_item_log_path", [work_item], expected_stdout, expected_stderr, expected_exceptions)
       
    89         self.assert_outputs(queue.begin_work_queue, "begin_work_queue", [], expected_stdout, expected_stderr, expected_exceptions)
       
    90         self.assert_outputs(queue.should_continue_work_queue, "should_continue_work_queue", [], expected_stdout, expected_stderr, expected_exceptions)
       
    91         self.assert_outputs(queue.next_work_item, "next_work_item", [], expected_stdout, expected_stderr, expected_exceptions)
       
    92         self.assert_outputs(queue.should_proceed_with_work_item, "should_proceed_with_work_item", [work_item], expected_stdout, expected_stderr, expected_exceptions)
       
    93         self.assert_outputs(queue.process_work_item, "process_work_item", [work_item], expected_stdout, expected_stderr, expected_exceptions)
       
    94         self.assert_outputs(queue.handle_unexpected_error, "handle_unexpected_error", [work_item, "Mock error message"], expected_stdout, expected_stderr, expected_exceptions)
       
    95         self.assert_outputs(queue.handle_script_error, "handle_script_error", [tool, {"patch": MockPatch()}, ScriptError(message="ScriptError error message", script_args="MockErrorCommand")], expected_stdout, expected_stderr, expected_exceptions)