diff --git a/Tests/helper.py b/Tests/helper.py index 38eb98a94..b8b44b6f2 100644 --- a/Tests/helper.py +++ b/Tests/helper.py @@ -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 diff --git a/Tests/images/copyleft.png b/Tests/images/copyleft.png new file mode 100644 index 000000000..c0c63b887 Binary files /dev/null and b/Tests/images/copyleft.png differ diff --git a/Tests/images/pil136.png b/Tests/images/pil136.png new file mode 100644 index 000000000..ec752cf26 Binary files /dev/null and b/Tests/images/pil136.png differ diff --git a/Tests/images/pil168.png b/Tests/images/pil168.png new file mode 100644 index 000000000..1f752ff56 Binary files /dev/null and b/Tests/images/pil168.png differ diff --git a/Tests/images/tiff_16bit_RGBa_target.png b/Tests/images/tiff_16bit_RGBa_target.png new file mode 100644 index 000000000..cecc295d4 Binary files /dev/null and b/Tests/images/tiff_16bit_RGBa_target.png differ diff --git a/Tests/test_file_tiff.py b/Tests/test_file_tiff.py index 785e7a477..a108a922c 100644 --- a/Tests/test_file_tiff.py +++ b/Tests/test_file_tiff.py @@ -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