Skip to content

Commit

Permalink
Merge pull request #3 from zertrin/master
Browse files Browse the repository at this point in the history
Modification of the parsing regular expressions to handle both hh:mm:ss and hh:mm timestamp format in IRC log files
  • Loading branch information
madjar committed Nov 14, 2012
2 parents 6237f0b + 53e8bd2 commit 1e6c424
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 33 deletions.
77 changes: 47 additions & 30 deletions rezoirclogs/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,46 +23,61 @@ def _get_FUT(self, *args, **kwargs):
return LogLine(*args, **kwargs)

def test_normal(self):
line = "02:16 <ciblout> 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 <ciblout> je suis secretaire, c'est moi qui decide", "normal", "je suis secretaire, c'est moi qui decide", 'ciblout', '02:16'),
("02:16:45 <ciblout> 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 <ciblout>")
self.assertEqual(m.type, "normal")
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, "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 [[email protected]] has quit [Quit: Bon debaras.]"
m = self._get_FUT(line)
self.assertEqual(m.type, "status")
self.assertEqual(m.message, "[[email protected]] 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 [[email protected]] has quit [Quit: Bon debaras.]", "status", "[[email protected]] has quit [Quit: Bon debaras.]", 'ciblout', '01:56'),
("01:56:09 -!- ciblout [[email protected]] has quit [Quit: Bon debaras.]", "status", "[[email protected]] 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")
Expand All @@ -73,6 +88,8 @@ def test_exotic_nicknames(self):
lines = [("20:26 <K-Yo> 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:
Expand Down
6 changes: 3 additions & 3 deletions rezoirclogs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 1e6c424

Please sign in to comment.