Commits

Mark Roddy committed f6b635c

Reorder the appearance of the PidginLogRecord and PidginLog classes so that classes appear in the order in which they consume eachother. Did the same with the test cases.

Comments (0)

Files changed (2)

larvotto/convsrc.py

 recordre=re.compile(r'^\((\d\d?\:\d\d\:\d\d(\s+[A|P]M)?)\)\s+(.*?)\:\s+(.*)\s*$', re.I|re.L)
 
 
+
+class PidginLogRecord(object):
+    """Container for a single entry/line in a pidgin log file"""
+    
+    _Msg=None
+    _SenderScrName=None
+    _MsgTime=None
+
+    def __init__(self,Message, SenderScrName, MsgTime):
+        self._Msg=Message
+        self._SenderScrName=SenderScrName
+        self._MsgTime=MsgTime
+
+    msg=property(lambda self: self._Msg)
+    sender=property(lambda self: self._SenderScrName)
+    msg_time=property(lambda self: self._MsgTime)
+
+    @classmethod
+    def fromRawRecord(cls,RawRecord,DayOfYearStr):
+        m=recordre.search(RawRecord.strip())
+        if not m:
+            raise Exception(RawRecord)
+        tod,isampm,scrnname,msg=m.groups()
+        if isampm:
+            dtime=datetime.strptime('%s %s'%(DayOfYearStr,tod), '%Y-%m-%d %I:%M:%S %p')	
+        else:
+            dtime=datetime.strptime('%s %s'%(DayOfYearStr,tod), '%Y-%m-%d %H:%M:%S')
+        return cls(msg,scrnname,dtime)
+
+
 class PidginLog(object):
     _Open=open
 
         self._LogRecords=LogRecords
         self._LogDate=LogDate
 
+    def __iter__(self):
+        return self.log_records
+
     @classmethod
     def fromPath(cls,PathToLog):
         """Create a PidginLog object from the path to a log file"""
         fname=os.path.basename(dir_path)
         return fname
 
-class PidginLogRecord(object):
-    """Container for a single entry/line in a pidgin log file"""
-    
-    _Msg=None
-    _SenderScrName=None
-    _MsgTime=None
-
-    def __init__(self,Message, SenderScrName, MsgTime):
-        self._Msg=Message
-        self._SenderScrName=SenderScrName
-        self._MsgTime=MsgTime
-
-    msg=property(lambda self: self._Msg)
-    sender=property(lambda self: self._SenderScrName)
-    msg_time=property(lambda self: self._MsgTime)
-
-    @classmethod
-    def fromRawRecord(cls,RawRecord,DayOfYearStr):
-        m=recordre.search(RawRecord.strip())
-        if not m:
-            raise Exception(RawRecord)
-        tod,isampm,scrnname,msg=m.groups()
-        if isampm:
-            dtime=datetime.strptime('%s %s'%(DayOfYearStr,tod), '%Y-%m-%d %I:%M:%S %p')	
-        else:
-            dtime=datetime.strptime('%s %s'%(DayOfYearStr,tod), '%Y-%m-%d %H:%M:%S')
-        return cls(msg,scrnname,dtime)
-
     
         
 class PidginLogParser(object):

larvotto/tests/test_convsrc.py

 
 from StringIO import StringIO
 
+
+class TestPidginLogRecord(unittest.TestCase):
+    """Test case for the larvotto.convsrc.PidginLogRecord class"""
+
+    def testFromRawRecord_ValidRecord_ObjectCreated(self):
+        """PidginLogRecord object created via fromRawRecord()"""
+        valid_entry="(10:08:26 PM) sendername: okay"
+        result=convsrc.PidginLogRecord.fromRawRecord(valid_entry,'2008-10-23')
+        self.assertTrue(isinstance(result,convsrc.PidginLogRecord))
+
+    def testFromRawRecord_ValidRecord_ExpectedAttrValues(self):
+        """Attributes receive expected values from fromRawRecord()"""
+        valid_entry="(10:08:26 PM) sendername: okay"
+        result=convsrc.PidginLogRecord.fromRawRecord(valid_entry,'2008-10-23')
+        self.assertEquals('okay',result.msg)
+        self.assertEquals('sendername',result.sender)
+        #msg_time=property(lambda self: self._MsgTime)
+
+
 class TestPidginLog(unittest.TestCase):
     """Test case for the larvotto.convsrc.PidginLog class"""
 
         log_records=list(log_obj.log_records)
         self.assertEquals(2,len(log_records))
 
-class TestPidginLogRecord(unittest.TestCase):
-    """Test case for the larvotto.convsrc.PidginLogRecord class"""
-
-    def testFromRawRecord_ValidRecord_ObjectCreated(self):
-        """PidginLogRecord object created via fromRawRecord()"""
-        valid_entry="(10:08:26 PM) sendername: okay"
-        result=convsrc.PidginLogRecord.fromRawRecord(valid_entry,'2008-10-23')
-        self.assertTrue(isinstance(result,convsrc.PidginLogRecord))
-
-    def testFromRawRecord_ValidRecord_ExpectedAttrValues(self):
-        """Attributes receive expected values from fromRawRecord()"""
-        valid_entry="(10:08:26 PM) sendername: okay"
-        result=convsrc.PidginLogRecord.fromRawRecord(valid_entry,'2008-10-23')
-        self.assertEquals('okay',result.msg)
-        self.assertEquals('sendername',result.sender)
-        #msg_time=property(lambda self: self._MsgTime)
-
 class TestPidginLogs(unittest.TestCase):
 	"""Test case for the L{larvotto.convsrc.PidginLogs} function"""