Ejemplo n.º 1
0
 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"]))
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
 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"]))
Ejemplo n.º 4
0
    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)