test_imagefile: handle missing PNG & JPEG encoders gracefully.

This commit is contained in:
Michał Górny 2013-04-21 10:13:33 +02:00
parent 6afa11ec02
commit 6cdc8b08db

View File

@ -3,6 +3,8 @@ from tester import *
from PIL import Image
from PIL import ImageFile
codecs = dir(Image.core)
# save original block sizes
MAXBLOCK = ImageFile.MAXBLOCK
SAFEBLOCK = ImageFile.SAFEBLOCK
@ -31,12 +33,13 @@ def test_parser():
assert_image_equal(*roundtrip("GIF"))
assert_image_equal(*roundtrip("IM"))
assert_image_equal(*roundtrip("MSP"))
try:
# force multiple blocks in PNG driver
ImageFile.MAXBLOCK = 8192
assert_image_equal(*roundtrip("PNG"))
finally:
ImageFile.MAXBLOCK = MAXBLOCK
if "zip_encoder" in codecs:
try:
# force multiple blocks in PNG driver
ImageFile.MAXBLOCK = 8192
assert_image_equal(*roundtrip("PNG"))
finally:
ImageFile.MAXBLOCK = MAXBLOCK
assert_image_equal(*roundtrip("PPM"))
assert_image_equal(*roundtrip("TIFF"))
assert_image_equal(*roundtrip("XBM"))
@ -44,8 +47,9 @@ def test_parser():
assert_image_equal(*roundtrip("TGA"))
assert_image_equal(*roundtrip("PCX"))
im1, im2 = roundtrip("JPEG") # lossy compression
assert_image(im1, im2.mode, im2.size)
if "jpeg_encoder" in codecs:
im1, im2 = roundtrip("JPEG") # lossy compression
assert_image(im1, im2.mode, im2.size)
# XXX Why assert exception and why does it fail?
# https://github.com/python-imaging/Pillow/issues/78
@ -55,6 +59,9 @@ def test_safeblock():
im1 = lena()
if "zip_encoder" not in codecs:
skip("PNG (zlib) encoder not available")
try:
ImageFile.SAFEBLOCK = 1
im2 = fromstring(tostring(im1, "PNG"))