def run(): sheriff = Sheriff(MockTool(), MockSheriffBot()) builders = [Builder("Foo", None), Builder("Bar", None)] commit_info = Mock() commit_info.bug_id = lambda: None commit_info.revision = lambda: 4321 # Should do nothing with no bug_id sheriff.post_blame_comment_on_bug(commit_info, builders, []) sheriff.post_blame_comment_on_bug(commit_info, builders, ["mock-test-1", "mock-test-2"]) # Should try to post a comment to the bug, but MockTool.bugs does nothing. commit_info.bug_id = lambda: 1234 sheriff.post_blame_comment_on_bug(commit_info, builders, []) sheriff.post_blame_comment_on_bug(commit_info, builders, ["mock-test-1"]) sheriff.post_blame_comment_on_bug(commit_info, builders, ["mock-test-1", "mock-test-2"])
def test_mark_bug_fixed(self): tool = MockTool() tool._scm.last_svn_commit_log = lambda: "r9876 |" options = Mock() options.bug_id = 50000 options.comment = "MOCK comment" expected_logs = """Bug: <http://example.com/50000> Bug with two r+'d and cq+'d patches, one of which has an invalid commit-queue setter. Revision: 9876 MOCK: user.open_url: http://example.com/50000 Is this correct? Adding comment to Bug 50000. MOCK bug comment: bug_id=50000, cc=None, see_also=None --- Begin comment --- MOCK comment Committed r9876 (5@main): <https://commits.webkit.org/5@main> --- End comment --- """ with mocks.Requests( 'commits.webkit.org', **{ 'r9876/json': mocks.Response.fromJson( dict( identifier='5@main', revision=9876, )), }): self.assert_execute_outputs(MarkBugFixed(), [], expected_logs=expected_logs, tool=tool, options=options)
def test_mark_bug_fixed(self): tool = MockTool() tool._scm.last_svn_commit_log = lambda: "r9876 |" options = Mock() options.bug_id = 42 options.comment = "MOCK comment" expected_stderr = "Bug: <http://example.com/42> Bug with two r+'d and cq+'d patches, one of which has an invalid commit-queue setter.\nRevision: 9876\nMOCK: user.open_url: http://example.com/42\nAdding comment to Bug 42.\nMOCK bug comment: bug_id=42, cc=None\n--- Begin comment ---\nMOCK comment\n\nCommitted r9876: <http://trac.webkit.org/changeset/9876>\n--- End comment ---\n\n" self.assert_execute_outputs(MarkBugFixed(), [], expected_stderr=expected_stderr, tool=tool, options=options)
def test_mark_bug_fixed(self): tool = MockTool() tool._scm.last_svn_commit_log = lambda: "r9876 |" options = Mock() options.bug_id = 42 options.comment = "MOCK comment" expected_stderr = "Bug: <http://example.com/42> Bug with two r+'d and cq+'d patches, one of which has an invalid commit-queue setter.\nRevision: 9876\nMOCK: user.open_url: http://example.com/42\nAdding comment to Bug 42.\nMOCK bug comment: bug_id=42, cc=None\n--- WebKitTools/Begin comment ---\\MOCK comment\n\nCommitted r9876: <http://trac.webkit.org/changeset/9876>\n--- WebKitTools/End comment ---\n\n" self.assert_execute_outputs(MarkBugFixed(), [], expected_stderr=expected_stderr, tool=tool, options=options)
def run(): sheriff = Sheriff(MockTool(), MockSheriffBot()) builders = [ Builder("Foo", None), Builder("Bar", None), ] commit_info = Mock() commit_info.bug_id = lambda: None commit_info.revision = lambda: 4321 # Should do nothing with no bug_id sheriff.post_blame_comment_on_bug(commit_info, builders, []) sheriff.post_blame_comment_on_bug(commit_info, builders, ["mock-test-1", "mock-test-2"]) # Should try to post a comment to the bug, but MockTool.bugs does nothing. commit_info.bug_id = lambda: 1234 sheriff.post_blame_comment_on_bug(commit_info, builders, []) sheriff.post_blame_comment_on_bug(commit_info, builders, ["mock-test-1"]) sheriff.post_blame_comment_on_bug(commit_info, builders, ["mock-test-1", "mock-test-2"])
def test_post_blame_comment_on_bug(self): sheriff = Sheriff(MockTool(), MockSheriffBot()) builders = [ Builder("Foo", None), Builder("Bar", None), ] commit_info = Mock() commit_info.bug_id = lambda: None commit_info.revision = lambda: 4321 commit_info.committer = lambda: None commit_info.committer_email = lambda: "*****@*****.**" commit_info.reviewer = lambda: None commit_info.author = lambda: None sheriff.post_automatic_rollout_patch(commit_info, builders)
def test_commit_info(self): command = AbstractRolloutPrepCommand() tool = MockTool() command.bind_to_tool(tool) output = OutputCapture() expected_stderr = "Preparing rollout for bug 42.\n" commit_info = output.assert_outputs(self, command._commit_info, [1234], expected_stderr=expected_stderr) self.assertTrue(commit_info) mock_commit_info = Mock() mock_commit_info.bug_id = lambda: None tool._checkout.commit_info_for_revision = lambda revision: mock_commit_info expected_stderr = "Unable to parse bug number from diff.\n" commit_info = output.assert_outputs(self, command._commit_info, [1234], expected_stderr=expected_stderr) self.assertEqual(commit_info, mock_commit_info)
def test_commit_info(self): command = AbstractRolloutPrepCommand() tool = MockTool() command.bind_to_tool(tool) output = OutputCapture() expected_logs = "Preparing rollout for bug 50000.\n" commit_info = output.assert_outputs(self, command._commit_info, [1234], expected_logs=expected_logs) self.assertTrue(commit_info) mock_commit_info = Mock() mock_commit_info.bug_id = lambda: None tool._checkout.commit_info_for_revision = lambda revision: mock_commit_info expected_logs = "Unable to parse bug number from diff.\n" commit_info = output.assert_outputs(self, command._commit_info, [1234], expected_logs=expected_logs) self.assertEqual(commit_info, mock_commit_info)
def test_commit_info(self): command = AbstractRevertPrepCommand() tool = MockTool() command.bind_to_tool(tool) with OutputCapture(level=logging.INFO) as captured: commit_info = command._commit_info(1234) self.assertEqual(captured.root.log.getvalue(), 'Preparing revert for bug 50000.\n') self.assertTrue(commit_info) mock_commit_info = Mock() mock_commit_info.bug_id = lambda: None tool._checkout.commit_info_for_revision = lambda revision: mock_commit_info with OutputCapture(level=logging.INFO) as captured: commit_info = command._commit_info(1234) self.assertEqual(captured.root.log.getvalue(), 'Unable to parse bug number from diff.\n') self.assertEqual(commit_info, mock_commit_info)
def test_mark_bug_fixed(self): tool = MockTool() tool._scm.last_svn_commit_log = lambda: "r9876 |" options = Mock() options.bug_id = 50000 options.comment = "MOCK comment" expected_stderr = """Bug: <http://example.com/50000> Bug with two r+'d and cq+'d patches, one of which has an invalid commit-queue setter. Revision: 9876 MOCK: user.open_url: http://example.com/50000 Is this correct? Adding comment to Bug 50000. MOCK bug comment: bug_id=50000, cc=None --- Begin comment --- MOCK comment Committed r9876: <http://trac.webkit.org/changeset/9876> --- End comment --- """ self.assert_execute_outputs(MarkBugFixed(), [], expected_stderr=expected_stderr, tool=tool, options=options)
def test_mark_bug_fixed(self): tool = MockTool() tool._scm.last_svn_commit_log = lambda: "r9876 |" options = Mock() options.bug_id = 50000 options.comment = "MOCK comment" expected_logs = """Bug: <http://example.com/50000> Bug with two r+'d and cq+'d patches, one of which has an invalid commit-queue setter. Revision: 9876 MOCK: user.open_url: http://example.com/50000 Is this correct? Adding comment to Bug 50000. MOCK bug comment: bug_id=50000, cc=None, see_also=None --- Begin comment --- MOCK comment Committed r9876: <https://trac.webkit.org/changeset/9876> --- End comment --- """ self.assert_execute_outputs(MarkBugFixed(), [], expected_logs=expected_logs, tool=tool, options=options)