| # Copyright (C) 2009 Google Inc. All rights reserved. |
| # Copyright (C) 2019-2020 Apple Inc. All rights reserved. |
| # |
| # Redistribution and use in source and binary forms, with or without |
| # modification, are permitted provided that the following conditions are |
| # met: |
| # |
| # * Redistributions of source code must retain the above copyright |
| # notice, this list of conditions and the following disclaimer. |
| # * Redistributions in binary form must reproduce the above |
| # copyright notice, this list of conditions and the following disclaimer |
| # in the documentation and/or other materials provided with the |
| # distribution. |
| # * Neither the name of Google Inc. nor the names of its |
| # contributors may be used to endorse or promote products derived from |
| # this software without specific prior written permission. |
| # |
| # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| |
| from webkitpy.thirdparty.mock import Mock |
| from webkitpy.tool.commands.commandtest import CommandsTest |
| from webkitpy.tool.commands.queues import * |
| from webkitpy.tool.mocktool import MockTool |
| |
| from webkitcorepy import OutputCapture |
| |
| |
| class TestQueue(AbstractPatchQueue): |
| name = "test-queue" |
| |
| |
| class AbstractQueueTest(CommandsTest): |
| def test_log_directory(self): |
| self.assertEqual(TestQueue()._log_directory(), os.path.join("..", "test-queue-logs")) |
| |
| def _assert_run_webkit_patch(self, run_args, port=None): |
| queue = TestQueue() |
| tool = MockTool() |
| tool.executive = Mock() |
| queue.bind_to_tool(tool) |
| queue._options = Mock() |
| queue._options.port = port |
| |
| queue.run_webkit_patch(run_args) |
| expected_run_args = ["echo"] |
| if port: |
| expected_run_args.append("--port=%s" % port) |
| expected_run_args.extend(run_args) |
| tool.executive.run_command.assert_called_with(expected_run_args, cwd='/mock-checkout') |
| |
| def test_run_webkit_patch(self): |
| self._assert_run_webkit_patch([1]) |
| self._assert_run_webkit_patch(["one", 2]) |
| self._assert_run_webkit_patch([1], port="mockport") |
| |
| def test_iteration_count(self): |
| queue = TestQueue() |
| queue._options = Mock() |
| queue._options.iterations = 3 |
| self.assertTrue(queue.should_continue_work_queue()) |
| self.assertTrue(queue.should_continue_work_queue()) |
| self.assertTrue(queue.should_continue_work_queue()) |
| self.assertFalse(queue.should_continue_work_queue()) |
| |
| def test_no_iteration_count(self): |
| queue = TestQueue() |
| queue._options = Mock() |
| self.assertTrue(queue.should_continue_work_queue()) |
| self.assertTrue(queue.should_continue_work_queue()) |
| self.assertTrue(queue.should_continue_work_queue()) |
| self.assertTrue(queue.should_continue_work_queue()) |
| |
| |
| |
| class PatchProcessingQueueTest(CommandsTest): |
| def test_upload_results_archive_for_patch(self): |
| queue = PatchProcessingQueue() |
| queue.name = "mock-queue" |
| tool = MockTool() |
| queue.bind_to_tool(tool) |
| queue._options = Mock() |
| queue._options.port = None |
| patch = queue._tool.bugs.fetch_attachment(10001) |
| |
| with OutputCapture(level=logging.INFO) as captured: |
| queue._upload_results_archive_for_patch(patch, Mock()) |
| self.assertEqual( |
| captured.root.log.getvalue(), |
| """MOCK add_attachment_to_bug: bug_id=50000, description=Archive of layout-test-results for mac-highsierra filename=layout-test-results.zip mimetype=None |
| -- Begin comment -- |
| The attached test failures were seen while running run-webkit-tests on the mock-queue. |
| Port: mac-highsierra Platform: MockPlatform 1.0 |
| -- End comment -- |
| """, |
| ) |