mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 17:36:18 +03:00
end to end test helper, more end to end tests for tiffs
This commit is contained in:
parent
bc6683cecf
commit
bec8f415be
|
@ -14,6 +14,16 @@ logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
HAS_UPLOADER = False
|
HAS_UPLOADER = False
|
||||||
|
|
||||||
|
if os.environ.get('SHOW_ERRORS', None):
|
||||||
|
# local img.show for errors.
|
||||||
|
HAS_UPLOADER=True
|
||||||
|
class test_image_results:
|
||||||
|
@classmethod
|
||||||
|
def upload(self, a, b):
|
||||||
|
a.show()
|
||||||
|
b.show()
|
||||||
|
else:
|
||||||
try:
|
try:
|
||||||
import test_image_results
|
import test_image_results
|
||||||
HAS_UPLOADER = True
|
HAS_UPLOADER = True
|
||||||
|
@ -21,6 +31,7 @@ except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def convert_to_comparable(a, b):
|
def convert_to_comparable(a, b):
|
||||||
new_a, new_b = a, b
|
new_a, new_b = a, b
|
||||||
if a.mode == 'P':
|
if a.mode == 'P':
|
||||||
|
@ -99,11 +110,17 @@ class PillowTestCase(unittest.TestCase):
|
||||||
try:
|
try:
|
||||||
url = test_image_results.upload(a, b)
|
url = test_image_results.upload(a, b)
|
||||||
logger.error("Url for test images: %s" % url)
|
logger.error("Url for test images: %s" % url)
|
||||||
except:
|
except Exception as msg:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
self.fail(msg or "got different content")
|
self.fail(msg or "got different content")
|
||||||
|
|
||||||
|
def assert_image_equal_tofile(self, a, filename, msg=None, mode=None):
|
||||||
|
with Image.open(filename) as img:
|
||||||
|
if mode:
|
||||||
|
img = img.convert(mode)
|
||||||
|
self.assert_image_equal(a, img, msg)
|
||||||
|
|
||||||
def assert_image_similar(self, a, b, epsilon, msg=None):
|
def assert_image_similar(self, a, b, epsilon, msg=None):
|
||||||
epsilon = float(epsilon)
|
epsilon = float(epsilon)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
@ -136,6 +153,12 @@ class PillowTestCase(unittest.TestCase):
|
||||||
pass
|
pass
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
def assert_image_similar_tofile(self, a, filename, epsilon, msg=None, mode=None):
|
||||||
|
with Image.open(filename) as img:
|
||||||
|
if mode:
|
||||||
|
img = img.convert(mode)
|
||||||
|
self.assert_image_similar(a, img, epsilon, msg)
|
||||||
|
|
||||||
def assert_warning(self, warn_class, func, *args, **kwargs):
|
def assert_warning(self, warn_class, func, *args, **kwargs):
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
|
|
BIN
Tests/images/copyleft.png
Normal file
BIN
Tests/images/copyleft.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.0 KiB |
BIN
Tests/images/pil136.png
Normal file
BIN
Tests/images/pil136.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
BIN
Tests/images/pil168.png
Normal file
BIN
Tests/images/pil168.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.6 KiB |
BIN
Tests/images/tiff_16bit_RGBa_target.png
Normal file
BIN
Tests/images/tiff_16bit_RGBa_target.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
|
@ -51,6 +51,8 @@ class TestFileTiff(PillowTestCase):
|
||||||
self.assertEqual(im.tile, [('raw', (0, 0, 55, 43), 8, ('RGBa', 0, 1))])
|
self.assertEqual(im.tile, [('raw', (0, 0, 55, 43), 8, ('RGBa', 0, 1))])
|
||||||
im.load()
|
im.load()
|
||||||
|
|
||||||
|
self.assert_image_similar_tofile(im, "Tests/images/pil136.png", 1)
|
||||||
|
|
||||||
def test_16bit_RGBa_tiff(self):
|
def test_16bit_RGBa_tiff(self):
|
||||||
im = Image.open("Tests/images/tiff_16bit_RGBa.tiff")
|
im = Image.open("Tests/images/tiff_16bit_RGBa.tiff")
|
||||||
|
|
||||||
|
@ -59,6 +61,8 @@ class TestFileTiff(PillowTestCase):
|
||||||
self.assertEqual(im.tile, [('tiff_lzw', (0, 0, 100, 40), 50, 'RGBa;16B')])
|
self.assertEqual(im.tile, [('tiff_lzw', (0, 0, 100, 40), 50, 'RGBa;16B')])
|
||||||
im.load()
|
im.load()
|
||||||
|
|
||||||
|
self.assert_image_equal_tofile(im, "Tests/images/tiff_16bit_RGBa_target.png")
|
||||||
|
|
||||||
def test_wrong_bits_per_sample(self):
|
def test_wrong_bits_per_sample(self):
|
||||||
im = Image.open("Tests/images/tiff_wrong_bits_per_sample.tiff")
|
im = Image.open("Tests/images/tiff_wrong_bits_per_sample.tiff")
|
||||||
|
|
||||||
|
@ -84,11 +88,15 @@ class TestFileTiff(PillowTestCase):
|
||||||
)
|
)
|
||||||
im.load()
|
im.load()
|
||||||
|
|
||||||
|
self.assert_image_equal_tofile(im, "Tests/images/pil168.png")
|
||||||
|
|
||||||
def test_sampleformat(self):
|
def test_sampleformat(self):
|
||||||
# https://github.com/python-pillow/Pillow/issues/1466
|
# https://github.com/python-pillow/Pillow/issues/1466
|
||||||
im = Image.open("Tests/images/copyleft.tiff")
|
im = Image.open("Tests/images/copyleft.tiff")
|
||||||
self.assertEqual(im.mode, 'RGB')
|
self.assertEqual(im.mode, 'RGB')
|
||||||
|
|
||||||
|
self.assert_image_equal_tofile(im, "Tests/images/copyleft.png", mode='RGB')
|
||||||
|
|
||||||
def test_set_legacy_api(self):
|
def test_set_legacy_api(self):
|
||||||
with self.assertRaises(Exception):
|
with self.assertRaises(Exception):
|
||||||
ImageFileDirectory_v2.legacy_api = None
|
ImageFileDirectory_v2.legacy_api = None
|
||||||
|
@ -221,12 +229,7 @@ class TestFileTiff(PillowTestCase):
|
||||||
# imagemagick will auto scale so that a 12bit FFF is 16bit FFF0,
|
# imagemagick will auto scale so that a 12bit FFF is 16bit FFF0,
|
||||||
# so we need to unshift so that the integer values are the same.
|
# so we need to unshift so that the integer values are the same.
|
||||||
|
|
||||||
im2 = Image.open('Tests/images/12in16bit.tif')
|
self.assert_image_equal_tofile(im, 'Tests/images/12in16bit.tif')
|
||||||
|
|
||||||
logger.debug("%s", [img.getpixel((0, idx))
|
|
||||||
for img in [im, im2] for idx in range(3)])
|
|
||||||
|
|
||||||
self.assert_image_equal(im, im2)
|
|
||||||
|
|
||||||
def test_32bit_float(self):
|
def test_32bit_float(self):
|
||||||
# Issue 614, specific 32-bit float format
|
# Issue 614, specific 32-bit float format
|
||||||
|
|
Loading…
Reference in New Issue
Block a user