end to end test helper, more end to end tests for tiffs

This commit is contained in:
Eric Soroos 2017-12-13 12:47:11 +00:00
parent bc6683cecf
commit bec8f415be
6 changed files with 38 additions and 12 deletions

View File

@ -14,11 +14,22 @@ logger = logging.getLogger(__name__)
HAS_UPLOADER = False HAS_UPLOADER = False
try:
import test_image_results if os.environ.get('SHOW_ERRORS', None):
HAS_UPLOADER = True # local img.show for errors.
except ImportError: HAS_UPLOADER=True
pass 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): def convert_to_comparable(a, b):
@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View File

@ -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