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_parse_command_and_args(self): tool = MockTool() bot = IRCBot("sheriffbot", tool, Sheriff(tool, MockSheriffBot()), irc_command.commands) self.assertEqual(bot._parse_command_and_args(""), (Eliza, [""])) self.assertEqual(bot._parse_command_and_args(" "), (Eliza, [""])) self.assertEqual(bot._parse_command_and_args(" hi "), (irc_command.Hi, [])) self.assertEqual(bot._parse_command_and_args(" hi there "), (irc_command.Hi, ["there"]))
def begin_work_queue(self): self._sheriff = Sheriff(self._tool, self) self._irc_bot = IRCBot(self.name, self._tool, self._sheriff, irc_commands) self._tool.ensure_irc_connected(self._irc_bot.irc_delegate())
def begin_work_queue(self): AbstractQueue.begin_work_queue(self) self._last_svn_revision = int(self._tool.scm().head_svn_revision()) self._irc_bot = IRCBot('WKR', self._tool, None, self._commands) self._tool.ensure_irc_connected(self._irc_bot.irc_delegate())
def begin_work_queue(self): AbstractQueue.begin_work_queue(self) self._sheriff = Sheriff(self._tool, self) self._irc_bot = IRCBot("perfalizer", self._tool, self._sheriff, self._commands) self._tool.ensure_irc_connected(self._irc_bot.irc_delegate())
def begin_work_queue(self): self._last_svn_revision = int(self._tool.scm().head_svn_revision()) self._irc_bot = IRCBot(self.name, self._tool, Agent(self._tool, self), self._commands) self._tool.ensure_irc_connected(self._irc_bot.irc_delegate())