mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 09:56:17 +03:00
Split tiff tests so that test_file_tiff tests the builtins, and test_file_libtiff tests only things that depend on libtiff
This commit is contained in:
parent
995fe2b041
commit
945b6bf53c
89
Tests/test_file_libtiff.py
Normal file
89
Tests/test_file_libtiff.py
Normal file
|
@ -0,0 +1,89 @@
|
|||
from tester import *
|
||||
|
||||
from PIL import Image
|
||||
|
||||
codecs = dir(Image.core)
|
||||
|
||||
if "group4_encoder" not in codecs or "group4_decoder" not in codecs:
|
||||
skip("tiff support not available")
|
||||
|
||||
def _assert_noerr(im):
|
||||
"""Helper tests that assert basic sanity about the g4 tiff reading"""
|
||||
#1 bit
|
||||
assert_equal(im.mode, "1")
|
||||
|
||||
# Does the data actually load
|
||||
assert_no_exception(lambda: im.load())
|
||||
assert_no_exception(lambda: im.getdata())
|
||||
|
||||
try:
|
||||
assert_equal(im._compression, 'group4')
|
||||
except:
|
||||
print("No _compression")
|
||||
print (dir(im))
|
||||
|
||||
# can we write it back out, in a different form.
|
||||
out = tempfile("temp.png")
|
||||
assert_no_exception(lambda: im.save(out))
|
||||
|
||||
def test_g4_tiff():
|
||||
"""Test the ordinary file path load path"""
|
||||
|
||||
file = "Tests/images/lena_g4_500.tif"
|
||||
im = Image.open(file)
|
||||
|
||||
assert_equal(im.size, (500,500))
|
||||
_assert_noerr(im)
|
||||
|
||||
def test_g4_large():
|
||||
file = "Tests/images/pport_g4.tif"
|
||||
im = Image.open(file)
|
||||
_assert_noerr(im)
|
||||
|
||||
def test_g4_tiff_file():
|
||||
"""Testing the string load path"""
|
||||
|
||||
file = "Tests/images/lena_g4_500.tif"
|
||||
with open(file,'rb') as f:
|
||||
im = Image.open(f)
|
||||
|
||||
assert_equal(im.size, (500,500))
|
||||
_assert_noerr(im)
|
||||
|
||||
def test_g4_tiff_bytesio():
|
||||
"""Testing the stringio loading code path"""
|
||||
from io import BytesIO
|
||||
file = "Tests/images/lena_g4_500.tif"
|
||||
s = BytesIO()
|
||||
with open(file,'rb') as f:
|
||||
s.write(f.read())
|
||||
s.seek(0)
|
||||
im = Image.open(s)
|
||||
|
||||
assert_equal(im.size, (500,500))
|
||||
_assert_noerr(im)
|
||||
|
||||
def test_g4_eq_png():
|
||||
""" Checking that we're actually getting the data that we expect"""
|
||||
png = Image.open('Tests/images/lena_bw_500.png')
|
||||
g4 = Image.open('Tests/images/lena_g4_500.tif')
|
||||
|
||||
assert_image_equal(g4, png)
|
||||
|
||||
def test_g4_write():
|
||||
"""Checking to see that the saved image is the same as what we wrote"""
|
||||
file = "Tests/images/lena_g4_500.tif"
|
||||
orig = Image.open(file)
|
||||
|
||||
out = tempfile("temp.tif")
|
||||
rot = orig.transpose(Image.ROTATE_90)
|
||||
assert_equal(rot.size,(500,500))
|
||||
rot.save(out)
|
||||
|
||||
reread = Image.open(out)
|
||||
assert_equal(reread.size,(500,500))
|
||||
_assert_noerr(reread)
|
||||
assert_image_equal(reread, rot)
|
||||
|
||||
assert_false(orig.tobytes() == reread.tobytes())
|
||||
|
|
@ -2,13 +2,6 @@ from tester import *
|
|||
|
||||
from PIL import Image
|
||||
|
||||
import random
|
||||
|
||||
codecs = dir(Image.core)
|
||||
|
||||
if "group4_encoder" not in codecs or "group4_decoder" not in codecs:
|
||||
skip("tiff support not available")
|
||||
|
||||
def test_sanity():
|
||||
|
||||
file = tempfile("temp.tif")
|
||||
|
@ -63,83 +56,4 @@ def test_gimp_tiff():
|
|||
])
|
||||
assert_no_exception(lambda: im.load())
|
||||
|
||||
def _assert_noerr(im):
|
||||
"""Helper tests that assert basic sanity about the g4 tiff reading"""
|
||||
#1 bit
|
||||
assert_equal(im.mode, "1")
|
||||
|
||||
# Does the data actually load
|
||||
assert_no_exception(lambda: im.load())
|
||||
assert_no_exception(lambda: im.getdata())
|
||||
|
||||
try:
|
||||
assert_equal(im._compression, 'group4')
|
||||
except:
|
||||
print("No _compression")
|
||||
print (dir(im))
|
||||
|
||||
# can we write it back out, in a different form.
|
||||
out = tempfile("temp.png")
|
||||
assert_no_exception(lambda: im.save(out))
|
||||
|
||||
def test_g4_tiff():
|
||||
"""Test the ordinary file path load path"""
|
||||
|
||||
file = "Tests/images/lena_g4_500.tif"
|
||||
im = Image.open(file)
|
||||
|
||||
assert_equal(im.size, (500,500))
|
||||
_assert_noerr(im)
|
||||
|
||||
def test_g4_large():
|
||||
file = "Tests/images/pport_g4.tif"
|
||||
im = Image.open(file)
|
||||
_assert_noerr(im)
|
||||
|
||||
def test_g4_tiff_file():
|
||||
"""Testing the string load path"""
|
||||
|
||||
file = "Tests/images/lena_g4_500.tif"
|
||||
with open(file,'rb') as f:
|
||||
im = Image.open(f)
|
||||
|
||||
assert_equal(im.size, (500,500))
|
||||
_assert_noerr(im)
|
||||
|
||||
def test_g4_tiff_bytesio():
|
||||
"""Testing the stringio loading code path"""
|
||||
from io import BytesIO
|
||||
file = "Tests/images/lena_g4_500.tif"
|
||||
s = BytesIO()
|
||||
with open(file,'rb') as f:
|
||||
s.write(f.read())
|
||||
s.seek(0)
|
||||
im = Image.open(s)
|
||||
|
||||
assert_equal(im.size, (500,500))
|
||||
_assert_noerr(im)
|
||||
|
||||
def test_g4_eq_png():
|
||||
""" Checking that we're actually getting the data that we expect"""
|
||||
png = Image.open('Tests/images/lena_bw_500.png')
|
||||
g4 = Image.open('Tests/images/lena_g4_500.tif')
|
||||
|
||||
assert_image_equal(g4, png)
|
||||
|
||||
def test_g4_write():
|
||||
"""Checking to see that the saved image is the same as what we wrote"""
|
||||
file = "Tests/images/lena_g4_500.tif"
|
||||
orig = Image.open(file)
|
||||
|
||||
out = tempfile("temp.tif")
|
||||
rot = orig.transpose(Image.ROTATE_90)
|
||||
assert_equal(rot.size,(500,500))
|
||||
rot.save(out)
|
||||
|
||||
reread = Image.open(out)
|
||||
assert_equal(reread.size,(500,500))
|
||||
_assert_noerr(reread)
|
||||
assert_image_equal(reread, rot)
|
||||
|
||||
assert_false(orig.tobytes() == reread.tobytes())
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ from tester import *
|
|||
|
||||
from PIL import Image
|
||||
|
||||
from test_file_tiff import _assert_noerr
|
||||
from test_file_libtiff import _assert_noerr
|
||||
|
||||
""" The small lena image was failing on open in the libtiff
|
||||
decoder because the file pointer was set to the wrong place
|
||||
|
|
Loading…
Reference in New Issue
Block a user