Commits

Anonymous committed 4c9cc18

more tests

Comments (0)

Files changed (2)

irc_reader/irc_parser.py

 class IRCMessage(object):
     def __init__(self, msg):
         msg = msg.split()
-        self.date = parser.parse(msg[0])
-        self.nick = msg[1]
-        if self.nick.startswith("<") and self.nick.endswith(">"):
-            self.nick = self.nick[1:-1]
+        if msg:
+            self.date = parser.parse(msg[0])
+            self.nick = msg[1]
+            if self.nick.startswith("<") and self.nick.endswith(">"):
+                self.nick = self.nick[1:-1]
+            else:
+                self.nick = ''
+
+            self.msg = " ".join(msg[2:])
         else:
-            self.nick = ''
-
-        self.msg = " ".join(msg[2:])
+            self.date = self.nick = self.msg = None
 
     def __str__(self):
         return "Date:%s Nick:%s Msg: %s" % (self.date,
+import os
+
 import test_settings
 
 from datetime import datetime
 
 from irc_reader import create_app
 from irc_reader.models import db, Channel, Message
+from irc_reader.irc_parser import parse_irc
 
 class _TestCase(TestCase):
     
     
         db.session.commit()
 
+class TestParseIRC(TestCase):
+
+    def create_app(self):
+        return create_app(test_settings)
+
+
+    def test_parse_irc_logs(self):
+
+        fp = open(os.path.join(self.app.config['IRC_LOGS_DIR'], 'irctest.log'))
+        messages = list(parse_irc(fp))
+        
+        print len(messages), messages[0]
+
+        assert len(messages) == 412
+        
+        assert messages[0].date.year == 2010
+        assert messages[0].date.month == 7
+        assert messages[0].nick == "mitsuhiko"
+        assert messages[0].msg == "the popular a project the bad the bug reports"
+
+        assert messages[4].nick == ''
+
 class TestModels(_TestCase):
 
     def test_search_messages(self):