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
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]
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]