示例#1
0
 def test_position(self):
     lf = LogFile(self.fname)
     expected_pos = 0
     for data in lf:
         expected_pos += len(self.make_line(data))
         real_pos = lf.position()
         print expected_pos, real_pos
         assert real_pos == expected_pos
示例#2
0
 def test_add(self):
     fname_log = tempfile.mktemp()
     lf = LogFile(fname_log)
     for linedata in self.LOG:
         lf.add(*linedata)
     expected_contents = open(self.fname, 'rb').read()
     real_contents = open(fname_log, 'rb').read()
     print repr(expected_contents)
     print repr(real_contents)
     assert real_contents == expected_contents
示例#3
0
 def test_seek(self):
     lf = LogFile(self.fname)
     for data in lf:
         print repr(data)
     # now we are at the current end, remember position
     pos = lf.position()
     # add new data
     newdata = [
         u'1303333333000000', u'00000003', u'SAVE', u'foo', u'0.0.0.0',
         u'example.org', u'666.666.666', u'', u'comment'
     ]
     lf.add(*newdata)
     # go to position before new data
     lf.seek(pos)
     assert lf.position() == pos
     for data in lf:
         # reads the one new line we added
         print 'new:', repr(data)
         assert data == newdata
     lf.seek(0)
     assert lf.position() == 0
     assert list(lf) == self.LOG + [newdata]
示例#4
0
 def test_iter_reverse(self):
     lf = LogFile(self.fname)
     for result, expected in zip(lf.reverse(), self.LOG[::-1]):
         print expected
         print result
         assert result == expected
示例#5
0
 def test_iter_forward(self):
     lf = LogFile(self.fname)
     for result, expected in zip(lf, self.LOG):
         print expected
         print result
         assert result == expected