Clean up ChunkedUpdateDrawingAreaProxy
[WebKit-https.git] / WebKitTools / Scripts / webkitpy / tool / commands / queuestest.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.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.commands.stepsequence import StepSequenceErrorHandler
36 from webkitpy.tool.mocktool import MockTool
37
38
39 class MockQueueEngine(object):
40     def __init__(self, name, queue, wakeup_event):
41         pass
42
43     def run(self):
44         pass
45
46
47 class QueuesTest(unittest.TestCase):
48     # This is _patch1 in mocktool.py
49     mock_work_item = MockTool().bugs.fetch_attachment(197)
50
51     def assert_outputs(self, func, func_name, args, expected_stdout, expected_stderr, expected_exceptions):
52         exception = None
53         if expected_exceptions and func_name in expected_exceptions:
54             exception = expected_exceptions[func_name]
55
56         OutputCapture().assert_outputs(self,
57                 func,
58                 args=args,
59                 expected_stdout=expected_stdout.get(func_name, ""),
60                 expected_stderr=expected_stderr.get(func_name, ""),
61                 expected_exception=exception)
62
63     def _default_begin_work_queue_stderr(self, name, checkout_dir):
64         string_replacements = {"name": name, 'checkout_dir': checkout_dir}
65         return "CAUTION: %(name)s will discard all local changes in \"%(checkout_dir)s\"\nRunning WebKit %(name)s.\nMOCK: update_status: %(name)s Starting Queue\n" % string_replacements
66
67     def assert_queue_outputs(self, queue, args=None, work_item=None, expected_stdout=None, expected_stderr=None, expected_exceptions=None, options=None, tool=None):
68         if not tool:
69             tool = MockTool()
70         if not expected_stdout:
71             expected_stdout = {}
72         if not expected_stderr:
73             expected_stderr = {}
74         if not args:
75             args = []
76         if not options:
77             options = Mock()
78             options.port = None
79         if not work_item:
80             work_item = self.mock_work_item
81         tool.user.prompt = lambda message: "yes"
82
83         queue.execute(options, args, tool, engine=MockQueueEngine)
84
85         self.assert_outputs(queue.queue_log_path, "queue_log_path", [], expected_stdout, expected_stderr, expected_exceptions)
86         self.assert_outputs(queue.work_item_log_path, "work_item_log_path", [work_item], expected_stdout, expected_stderr, expected_exceptions)
87         self.assert_outputs(queue.begin_work_queue, "begin_work_queue", [], expected_stdout, expected_stderr, expected_exceptions)
88         self.assert_outputs(queue.should_continue_work_queue, "should_continue_work_queue", [], expected_stdout, expected_stderr, expected_exceptions)
89         self.assert_outputs(queue.next_work_item, "next_work_item", [], expected_stdout, expected_stderr, expected_exceptions)
90         self.assert_outputs(queue.should_proceed_with_work_item, "should_proceed_with_work_item", [work_item], expected_stdout, expected_stderr, expected_exceptions)
91         self.assert_outputs(queue.process_work_item, "process_work_item", [work_item], expected_stdout, expected_stderr, expected_exceptions)
92         self.assert_outputs(queue.handle_unexpected_error, "handle_unexpected_error", [work_item, "Mock error message"], expected_stdout, expected_stderr, expected_exceptions)
93         # Should we have a different function for testing StepSequenceErrorHandlers?
94         if isinstance(queue, StepSequenceErrorHandler):
95             self.assert_outputs(queue.handle_script_error, "handle_script_error", [tool, {"patch": self.mock_work_item}, ScriptError(message="ScriptError error message", script_args="MockErrorCommand")], expected_stdout, expected_stderr, expected_exceptions)