| OLD | NEW |
| (Empty) |
| 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 webkitpy.thirdparty.unittest2 as 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, seconds_to_sleep): | |
| 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(10000) | |
| 50 | |
| 51 def assert_outputs(self, func, func_name, args, expected_stdout, expected_st
derr, expected_exceptions, expected_logs): | |
| 52 exception = None | |
| 53 if expected_exceptions and func_name in expected_exceptions: | |
| 54 exception = expected_exceptions[func_name] | |
| 55 | |
| 56 logs = None | |
| 57 if expected_logs and func_name in expected_logs: | |
| 58 logs = expected_logs[func_name] | |
| 59 | |
| 60 OutputCapture().assert_outputs(self, | |
| 61 func, | |
| 62 args=args, | |
| 63 expected_stdout=expected_stdout.get(func_name, ""), | |
| 64 expected_stderr=expected_stderr.get(func_name, ""), | |
| 65 expected_exception=exception, | |
| 66 expected_logs=logs) | |
| 67 | |
| 68 def _default_begin_work_queue_stderr(self, name): | |
| 69 string_replacements = {"name": name} | |
| 70 return "MOCK: update_status: %(name)s Starting Queue\n" % string_replace
ments | |
| 71 | |
| 72 def _default_begin_work_queue_logs(self, name): | |
| 73 checkout_dir = '/mock-checkout' | |
| 74 string_replacements = {"name": name, 'checkout_dir': checkout_dir} | |
| 75 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 | |
| 76 | |
| 77 def assert_queue_outputs(self, queue, args=None, work_item=None, expected_st
dout=None, expected_stderr=None, expected_exceptions=None, expected_logs=None, o
ptions=None, tool=None): | |
| 78 if not tool: | |
| 79 tool = MockTool() | |
| 80 # This is a hack to make it easy for callers to not have to setup a
custom MockFileSystem just to test the commit-queue | |
| 81 # the cq tries to read the layout test results, and will hit a KeyEr
ror in MockFileSystem if we don't do this. | |
| 82 tool.filesystem.write_text_file('/mock-results/full_results.json', "
") | |
| 83 if not expected_stdout: | |
| 84 expected_stdout = {} | |
| 85 if not expected_stderr: | |
| 86 expected_stderr = {} | |
| 87 if not args: | |
| 88 args = [] | |
| 89 if not options: | |
| 90 options = Mock() | |
| 91 options.port = None | |
| 92 if not work_item: | |
| 93 work_item = self.mock_work_item | |
| 94 tool.user.prompt = lambda message: "yes" | |
| 95 | |
| 96 queue.execute(options, args, tool, engine=MockQueueEngine) | |
| 97 | |
| 98 self.assert_outputs(queue.queue_log_path, "queue_log_path", [], expected
_stdout, expected_stderr, expected_exceptions, expected_logs) | |
| 99 self.assert_outputs(queue.work_item_log_path, "work_item_log_path", [wor
k_item], expected_stdout, expected_stderr, expected_exceptions, expected_logs) | |
| 100 self.assert_outputs(queue.begin_work_queue, "begin_work_queue", [], expe
cted_stdout, expected_stderr, expected_exceptions, expected_logs) | |
| 101 self.assert_outputs(queue.should_continue_work_queue, "should_continue_w
ork_queue", [], expected_stdout, expected_stderr, expected_exceptions, expected_
logs) | |
| 102 self.assert_outputs(queue.next_work_item, "next_work_item", [], expected
_stdout, expected_stderr, expected_exceptions, expected_logs) | |
| 103 self.assert_outputs(queue.process_work_item, "process_work_item", [work_
item], expected_stdout, expected_stderr, expected_exceptions, expected_logs) | |
| 104 self.assert_outputs(queue.handle_unexpected_error, "handle_unexpected_er
ror", [work_item, "Mock error message"], expected_stdout, expected_stderr, expec
ted_exceptions, expected_logs) | |
| 105 # Should we have a different function for testing StepSequenceErrorHandl
ers? | |
| 106 if isinstance(queue, StepSequenceErrorHandler): | |
| 107 self.assert_outputs(queue.handle_script_error, "handle_script_error"
, [tool, {"patch": self.mock_work_item}, ScriptError(message="ScriptError error
message", script_args="MockErrorCommand", output="MOCK output")], expected_stdou
t, expected_stderr, expected_exceptions, expected_logs) | |
| OLD | NEW |