From 7c82c8b72860a44de50d02e9f8a0689e6b62adfe Mon Sep 17 00:00:00 2001 From: Zertrin Date: Tue, 13 Nov 2012 22:21:57 +0100 Subject: [PATCH 1/2] Modification of the parsing regular expressions to handle both hh:mm:ss and hh:mm timestamp format in IRC log files --- rezoirclogs/utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rezoirclogs/utils.py b/rezoirclogs/utils.py index 10cd295..461af85 100644 --- a/rezoirclogs/utils.py +++ b/rezoirclogs/utils.py @@ -39,9 +39,9 @@ def __new__(cls, value): _regex = [ - (re.compile(r"(\d\d:\d\d) <%s> ?(.*)" % _nick_regex), 'normal'), - (re.compile(r"(\d\d:\d\d) *\* %s ?(.*)" % _nick_regex), 'me'), - (re.compile(r"(\d\d:\d\d) -!- %s ?(.*)" % _nick_regex), 'status'), + (re.compile(r"(\d\d:\d\d(?::\d\d)??) <%s> ?(.*)" % _nick_regex), 'normal'), + (re.compile(r"(\d\d:\d\d(?::\d\d)??) *\* %s ?(.*)" % _nick_regex), 'me'), + (re.compile(r"(\d\d:\d\d(?::\d\d)??) -!- %s ?(.*)" % _nick_regex), 'status'), ] def populate(self): From 53e8bd202aae3663cb767088dd5bb860f733846d Mon Sep 17 00:00:00 2001 From: Zertrin Date: Wed, 14 Nov 2012 11:32:00 +0100 Subject: [PATCH 2/2] Adding tests with the hh:mm:ss timestamp format --- rezoirclogs/tests/test_utils.py | 77 ++++++++++++++++++++------------- 1 file changed, 47 insertions(+), 30 deletions(-) diff --git a/rezoirclogs/tests/test_utils.py b/rezoirclogs/tests/test_utils.py index 0c09563..8b395dc 100644 --- a/rezoirclogs/tests/test_utils.py +++ b/rezoirclogs/tests/test_utils.py @@ -23,46 +23,61 @@ def _get_FUT(self, *args, **kwargs): return LogLine(*args, **kwargs) def test_normal(self): - line = "02:16 je suis secretaire, c'est moi qui decide" - m = self._get_FUT(line) - self.assertEqual(m.type, "normal") - self.assertEqual(m.message, "je suis secretaire, c'est moi qui decide") - self.assertEqual(m.user, 'ciblout') - self.assertEqual(m.time, '02:16') - self.assertEqual(str(m), line) + lines = [("02:16 je suis secretaire, c'est moi qui decide", "normal", "je suis secretaire, c'est moi qui decide", 'ciblout', '02:16'), + ("02:16:45 je suis secretaire, c'est moi qui decide", "normal", "je suis secretaire, c'est moi qui decide", 'ciblout', '02:16:45')] + for line, expected_type, expected_message, expected_nick, expected_time in lines: + m = self._get_FUT(line) + self.assertEqual(m.type, expected_type) + self.assertEqual(m.message, expected_message) + self.assertEqual(m.user, expected_nick) + self.assertEqual(m.time, expected_time) + self.assertEqual(str(m), line) def test_normal_empty(self): - m = self._get_FUT("02:16 ") - self.assertEqual(m.type, "normal") - self.assertEqual(m.message, "") + lines = ["02:16 ", + "02:16:45 "] + for line in lines: + m = self._get_FUT(line) + self.assertEqual(m.type, "normal") + self.assertEqual(m.message, "") def test_me(self): - line = "02:16 * ciblout dit encore des conneries" - m = self._get_FUT(line) - self.assertEqual(m.type, "me") - self.assertEqual(m.message, "dit encore des conneries") - self.assertEqual(m.user, 'ciblout') - self.assertEqual(m.time, '02:16') - self.assertEqual(str(m), line) + lines = [("02:16 * ciblout dit encore des conneries", "me", "dit encore des conneries", 'ciblout', '02:16'), + ("02:16:45 * ciblout dit encore des conneries", "me", "dit encore des conneries", 'ciblout', '02:16:45')] + for line, expected_type, expected_message, expected_nick, expected_time in lines: + m = self._get_FUT(line) + self.assertEqual(m.type, expected_type) + self.assertEqual(m.message, expected_message) + self.assertEqual(m.user, expected_nick) + self.assertEqual(m.time, expected_time) + self.assertEqual(str(m), line) def test_me_empty(self): - m = self._get_FUT("02:16 * ciblout") - self.assertEqual(m.type, "me") - self.assertEqual(m.message, "") + lines = ["02:16 * ciblout", + "02:16:45 * ciblout"] + for line in lines: + m = self._get_FUT(line) + self.assertEqual(m.type, "me") + self.assertEqual(m.message, "") def test_status(self): - line = "01:56 -!- ciblout [cyprien@mauvaise.foi] has quit [Quit: Bon debaras.]" - m = self._get_FUT(line) - self.assertEqual(m.type, "status") - self.assertEqual(m.message, "[cyprien@mauvaise.foi] has quit [Quit: Bon debaras.]") - self.assertEqual(m.user, 'ciblout') - self.assertEqual(m.time, '01:56') - self.assertEqual(str(m), line) + lines = [("01:56 -!- ciblout [cyprien@mauvaise.foi] has quit [Quit: Bon debaras.]", "status", "[cyprien@mauvaise.foi] has quit [Quit: Bon debaras.]", 'ciblout', '01:56'), + ("01:56:09 -!- ciblout [cyprien@mauvaise.foi] has quit [Quit: Bon debaras.]", "status", "[cyprien@mauvaise.foi] has quit [Quit: Bon debaras.]", 'ciblout', '01:56:09')] + for line, expected_type, expected_message, expected_nick, expected_time in lines: + m = self._get_FUT(line) + self.assertEqual(m.type, expected_type) + self.assertEqual(m.message, expected_message) + self.assertEqual(m.user, expected_nick) + self.assertEqual(m.time, expected_time) + self.assertEqual(str(m), line) def test_status_empty(self): - m = self._get_FUT("01:56 -!- ciblout ") - self.assertEqual(m.type, "status") - self.assertEqual(m.message, "") + lines = ["02:16 -!- ciblout", + "02:16:45 -!- ciblout"] + for line in lines: + m = self._get_FUT(line) + self.assertEqual(m.type, "status") + self.assertEqual(m.message, "") def test_unrecognized(self): m = self._get_FUT("Ceci n'est pas une ligne de log") @@ -73,6 +88,8 @@ def test_exotic_nicknames(self): lines = [("20:26 madjar, \o/", "K-Yo"), ("22:14 <+K-Yo> putain, j'ai la même!", "K-Yo"), ("22:14 <@DaLynX> merci remram", "DaLynX"), + ("04:54 <@Zertr1> derns!", "Zertr1"), + ("04:54:00 <@Zertr1> derns!", "Zertr1"), ("01:59 < kage> c'est moche les GUI en java", "kage")] for line, nick in lines: