예제 #1
0
 def test_seek_and_end_read(self):
     f = seek_open(self.datafile, 8, 14)
     self.failUnlessEqual(f.next(), 'ab\n')
     self.failUnlessEqual(f.next(), '3456789\n')
     self.failUnlessRaises(StopIteration, lambda: f.next())
     
     f = seek_open(self.datafile, 9, 14)
     self.failUnlessEqual(f.next(), '3456789\n')
     self.failUnlessRaises(StopIteration, lambda: f.next())
예제 #2
0
 def test_simple_read(self):
     f = seek_open(self.datafile)
     self.failUnlessEqual(f.next(), '12345678\n')
     self.failUnlessEqual(f.next(), 'ab\n')
     self.failUnlessEqual(f.next(), '3456789\n')
     self.failUnlessEqual(f.next(), 'cdef\n')
     self.failUnlessEqual(f.next(), '87654\n')
     self.failUnlessEqual(f.next(), 'pqrstuvw\n')
     self.failUnlessRaises(StopIteration, lambda: f.next())
예제 #3
0
 def test_end_read(self):
     f = seek_open(self.datafile, end=2)
     self.failUnlessEqual(f.next(), '12345678\n')
     self.failUnlessRaises(StopIteration, lambda: f.next())
     
     f = seek_open(self.datafile, end=8)
     self.failUnlessEqual(f.next(), '12345678\n')
     self.failUnlessRaises(StopIteration, lambda: f.next())
     
     f = seek_open(self.datafile, end=9)
     self.failUnlessEqual(f.next(), '12345678\n')
     self.failUnlessEqual(f.next(), 'ab\n')
     self.failUnlessRaises(StopIteration, lambda: f.next())
     
     f = seek_open(self.datafile, end=9)
     data = ''
     for line in f:
         data += line
     self.failUnlessEqual(data, '12345678\nab\n')
예제 #4
0
 def read_seek():
     for (start, end) in file_offsets(os.path.getsize(file_name), n_pieces):
         # print "reading piece: %d -> %d" % (start, end)
         for line in seek_open(file_name, start, end):
             yield line
예제 #5
0
 def test_seek_read(self):
     f = seek_open(self.datafile, 10)
     self.failUnlessEqual(f.next(), '3456789\n')