Пример #1
0
 def test_read_default_value(self):
     BYTES = 1024
     data_str = "*" * BYTES
     data = six.StringIO(data_str)
     reader = sizelimit.LimitingReader(data, BYTES)
     res = reader.read()
     self.assertEqual(data_str, res)
Пример #2
0
 def _consume_all_read():
     bytes_read = 0
     data = six.StringIO("*" * BYTES)
     reader = sizelimit.LimitingReader(data, BYTES - 1)
     byte = reader.read(1)
     while len(byte) != 0:
         bytes_read += 1
         byte = reader.read(1)
Пример #3
0
    def test_limiting_reader(self):
        BYTES = 1024
        bytes_read = 0
        data = six.StringIO("*" * BYTES)
        for chunk in sizelimit.LimitingReader(data, BYTES):
            bytes_read += len(chunk)

        self.assertEqual(bytes_read, BYTES)

        bytes_read = 0
        data = six.StringIO("*" * BYTES)
        reader = sizelimit.LimitingReader(data, BYTES)
        byte = reader.read(1)
        while len(byte) != 0:
            bytes_read += 1
            byte = reader.read(1)

        self.assertEqual(bytes_read, BYTES)
Пример #4
0
 def _consume_all_iter():
     bytes_read = 0
     data = six.StringIO("*" * BYTES)
     for chunk in sizelimit.LimitingReader(data, BYTES - 1):
         bytes_read += len(chunk)