def test_exception_during_command(self): tool = MockTool() tool.ensure_irc_connected(None) bot = IRCBot("sheriffbot", tool, Sheriff(tool, MockSheriffBot()), irc_command.commands) class CommandWithException(object): def execute(self, nick, args, tool, sheriff): raise Exception("mock_exception") bot._parse_command_and_args = lambda request: (CommandWithException, [ ]) expected_logs = 'MOCK: irc.post: Exception executing command: mock_exception\n' OutputCapture().assert_outputs(self, bot.process_message, args=["mock_nick", "ignored message"], expected_logs=expected_logs) class CommandWithException(object): def execute(self, nick, args, tool, sheriff): raise KeyboardInterrupt() bot._parse_command_and_args = lambda request: (CommandWithException, [ ]) # KeyboardInterrupt and SystemExit are not subclasses of Exception and thus correctly will not be caught. OutputCapture().assert_outputs(self, bot.process_message, args=["mock_nick", "ignored message"], expected_exception=KeyboardInterrupt)
def run(message): tool = MockTool() tool.ensure_irc_connected(None) bot = IRCBot("sheriffbot", tool, Sheriff(tool, MockSheriffBot()), irc_command.commands) bot._message_queue.post(["mock_nick", message]) bot.process_pending_messages()
def test_exception_during_command(self): tool = MockTool() tool.ensure_irc_connected(None) bot = IRCBot("sheriffbot", tool, Sheriff(tool, MockSheriffBot()), irc_command.commands) class CommandWithException(object): def execute(self, nick, args, tool, sheriff): raise Exception("mock_exception") bot._parse_command_and_args = lambda request: (CommandWithException, []) expected_logs = 'MOCK: irc.post: Exception executing command: mock_exception\n' OutputCapture().assert_outputs(self, bot.process_message, args=["mock_nick", "ignored message"], expected_logs=expected_logs) class CommandWithException(object): def execute(self, nick, args, tool, sheriff): raise KeyboardInterrupt() bot._parse_command_and_args = lambda request: (CommandWithException, []) # KeyboardInterrupt and SystemExit are not subclasses of Exception and thus correctly will not be caught. OutputCapture().assert_outputs(self, bot.process_message, args=["mock_nick", "ignored message"], expected_exception=KeyboardInterrupt)