mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 09:26:16 +03:00
end to end test helper, more end to end tests for tiffs
This commit is contained in:
parent
bc6683cecf
commit
bec8f415be
|
@ -14,11 +14,22 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
|
||||
HAS_UPLOADER = False
|
||||
try:
|
||||
import test_image_results
|
||||
HAS_UPLOADER = True
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
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:
|
||||
import test_image_results
|
||||
HAS_UPLOADER = True
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
|
||||
def convert_to_comparable(a, b):
|
||||
|
@ -99,11 +110,17 @@ class PillowTestCase(unittest.TestCase):
|
|||
try:
|
||||
url = test_image_results.upload(a, b)
|
||||
logger.error("Url for test images: %s" % url)
|
||||
except:
|
||||
except Exception as msg:
|
||||
pass
|
||||
|
||||
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):
|
||||
epsilon = float(epsilon)
|
||||
self.assertEqual(
|
||||
|
@ -136,6 +153,12 @@ class PillowTestCase(unittest.TestCase):
|
|||
pass
|
||||
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):
|
||||
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))])
|
||||
im.load()
|
||||
|
||||
self.assert_image_similar_tofile(im, "Tests/images/pil136.png", 1)
|
||||
|
||||
def test_16bit_RGBa_tiff(self):
|
||||
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')])
|
||||
im.load()
|
||||
|
||||
self.assert_image_equal_tofile(im, "Tests/images/tiff_16bit_RGBa_target.png")
|
||||
|
||||
def test_wrong_bits_per_sample(self):
|
||||
im = Image.open("Tests/images/tiff_wrong_bits_per_sample.tiff")
|
||||
|
||||
|
@ -84,11 +88,15 @@ class TestFileTiff(PillowTestCase):
|
|||
)
|
||||
im.load()
|
||||
|
||||
self.assert_image_equal_tofile(im, "Tests/images/pil168.png")
|
||||
|
||||
def test_sampleformat(self):
|
||||
# https://github.com/python-pillow/Pillow/issues/1466
|
||||
im = Image.open("Tests/images/copyleft.tiff")
|
||||
self.assertEqual(im.mode, 'RGB')
|
||||
|
||||
self.assert_image_equal_tofile(im, "Tests/images/copyleft.png", mode='RGB')
|
||||
|
||||
def test_set_legacy_api(self):
|
||||
with self.assertRaises(Exception):
|
||||
ImageFileDirectory_v2.legacy_api = None
|
||||
|
@ -221,12 +229,7 @@ class TestFileTiff(PillowTestCase):
|
|||
# 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.
|
||||
|
||||
im2 = Image.open('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)
|
||||
self.assert_image_equal_tofile(im, 'Tests/images/12in16bit.tif')
|
||||
|
||||
def test_32bit_float(self):
|
||||
# Issue 614, specific 32-bit float format
|
||||
|
|
Loading…
Reference in New Issue
Block a user