mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-09 16:10:48 +03:00
test_imagefile: handle missing PNG & JPEG encoders gracefully.
This commit is contained in:
parent
6afa11ec02
commit
6cdc8b08db
|
@ -3,6 +3,8 @@ from tester import *
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from PIL import ImageFile
|
from PIL import ImageFile
|
||||||
|
|
||||||
|
codecs = dir(Image.core)
|
||||||
|
|
||||||
# save original block sizes
|
# save original block sizes
|
||||||
MAXBLOCK = ImageFile.MAXBLOCK
|
MAXBLOCK = ImageFile.MAXBLOCK
|
||||||
SAFEBLOCK = ImageFile.SAFEBLOCK
|
SAFEBLOCK = ImageFile.SAFEBLOCK
|
||||||
|
@ -31,6 +33,7 @@ def test_parser():
|
||||||
assert_image_equal(*roundtrip("GIF"))
|
assert_image_equal(*roundtrip("GIF"))
|
||||||
assert_image_equal(*roundtrip("IM"))
|
assert_image_equal(*roundtrip("IM"))
|
||||||
assert_image_equal(*roundtrip("MSP"))
|
assert_image_equal(*roundtrip("MSP"))
|
||||||
|
if "zip_encoder" in codecs:
|
||||||
try:
|
try:
|
||||||
# force multiple blocks in PNG driver
|
# force multiple blocks in PNG driver
|
||||||
ImageFile.MAXBLOCK = 8192
|
ImageFile.MAXBLOCK = 8192
|
||||||
|
@ -44,6 +47,7 @@ def test_parser():
|
||||||
assert_image_equal(*roundtrip("TGA"))
|
assert_image_equal(*roundtrip("TGA"))
|
||||||
assert_image_equal(*roundtrip("PCX"))
|
assert_image_equal(*roundtrip("PCX"))
|
||||||
|
|
||||||
|
if "jpeg_encoder" in codecs:
|
||||||
im1, im2 = roundtrip("JPEG") # lossy compression
|
im1, im2 = roundtrip("JPEG") # lossy compression
|
||||||
assert_image(im1, im2.mode, im2.size)
|
assert_image(im1, im2.mode, im2.size)
|
||||||
|
|
||||||
|
@ -55,6 +59,9 @@ def test_safeblock():
|
||||||
|
|
||||||
im1 = lena()
|
im1 = lena()
|
||||||
|
|
||||||
|
if "zip_encoder" not in codecs:
|
||||||
|
skip("PNG (zlib) encoder not available")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ImageFile.SAFEBLOCK = 1
|
ImageFile.SAFEBLOCK = 1
|
||||||
im2 = fromstring(tostring(im1, "PNG"))
|
im2 = fromstring(tostring(im1, "PNG"))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user