Beispiel #1
0
 def test_reset_stream_emulation(self):
     filename = os.path.join(self.tempdir, 'foo')
     f = open(filename, 'wb')
     f.write(b'onetwothreefourfivesixseveneightnineten')
     f.flush()
     chunk = ReadFileChunk(filename, start_byte=11, size=4)
     self.assertEqual(chunk.read(), b'four')
     chunk.seek(0)
     self.assertEqual(chunk.read(), b'four')
Beispiel #2
0
 def test_reset_stream_emulation(self):
     filename = os.path.join(self.tempdir, 'foo')
     f = open(filename, 'wb')
     f.write(b'onetwothreefourfivesixseveneightnineten')
     f.flush()
     chunk = ReadFileChunk(filename, start_byte=11, size=4)
     self.assertEqual(chunk.read(), b'four')
     chunk.seek(0)
     self.assertEqual(chunk.read(), b'four')
Beispiel #3
0
 def test_read_with_amount_size(self):
     filename = os.path.join(self.tempdir, 'foo')
     f = open(filename, 'wb')
     f.write(b'onetwothreefourfivesixseveneightnineten')
     f.flush()
     chunk = ReadFileChunk(filename, start_byte=11, size=4)
     self.assertEqual(chunk.read(1), b'f')
     self.assertEqual(chunk.read(1), b'o')
     self.assertEqual(chunk.read(1), b'u')
     self.assertEqual(chunk.read(1), b'r')
     self.assertEqual(chunk.read(1), b'')
Beispiel #4
0
 def test_read_with_amount_size(self):
     filename = os.path.join(self.tempdir, 'foo')
     f = open(filename, 'wb')
     f.write(b'onetwothreefourfivesixseveneightnineten')
     f.flush()
     chunk = ReadFileChunk(filename, start_byte=11, size=4)
     self.assertEqual(chunk.read(1), b'f')
     self.assertEqual(chunk.read(1), b'o')
     self.assertEqual(chunk.read(1), b'u')
     self.assertEqual(chunk.read(1), b'r')
     self.assertEqual(chunk.read(1), b'')
Beispiel #5
0
 def test_read_with_amount_size(self):
     filename = os.path.join(self.tempdir, "foo")
     f = open(filename, "wb")
     f.write(b"onetwothreefourfivesixseveneightnineten")
     f.flush()
     chunk = ReadFileChunk(filename, start_byte=11, size=4)
     self.assertEqual(chunk.read(1), b"f")
     self.assertEqual(chunk.read(1), b"o")
     self.assertEqual(chunk.read(1), b"u")
     self.assertEqual(chunk.read(1), b"r")
     self.assertEqual(chunk.read(1), b"")
Beispiel #6
0
 def test_read_entire_chunk(self):
     filename = os.path.join(self.tempdir, 'foo')
     f = open(filename, 'wb')
     f.write(b'onetwothreefourfivesixseveneightnineten')
     f.flush()
     chunk = ReadFileChunk(filename, start_byte=0, size=3)
     self.assertEqual(chunk.read(), b'one')
     self.assertEqual(chunk.read(), b'')
Beispiel #7
0
 def test_read_entire_chunk(self):
     filename = os.path.join(self.tempdir, 'foo')
     f = open(filename, 'wb')
     f.write(b'onetwothreefourfivesixseveneightnineten')
     f.flush()
     chunk = ReadFileChunk(filename, start_byte=0, size=3)
     self.assertEqual(chunk.read(), b'one')
     self.assertEqual(chunk.read(), b'')
Beispiel #8
0
 def test_read_past_end_of_file(self):
     filename = os.path.join(self.tempdir, 'foo')
     f = open(filename, 'wb')
     f.write(b'onetwothreefourfivesixseveneightnineten')
     f.flush()
     chunk = ReadFileChunk(filename, start_byte=36, size=100000)
     self.assertEqual(chunk.read(), b'ten')
     self.assertEqual(chunk.read(), b'')
     self.assertEqual(len(chunk), 3)
Beispiel #9
0
 def test_read_past_end_of_file(self):
     filename = os.path.join(self.tempdir, 'foo')
     f = open(filename, 'wb')
     f.write(b'onetwothreefourfivesixseveneightnineten')
     f.flush()
     chunk = ReadFileChunk(filename, start_byte=36, size=100000)
     self.assertEqual(chunk.read(), b'ten')
     self.assertEqual(chunk.read(), b'')
     self.assertEqual(len(chunk), 3)
Beispiel #10
0
 def test_tell_and_seek(self):
     filename = os.path.join(self.tempdir, "foo")
     f = open(filename, "wb")
     f.write(b"onetwothreefourfivesixseveneightnineten")
     f.flush()
     chunk = ReadFileChunk(filename, start_byte=36, size=100000)
     self.assertEqual(chunk.tell(), 0)
     self.assertEqual(chunk.read(), b"ten")
     self.assertEqual(chunk.tell(), 3)
     chunk.seek(0)
     self.assertEqual(chunk.tell(), 0)