def _test_check_test_expectations(self, filename): capture = OutputCapture() options = MockOptions() options.git_commit = "" options.non_interactive = True tool = MockTool() tool.user = None # Will cause any access of tool.user to raise an exception. step = Commit(tool, options) state = { "changed_files": [filename + "XXX"], } tool.executive = MockExecutive(should_log=True, should_throw_when_run=False) expected_logs = "Committed r49824: <http://trac.webkit.org/changeset/49824>\n" capture.assert_outputs(self, step.run, [state], expected_logs=expected_logs) state = { "changed_files": ["platform/chromium/" + filename], } expected_logs = """MOCK run_and_throw_if_fail: ['mock-check-webkit-style', '--diff-files', 'platform/chromium/%s'], cwd=/mock-checkout Committed r49824: <http://trac.webkit.org/changeset/49824> """ % filename capture.assert_outputs(self, step.run, [state], expected_logs=expected_logs) tool.executive = MockExecutive(should_log=True, should_throw_when_run=set(["platform/chromium/" + filename])) self.assertRaises(ScriptError, capture.assert_outputs, self, step.run, [state])
def test_guess_reviewer_from_multipatch_bug(self): capture = OutputCapture() step = UpdateChangeLogsWithReviewer(MockTool(), MockOptions()) expected_stderr = "Guessing \"Reviewer2\" as reviewer from attachment 10001 on bug 50000.\n" capture.assert_outputs(self, step._guess_reviewer_from_bug, [50000], expected_stderr=expected_stderr)
def test_guess_reviewer_from_bug(self): capture = OutputCapture() step = UpdateChangeLogsWithReviewer(MockTool(), MockOptions()) expected_stderr = "No reviewed patches on bug 50001, cannot infer reviewer.\n" capture.assert_outputs(self, step._guess_reviewer_from_bug, [50001], expected_stderr=expected_stderr)
def test_check_test_expectations(self): capture = OutputCapture() options = MockOptions() options.git_commit = "" tool = MockTool() step = Commit(tool, options) state = { "changed_files": ["test_expectations.txtXXX"], } tool.executive = MockExecutive(should_log=True, should_throw_when_run=False) capture.assert_outputs( self, step.run, [state], expected_stderr= "Committed r49824: <http://trac.webkit.org/changeset/49824>\n") state = { "changed_files": ["platform/chromium/test_expectations.txt"], } capture.assert_outputs( self, step.run, [state], expected_stderr= "MOCK run_and_throw_if_fail: ['mock-check-webkit-style', '--diff-files', 'platform/chromium/test_expectations.txt'], cwd=/mock-checkout\nCommitted r49824: <http://trac.webkit.org/changeset/49824>\n" ) tool.executive = MockExecutive( should_log=True, should_throw_when_run=set( ["platform/chromium/test_expectations.txt"])) self.assertRaises(SystemExit, capture.assert_outputs, self, step.run, [state])
def test_check_test_expectations(self): capture = OutputCapture() options = MockOptions() options.git_commit = "" tool = MockTool() step = Commit(tool, options) state = {"changed_files": ["test_expectations.txtXXX"]} tool.executive = MockExecutive(should_log=True, should_throw_when_run=False) capture.assert_outputs( self, step.run, [state], expected_stderr="Committed r49824: <http://trac.webkit.org/changeset/49824>\n" ) state = {"changed_files": ["platform/chromium/test_expectations.txt"]} capture.assert_outputs( self, step.run, [state], expected_stderr="MOCK run_and_throw_if_fail: ['mock-check-webkit-style', '--diff-files', 'platform/chromium/test_expectations.txt'], cwd=/mock-checkout\nCommitted r49824: <http://trac.webkit.org/changeset/49824>\n", ) tool.executive = MockExecutive( should_log=True, should_throw_when_run=set(["platform/chromium/test_expectations.txt"]) ) self.assertRaises(SystemExit, capture.assert_outputs, self, step.run, [state])
def test_build_driver(self): output = OutputCapture() port = TestWebKitPort() # Delay setting _executive to avoid logging during construction port._executive = MockExecutive(should_log=True) port._options = MockOptions( configuration="Release" ) # This should not be necessary, but I think TestWebKitPort is actually reading from disk (and thus detects the current configuration). expected_stderr = "MOCK run_command: ['Tools/Scripts/build-dumprendertree', '--release'], cwd=/mock-checkout\n" self.assertTrue( output.assert_outputs(self, port._build_driver, expected_stderr=expected_stderr)) # Make sure when passed --webkit-test-runner web build the right tool. port._options = MockOptions(webkit_test_runner=True, configuration="Release") expected_stderr = "MOCK run_command: ['Tools/Scripts/build-webkittestrunner', '--release'], cwd=/mock-checkout\n" self.assertTrue( output.assert_outputs(self, port._build_driver, expected_stderr=expected_stderr)) # Make sure that failure to build returns False. port._executive = MockExecutive(should_log=True, should_throw=True) expected_stderr = "MOCK run_command: ['Tools/Scripts/build-webkittestrunner', '--release'], cwd=/mock-checkout\n" self.assertFalse( output.assert_outputs(self, port._build_driver, expected_stderr=expected_stderr))
def test_build_driver(self): output = OutputCapture() port = TestWebKitPort() # Delay setting _executive to avoid logging during construction port._executive = MockExecutive(should_log=True) port._options = MockOptions(configuration="Release") # This should not be necessary, but I think TestWebKitPort is actually reading from disk (and thus detects the current configuration). expected_stderr = "MOCK run_command: ['Tools/Scripts/build-dumprendertree', '--release'], cwd=/mock-checkout, env={'LC_ALL': 'C', 'MOCK_ENVIRON_COPY': '1'}\n" self.assertTrue(output.assert_outputs(self, port._build_driver, expected_stderr=expected_stderr, expected_logs='')) # Make sure when passed --webkit-test-runner we build the right tool. port._options = MockOptions(webkit_test_runner=True, configuration="Release") expected_stderr = "MOCK run_command: ['Tools/Scripts/build-dumprendertree', '--release'], cwd=/mock-checkout, env={'LC_ALL': 'C', 'MOCK_ENVIRON_COPY': '1'}\nMOCK run_command: ['Tools/Scripts/build-webkittestrunner', '--release'], cwd=/mock-checkout, env={'LC_ALL': 'C', 'MOCK_ENVIRON_COPY': '1'}\n" self.assertTrue(output.assert_outputs(self, port._build_driver, expected_stderr=expected_stderr, expected_logs='')) # Make sure we show the build log when --verbose is passed, which we simulate by setting the logging level to DEBUG. output.set_log_level(logging.DEBUG) port._options = MockOptions(configuration="Release") expected_stderr = "MOCK run_command: ['Tools/Scripts/build-dumprendertree', '--release'], cwd=/mock-checkout, env={'LC_ALL': 'C', 'MOCK_ENVIRON_COPY': '1'}\n" expected_logs = "Output of ['Tools/Scripts/build-dumprendertree', '--release']:\nMOCK output of child process\n" self.assertTrue(output.assert_outputs(self, port._build_driver, expected_stderr=expected_stderr, expected_logs=expected_logs)) output.set_log_level(logging.INFO) # Make sure that failure to build returns False. port._executive = MockExecutive(should_log=True, should_throw=True) # Because WK2 currently has to build both webkittestrunner and DRT, if DRT fails, that's the only one it tries. expected_stderr = "MOCK run_command: ['Tools/Scripts/build-dumprendertree', '--release'], cwd=/mock-checkout, env={'LC_ALL': 'C', 'MOCK_ENVIRON_COPY': '1'}\n" expected_logs = "MOCK ScriptError\n\nMOCK output of child process\n" self.assertFalse(output.assert_outputs(self, port._build_driver, expected_stderr=expected_stderr, expected_logs=expected_logs))
def test_empty_state(self): capture = OutputCapture() options = MockOptions() options.reviewer = 'MOCK reviewer' options.git_commit = 'MOCK git commit' step = UpdateChangeLogsWithReviewer(MockTool(), options) capture.assert_outputs(self, step.run, [{}])
def test_basic(self): capture = OutputCapture() step = SuggestReviewers(MockTool(), MockOptions(suggest_reviewers=True, git_commit=None)) expected_stdout = "The following reviewers have recently modified files in your patch:\nFoo Bar\n" expected_logs = "Would you like to CC them?\n" capture.assert_outputs( self, step.run, [{"bug_id": "123"}], expected_stdout=expected_stdout, expected_logs=expected_logs )
def test_empty_state(self): capture = OutputCapture() step = CloseBugForLandDiff(MockTool(), MockOptions()) expected_logs = "Committed r49824: <http://trac.webkit.org/changeset/49824>\nNo bug id provided.\n" capture.assert_outputs(self, step.run, [{ "commit_text": "Mock commit text" }], expected_logs=expected_logs)
def test_warn_if_application_is_xcode(self): output = OutputCapture() user = User() output.assert_outputs(self, user._warn_if_application_is_xcode, ["TextMate"]) output.assert_outputs(self, user._warn_if_application_is_xcode, ["/Applications/TextMate.app"]) output.assert_outputs(self, user._warn_if_application_is_xcode, ["XCode"]) # case sensitive matching xcode_warning = "Instead of using Xcode.app, consider using EDITOR=\"xed --wait\".\n" output.assert_outputs(self, user._warn_if_application_is_xcode, ["Xcode"], expected_stdout=xcode_warning) output.assert_outputs(self, user._warn_if_application_is_xcode, ["/Developer/Applications/Xcode.app"], expected_stdout=xcode_warning)
def test_basic(self): capture = OutputCapture() step = SuggestReviewers( MockTool(), MockOptions(suggest_reviewers=True, git_commit=None)) expected_stdout = "The following reviewers have recently modified files in your patch:\nFoo Bar\n" expected_logs = "Would you like to CC them?\n" capture.assert_outputs(self, step.run, [{ "bug_id": "123" }], expected_stdout=expected_stdout, expected_logs=expected_logs)
def test_run(self): capture = OutputCapture() options = MockOptions(git_commit="MOCK git commit") files = {"/Users/mock/.subversion/config": "enable-auto-props = yes\n*.png = svn:mime-type=image/png"} fs = MockFileSystem(files) scm = MockSCMDetector("git") step = AddSvnMimetypeForPng(MockTool(), options, MockSystemHost(os_name="linux", filesystem=fs), scm) state = {"changed_files": ["test.png", "test.txt"]} try: capture.assert_outputs(self, step.run, [state]) except SystemExit, e: self.assertEquals(e.code, 1)
def test_apply_watch_list_local(self): capture = OutputCapture() step = ApplyWatchList(MockTool(log_executive=True), MockOptions()) state = { 'bug_id': '50001', 'diff': 'The diff', } expected_logs = """MockWatchList: determine_cc_and_messages MOCK bug comment: bug_id=50001, cc=set(['*****@*****.**']) --- Begin comment --- Message2. --- End comment --- """ capture.assert_outputs(self, step.run, [state], expected_logs=expected_logs)
def test_ensure_bug_url(self): capture = OutputCapture() step = PrepareChangeLog(MockTool(), MockOptions()) changelog_contents = u"%s\n%s" % (self._new_entry_boilerplate, self._example_changelog) changelog_path = "ChangeLog" state = {"bug_title": "Example title", "bug_id": 1234, "changelogs": [changelog_path]} step._tool.filesystem = MockFileSystem() step._tool.filesystem.write_text_file(changelog_path, changelog_contents) capture.assert_outputs(self, step._ensure_bug_url, [state]) actual_contents = step._tool.filesystem.read_text_file(changelog_path) expected_message = "Example title\n http://example.com/1234" expected_contents = changelog_contents.replace( "Need a short description (OOPS!).\n Need the bug URL (OOPS!).", expected_message ) self.assertEqual(actual_contents, expected_contents)
def test_ensure_bug_url(self): capture = OutputCapture() step = PrepareChangeLog(MockTool(), Mock()) changelog_contents = u"%s\n%s" % (self._new_entry_boilerplate, self._example_changelog) changelog_path = self._write_tmp_file_with_contents(changelog_contents.encode("utf-8")) state = { "bug_title": "Example title", "bug_id": 1234, "changelogs": [changelog_path], } capture.assert_outputs(self, step.run, [state]) actual_contents = self._read_file_contents(changelog_path, "utf-8") expected_message = "Example title\n http://example.com/1234" expected_contents = changelog_contents.replace("Need a short description and bug URL (OOPS!)", expected_message) os.remove(changelog_path) self.assertEquals(actual_contents, expected_contents)
def _test_terminating_queue(self, exception, expected_message): work_item_index = LoggingDelegate.expected_callbacks.index('process_work_item') # The terminating error should be handled right after process_work_item. # There should be no other callbacks after stop_work_queue. expected_callbacks = LoggingDelegate.expected_callbacks[:work_item_index + 1] expected_callbacks.append("stop_work_queue") delegate = RaisingDelegate(self, exception) work_queue = QueueEngine("terminating-queue", delegate, threading.Event()) output = OutputCapture() expected_stderr = "\n%s\n" % expected_message output.assert_outputs(self, work_queue.run, [], expected_stderr=expected_stderr) self.assertEquals(delegate._callbacks, expected_callbacks) self.assertEquals(delegate.stop_message, expected_message)
def test_commit_message_for_this_commit(self): checkout = Checkout(None) checkout.modified_changelogs = lambda: ["ChangeLog1", "ChangeLog2"] output = OutputCapture() expected_stderr = "Parsing ChangeLog: ChangeLog1\nParsing ChangeLog: ChangeLog2\n" commit_message = output.assert_outputs(self, checkout.commit_message_for_this_commit, expected_stderr=expected_stderr) self.assertEqual(commit_message.message(), self.expected_commit_message)
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_ensure_bug_url(self): capture = OutputCapture() step = PrepareChangeLog(MockTool(), MockOptions()) changelog_contents = u"%s\n%s" % (self._new_entry_boilerplate, self._example_changelog) changelog_path = self._write_tmp_file_with_contents(changelog_contents.encode("utf-8")) state = { "bug_title": "Example title", "bug_id": 1234, "changelogs": [changelog_path], } capture.assert_outputs(self, step.run, [state]) actual_contents = self._read_file_contents(changelog_path, "utf-8") expected_message = "Example title\n http://example.com/1234" expected_contents = changelog_contents.replace("Need a short description and bug URL (OOPS!)", expected_message) os.remove(changelog_path) self.assertEquals(actual_contents, expected_contents)
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_run(self): capture = OutputCapture() options = MockOptions(git_commit='MOCK git commit') files = {'/Users/mock/.subversion/config': 'enable-auto-props = yes\n*.png = svn:mime-type=image/png'} fs = MockFileSystem(files) scm = MockSCMDetector('git') step = AddSvnMimetypeForPng(MockTool(), options, MockSystemHost(os_name='linux', filesystem=fs), scm) state = { "changed_files": ["test.png", "test.txt"], } try: capture.assert_outputs(self, step.run, [state]) except SystemExit, e: self.assertEqual(e.code, 1)
def test_ensure_bug_url(self): capture = OutputCapture() step = PrepareChangeLog(MockTool(), MockOptions()) changelog_contents = u"%s\n%s" % (self._new_entry_boilerplate, self._example_changelog) changelog_path = "ChangeLog" state = { "bug_title": "Example title", "bug_id": 1234, "changelogs": [changelog_path], } step._tool.filesystem = MockFileSystem() step._tool.filesystem.write_text_file(changelog_path, changelog_contents) capture.assert_outputs(self, step._ensure_bug_url, [state]) actual_contents = step._tool.filesystem.read_text_file(changelog_path) expected_message = "Example title\n http://example.com/1234" expected_contents = changelog_contents.replace("Need a short description (OOPS!).\n Need the bug URL (OOPS!).", expected_message) self.assertEqual(actual_contents, expected_contents)
def run_prompt_test(inputs, expected_result, can_choose_multiple=False): def mock_raw_input(message): return inputs.pop(0) output_capture = OutputCapture() actual_result = output_capture.assert_outputs( self, User.prompt_with_list, args=["title", ["foo", "bar"]], kwargs={"can_choose_multiple": can_choose_multiple, "raw_input": mock_raw_input}, expected_stdout="title\n 1. foo\n 2. bar\n") self.assertEqual(actual_result, expected_result) self.assertEqual(len(inputs), 0)
def test_commit_message_for_this_commit(self): checkout = Checkout(None) checkout.modified_changelogs = lambda git_commit, changed_files=None: [ "ChangeLog1", "ChangeLog2" ] output = OutputCapture() expected_stderr = "Parsing ChangeLog: ChangeLog1\nParsing ChangeLog: ChangeLog2\n" commit_message = output.assert_outputs( self, checkout.commit_message_for_this_commit, kwargs={"git_commit": None}, expected_stderr=expected_stderr) self.assertEqual(commit_message.message(), self.expected_commit_message)
def test_build_driver(self): output = OutputCapture() port = TestWebKitPort() # Delay setting _executive to avoid logging during construction port._executive = MockExecutive(should_log=True) port._options = MockOptions( configuration="Release" ) # This should not be necessary, but I think TestWebKitPort is actually reading from disk (and thus detects the current configuration). expected_stderr = "MOCK run_command: ['Tools/Scripts/build-dumprendertree', '--release'], cwd=/mock-checkout\n" self.assertTrue(output.assert_outputs(self, port._build_driver, expected_stderr=expected_stderr)) # Make sure when passed --webkit-test-runner web build the right tool. port._options = MockOptions(webkit_test_runner=True, configuration="Release") expected_stderr = ( "MOCK run_command: ['Tools/Scripts/build-webkittestrunner', '--release'], cwd=/mock-checkout\n" ) self.assertTrue(output.assert_outputs(self, port._build_driver, expected_stderr=expected_stderr)) # Make sure that failure to build returns False. port._executive = MockExecutive(should_log=True, should_throw=True) expected_stderr = ( "MOCK run_command: ['Tools/Scripts/build-webkittestrunner', '--release'], cwd=/mock-checkout\n" ) self.assertFalse(output.assert_outputs(self, port._build_driver, expected_stderr=expected_stderr))
def test_guess_reviewer_from_bug(self): capture = OutputCapture() step = UpdateChangeLogsWithReviewer(MockTool(), MockOptions()) expected_stderr = "0 reviewed patches on bug 75, cannot infer reviewer.\n" capture.assert_outputs(self, step._guess_reviewer_from_bug, [75], expected_stderr=expected_stderr)
def test_empty_state(self): capture = OutputCapture() step = UpdateChangeLogsWithReviewer(MockTool(), MockOptions()) capture.assert_outputs(self, step.run, [{}])
def test_empty_state(self): capture = OutputCapture() step = CloseBugForLandDiff(MockTool(), MockOptions()) expected_stderr = "Committed r49824: <http://trac.webkit.org/changeset/49824>\nNo bug id provided.\n" capture.assert_outputs(self, step.run, [{"commit_text" : "Mock commit text"}], expected_stderr=expected_stderr)
def test_guess_reviewer_from_multipatch_bug(self): capture = OutputCapture() step = UpdateChangeLogsWithReviewer(MockTool(), MockOptions()) expected_logs = "Guessing \"Reviewer2\" as reviewer from attachment 10001 on bug 50000.\n" capture.assert_outputs(self, step._guess_reviewer_from_bug, [50000], expected_logs=expected_logs)
def test_empty_state(self): capture = OutputCapture() step = UpdateChangeLogsWithReviewer(MockTool(), Mock()) capture.assert_outputs(self, step.run, [{}])