Exemplo n.º 1
0
 def test_static_read_no_size(self):
     pb = rz.PartialBuffer(io.BytesIO(b'aaaabbcccdd'), 10, 11, stream=False)
     self.assertEqual(pb.read(), b'aaaabbcccdd')
     self.assertEqual(pb.position, 21)
     self.assertEqual(pb.seek(15, 0), 15)
     self.assertEqual(pb.read(), b'bcccdd')
     self.assertEqual(pb.seek(-5, 2), 16)
     self.assertEqual(pb.read(), b'cccdd')
     self.assertEqual(pb.read(), b'')
Exemplo n.º 2
0
 def test_static_seek(self):
     pb = rz.PartialBuffer(io.BytesIO(b'aaaabbcccdd'), 10, 11, stream=False)
     self.assertEqual(pb.seek(10, 0), 10)
     self.assertEqual(pb.read(5), b'aaaab')
     self.assertEqual(pb.seek(12, 0), 12)
     self.assertEqual(pb.read(5), b'aabbc')
     self.assertEqual(pb.seek(20, 0), 20)
     self.assertEqual(pb.read(1), b'd')
     self.assertEqual(pb.seek(10, 0), 10)
     self.assertEqual(pb.seek(2, 1), 12)
Exemplo n.º 3
0
    def test_stream_forward_seek(self):
        pb = rz.PartialBuffer(io.BytesIO(b'aaaabbcccdd'), 10, 11, stream=True)
        self.assertEqual(pb.seek(12, 0), 12)
        self.assertEqual(pb.read(3), b'aab')
        self.assertEqual(pb.seek(2, 1), 17)
        self.assertEqual(pb.read(), b'ccdd')

        with self.assertRaisesRegexp(rz.OutOfBound,
                                     "Negative seek not supported"):
            pb.seek(12, 0)
        self.assertEqual(pb.position, 12)
Exemplo n.º 4
0
 def verify(self, stream):
     pb = rz.PartialBuffer(io.BytesIO(b'aaaabbcccdd'),
                           10,
                           11,
                           stream=stream)
     self.assertEqual(pb.position, 10)
     self.assertEqual(pb.size, 11)
     self.assertEqual(pb.read(5), b'aaaab')
     self.assertEqual(pb.read(3), b'bcc')
     self.assertEqual(pb.read(3), b'cdd')
     pb.close()
Exemplo n.º 5
0
    def fetch_fun(self, data_range, stream=False):
        # simulate 200k file
        fsize = 200 * 1024
        min_range, max_range = data_range
        if min_range < 0:
            size = -min_range
            min_range = fsize - size
        else:
            size = max_range - min_range + 1

        if stream:
            data = b's' * size
        else:
            data = b'x' * size
        return rz.PartialBuffer(io.BytesIO(data),
                                min_range,
                                size,
                                stream=stream)
Exemplo n.º 6
0
 def test_static_oob(self):
     pb = rz.PartialBuffer(io.BytesIO(b'aaaabbcccdd'), 10, 11, stream=False)
     with self.assertRaises(rz.OutOfBound):
         pb.seek(21, 0)