'Ensure limiting reader class throws exceptions if limit exceeded'

def test_limiting_reader_fails(self):

    BYTES = 1024
    def _consume_all_iter():
        bytes_read = 0
        data = six.StringIO(('*' * BYTES))
        for chunk in utils.LimitingReader(data, (BYTES - 1)):
            bytes_read += len(chunk)
    self.assertRaises(exception.ImageSizeLimitExceeded, _consume_all_iter)
    def _consume_all_read():
        bytes_read = 0
        data = six.StringIO(('*' * BYTES))
        reader = utils.LimitingReader(data, (BYTES - 1))
        byte = reader.read(1)
        while (len(byte) != 0):
            bytes_read += 1
            byte = reader.read(1)
    self.assertRaises(exception.ImageSizeLimitExceeded, _consume_all_read)
