test for loading truncated image and raising proper exception

This commit is contained in:
homm 2015-07-31 15:49:46 +03:00
parent b078ad4599
commit 430e9922eb
2 changed files with 21 additions and 3 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

View File

@ -79,12 +79,11 @@ class TestImageFile(PillowTestCase):
self.assertEqual((48, 48), p.image.size)
def test_safeblock(self):
im1 = hopper()
if "zip_encoder" not in codecs:
self.skipTest("PNG (zlib) encoder not available")
im1 = hopper()
try:
ImageFile.SAFEBLOCK = 1
im2 = fromstring(tostring(im1, "PNG"))
@ -96,6 +95,25 @@ class TestImageFile(PillowTestCase):
def test_raise_ioerror(self):
self.assertRaises(IOError, lambda: ImageFile.raise_ioerror(1))
def test_truncated_with_errors(self):
if "zip_encoder" not in codecs:
self.skipTest("PNG (zlib) encoder not available")
im = Image.open("Tests/images/truncated_image.png")
with self.assertRaises(IOError):
im.load()
def test_truncated_without_errors(self):
if "zip_encoder" not in codecs:
self.skipTest("PNG (zlib) encoder not available")
im = Image.open("Tests/images/truncated_image.png")
ImageFile.LOAD_TRUNCATED_IMAGES = True
try:
im.load()
finally:
ImageFile.LOAD_TRUNCATED_IMAGES = False
if __name__ == '__main__':
unittest.main()