def test_string_from_args(self): error = ScriptError() self.assertEquals(error._string_from_args(None), "None") self.assertEquals(error._string_from_args([]), "[]") self.assertEquals( error._string_from_args(map(str, range(30))), "['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17'...", )
def test_message_with_output(self): error = ScriptError('My custom message!', '', -1) self.assertEquals(error.message_with_output(), 'My custom message!') error = ScriptError('My custom message!', '', -1, 'My output.') self.assertEquals(error.message_with_output(), 'My custom message!\n\nMy output.') error = ScriptError('', 'my_command!', -1, 'My output.', '/Users/username/blah') self.assertEquals(error.message_with_output(), 'Failed to run "my_command!" exit_code: -1 cwd: /Users/username/blah\n\nMy output.') error = ScriptError('', 'my_command!', -1, 'ab' + '1' * 499) self.assertEquals(error.message_with_output(), 'Failed to run "my_command!" exit_code: -1\n\nLast 500 characters of output:\nb' + '1' * 499)
def test_message_with_output(self): error = ScriptError("My custom message!", "", -1) self.assertEquals(error.message_with_output(), "My custom message!") error = ScriptError("My custom message!", "", -1, "My output.") self.assertEquals(error.message_with_output(), "My custom message!\n\nMy output.") error = ScriptError("", "my_command!", -1, "My output.", "/Users/username/blah") self.assertEquals( error.message_with_output(), 'Failed to run "my_command!" exit_code: -1 cwd: /Users/username/blah\n\nMy output.', ) error = ScriptError("", "my_command!", -1, "ab" + "1" * 499) self.assertEquals( error.message_with_output(), 'Failed to run "my_command!" exit_code: -1\n\nLast 500 characters of output:\nb' + "1" * 499, )
def test_handled_error(self): delegate = RaisingDelegate( self, ScriptError(exit_code=QueueEngine.handled_error_code)) self._run_engine(delegate) self.assertEquals(delegate._callbacks, LoggingDelegate.expected_callbacks)
def __init__(self, script_args, exit_code, output, cwd): ScriptError.__init__(self, script_args=script_args, exit_code=exit_code, output=output, cwd=cwd)
def _run_fn(args): if args[0] == 'git' and args[1] == 'apply': raise ScriptError('MOCK failed applying patch') return ''
def mock_latest_entry_for_changelog_at_revision(path, revision): if path == "foo/ChangeLog": return 'foo' raise ScriptError()
def git_commit_from_svn_revision(self, svn_revision): git_commit = self._run_git_svn_find_rev('r%s' % svn_revision) if not git_commit: # FIXME: Alternatively we could offer to update the checkout? Or return None? raise ScriptError(message='Failed to find git commit for revision %s, your checkout likely needs an update.' % svn_revision) return git_commit
def assert_queue_outputs(self, queue, args=None, work_item=None, expected_stdout=None, expected_stderr=None, expected_exceptions=None, expected_logs=None, options=None, tool=None): if not tool: tool = MockTool() # This is a hack to make it easy for callers to not have to setup a custom MockFileSystem just to test the commit-queue # the cq tries to read the layout test results, and will hit a KeyError in MockFileSystem if we don't do this. tool.filesystem.write_text_file('/mock-results/full_results.json', "") if not expected_stdout: expected_stdout = {} if not expected_stderr: expected_stderr = {} if not args: args = [] if not options: options = Mock() options.port = None if not work_item: work_item = self.mock_work_item tool.user.prompt = lambda message: "yes" queue.execute(options, args, tool, engine=MockQueueEngine) self.assert_outputs(queue.queue_log_path, "queue_log_path", [], expected_stdout, expected_stderr, expected_exceptions, expected_logs) self.assert_outputs(queue.work_item_log_path, "work_item_log_path", [work_item], expected_stdout, expected_stderr, expected_exceptions, expected_logs) self.assert_outputs(queue.begin_work_queue, "begin_work_queue", [], expected_stdout, expected_stderr, expected_exceptions, expected_logs) self.assert_outputs(queue.should_continue_work_queue, "should_continue_work_queue", [], expected_stdout, expected_stderr, expected_exceptions, expected_logs) self.assert_outputs(queue.next_work_item, "next_work_item", [], expected_stdout, expected_stderr, expected_exceptions, expected_logs) self.assert_outputs(queue.process_work_item, "process_work_item", [work_item], expected_stdout, expected_stderr, expected_exceptions, expected_logs) self.assert_outputs(queue.handle_unexpected_error, "handle_unexpected_error", [work_item, "Mock error message"], expected_stdout, expected_stderr, expected_exceptions, expected_logs) # Should we have a different function for testing StepSequenceErrorHandlers? if isinstance(queue, StepSequenceErrorHandler): 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_stdout, expected_stderr, expected_exceptions, expected_logs)
def _throwing_run_command(args): raise ScriptError("MOCK script error")
def test_message_with_tuple(self): error = ScriptError('', ('my', 'command'), -1, 'My output.', '/Users/username/blah') self.assertEqual(error.message_with_output(), 'Failed to run "(\'my\', \'command\')" exit_code: -1 cwd: /Users/username/blah\n\nMy output.')
def _remote_branch_ref(self): # Use references so that we can avoid collisions, e.g. we don't want to operate on refs/heads/trunk if it exists. remote_master_ref = 'refs/remotes/origin/master' if not self._branch_ref_exists(remote_master_ref): raise ScriptError(message="Can't find a branch to diff against. %s does not exist" % remote_master_ref) return remote_master_ref
def test_message_with_tuple(self): error = ScriptError('', ('my', 'command'), -1, 'My output.', '/Users/username/blah') self.assertEqual(error.message_with_output(), 'Failed to run "(\'my\', \'command\')" exit_code: -1 cwd: /Users/username/blah\n\noutput: My output.')
def test_string_from_args(self): error = ScriptError() self.assertEquals(error._string_from_args(None), 'None') self.assertEquals(error._string_from_args([]), '[]') self.assertEquals(error._string_from_args(map(str, range(30))), "['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17'...")
def should_squash(squash): raise ScriptError(message="Dummy error")
def run_command(_): raise ScriptError( 'Unable to infer commit position from footers rutabaga')
def process_work_item(self, work_item): self.record("process_work_item") raise ScriptError(exit_code=self.error_code)
def test_log(self): self.assert_log_equals("test", "test\n") # Test that log() does not throw an exception when passed an object instead of a string. self.assert_log_equals(ScriptError(message="ScriptError"), "ScriptError\n")
def test_message_with_output(self): error = ScriptError('My custom message!', '', -1) self.assertEqual(error.message_with_output(), 'My custom message!') error = ScriptError('My custom message!', '', -1, 'My output.') self.assertEqual(error.message_with_output(), 'My custom message!\n\noutput: My output.') error = ScriptError('', 'my_command!', -1, 'My output.', '/Users/username/blah') self.assertEqual( error.message_with_output(), 'Failed to run "\'my_command!\'" exit_code: -1 cwd: /Users/username/blah\n\noutput: My output.' ) error = ScriptError('', 'my_command!', -1, 'ab' + '1' * 499) self.assertEqual( error.message_with_output(), 'Failed to run "\'my_command!\'" exit_code: -1\n\noutput: Last 500 characters of output:\nb' + '1' * 499)
def mock_run_command(cmd): raise ScriptError('Failure')