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 Bugzilla 32 from webkitpy.thirdparty.mock import Mock 33 from webkitpy.tool.commands.commandtest import CommandsTest 34 from webkitpy.tool.commands.queries import * 35 from webkitpy.tool.mocktool import MockTool 36 37 38 class QueryCommandsTest(CommandsTest): 39 def test_bugs_to_commit(self): 40 expected_stderr = "Warning, attachment 128 on bug 42 has invalid committer (non-committer (at] example.com)\n" 41 self.assert_execute_outputs(BugsToCommit(), None, "42\n77\n", expected_stderr) 42 43 def test_patches_in_commit_queue(self): 44 expected_stdout = "http://example.com/197\nhttp://example.com/103\n" 45 expected_stderr = "Warning, attachment 128 on bug 42 has invalid committer (non-committer (at] example.com)\nPatches in commit queue:\n" 46 self.assert_execute_outputs(PatchesInCommitQueue(), None, expected_stdout, expected_stderr) 47 48 def test_patches_to_commit_queue(self): 49 expected_stdout = "http://example.com/104&action=edit\n" 50 expected_stderr = "197 already has cq=+\n128 already has cq=+\n105 committer = \"Eric Seidel\" <eric (at] webkit.org>\n" 51 options = Mock() 52 options.bugs = False 53 self.assert_execute_outputs(PatchesToCommitQueue(), None, expected_stdout, expected_stderr, options=options) 54 55 expected_stdout = "http://example.com/77\n" 56 options.bugs = True 57 self.assert_execute_outputs(PatchesToCommitQueue(), None, expected_stdout, expected_stderr, options=options) 58 59 def test_patches_to_review(self): 60 expected_stdout = "103\n" 61 expected_stderr = "Patches pending review:\n" 62 self.assert_execute_outputs(PatchesToReview(), None, expected_stdout, expected_stderr) 63 64 def test_tree_status(self): 65 expected_stdout = "ok : Builder1\nok : Builder2\n" 66 self.assert_execute_outputs(TreeStatus(), None, expected_stdout) 67 68 def test_skipped_ports(self): 69 expected_stdout = "Ports skipping test 'media/foo/bar.html': test_port1, test_port2\n" 70 self.assert_execute_outputs(SkippedPorts(), ("media/foo/bar.html",), expected_stdout) 71 72 expected_stdout = "Ports skipping test 'foo': test_port1\n" 73 self.assert_execute_outputs(SkippedPorts(), ("foo",), expected_stdout) 74 75 expected_stdout = "Test 'media' is not skipped by any port.\n" 76 self.assert_execute_outputs(SkippedPorts(), ("media",), expected_stdout) 77 78 79 class FailureReasonTest(unittest.TestCase): 80 def test_blame_line_for_revision(self): 81 tool = MockTool() 82 command = FailureReason() 83 command.bind_to_tool(tool) 84 # This is an artificial example, mostly to test the CommitInfo lookup failure case. 85 self.assertEquals(command._blame_line_for_revision(None), "FAILED to fetch CommitInfo for rNone, likely missing ChangeLog") 86 87 def raising_mock(self): 88 raise Exception("MESSAGE") 89 tool.checkout().commit_info_for_revision = raising_mock 90 self.assertEquals(command._blame_line_for_revision(None), "FAILED to fetch CommitInfo for rNone, exception: MESSAGE") 91