Esempio n. 1
0
    def test_parse_invalid_message(self):
        """Test whether it raises an exception when an invalid line is found"""

        with self.assertRaisesRegex(ParseError, "invalid message on line 9"):
            with open("data/supybot_invalid_msg.log", 'r') as f:
                parser = SupybotParser(f)
                _ = [item for item in parser.parse()]
Esempio n. 2
0
    def test_parse_invalid_date(self):
        """Test whether it raises an exception when a date is invalid"""

        with self.assertRaisesRegex(ParseError, "date expected on line 4"):
            with open("data/supybot_invalid_date.log", 'r') as f:
                parser = SupybotParser(f)
                _ = [item for item in parser.parse()]
    def test_parse_invalid_date(self):
        """Test whether it raises an exception when a date is invalid"""

        with self.assertRaisesRegex(ParseError, "date expected on line 4"):
            with open(os.path.join(os.path.dirname(os.path.abspath(__file__)),
                                   "data/supybot/supybot_invalid_date.log"), 'r') as f:
                parser = SupybotParser(f)
                _ = [item for item in parser.parse()]
    def test_parser(self):
        """Test whether it parses a valid Supybot IRC log stream"""

        with open(
                os.path.join(os.path.dirname(os.path.abspath(__file__)),
                             "data/supybot/supybot_valid.log"), 'r') as f:
            parser = SupybotParser(f)
            items = [item for item in parser.parse()]

        self.assertEqual(len(items), 97)

        item = items[1]
        self.assertEqual(item['timestamp'], '2012-10-17T09:16:29+0000')
        self.assertEqual(item['type'], SupybotParser.TCOMMENT)
        self.assertEqual(item['nick'], 'benpol')
        self.assertEqual(item['body'], "they're related to fragmentation?")

        item = items[2]
        self.assertEqual(item['timestamp'], '2012-10-17T09:16:35+0000')
        self.assertEqual(item['type'], SupybotParser.TCOMMENT)
        self.assertEqual(item['nick'], 'benpol')
        self.assertEqual(item['body'], "benpol is wondering...")

        item = items[3]
        self.assertEqual(item['timestamp'], '2012-10-17T09:16:50+0000')
        self.assertEqual(item['type'], SupybotParser.TSERVER)
        self.assertEqual(item['nick'], 'MikeMcClurg')
        self.assertEqual(item['body'], "MikeMcClurg has quit IRC")

        item = items[-2]
        self.assertEqual(item['timestamp'], '2012-10-17T23:42:10+0000')
        self.assertEqual(item['type'], SupybotParser.TCOMMENT)
        self.assertEqual(item['nick'], 'supy-bot')
        self.assertEqual(item['body'],
                         "[backend] Fix bug #23: invalid timestamp")

        item = items[-1]
        self.assertEqual(item['timestamp'], '2012-10-17T23:42:26+0000')
        self.assertEqual(item['type'], SupybotParser.TCOMMENT)
        self.assertEqual(item['nick'], 'gregaf')
        self.assertEqual(
            item['body'],
            "but I may be wrong or debugging at the wrong level...")

        # Count the number of messages parsed by type
        ncomments = 0
        nserver = 0

        for item in items:
            if item['type'] == SupybotParser.TCOMMENT:
                ncomments += 1
            else:
                nserver += 1

        self.assertEqual(ncomments, 51)
        self.assertEqual(nserver, 46)