From 6afa11ec02df3d5e9e6b8da3c1eee91b7e6146aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Sun, 21 Apr 2013 10:04:58 +0200 Subject: [PATCH 01/10] test_file_tar: skip if codecs are not available. The .tar test requires both jpeg & zlib support. If one of the two is unavailable, run the test for the second one. If both are unavailable, skip the test. --- Tests/test_file_tar.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/Tests/test_file_tar.py b/Tests/test_file_tar.py index 0f87ea2c0..fa33d3802 100644 --- a/Tests/test_file_tar.py +++ b/Tests/test_file_tar.py @@ -2,21 +2,27 @@ from tester import * from PIL import Image, TarIO +codecs = dir(Image.core) +if "zip_decoder" not in codecs and "jpeg_decoder" not in codecs: + skip("neither jpeg nor zip support not available") + # sample ppm stream tarfile = "Images/lena.tar" def test_sanity(): - tar = TarIO.TarIO(tarfile, 'lena.png') - im = Image.open(tar) - im.load() - assert_equal(im.mode, "RGB") - assert_equal(im.size, (128, 128)) - assert_equal(im.format, "PNG") + if "zip_decoder" in codecs: + tar = TarIO.TarIO(tarfile, 'lena.png') + im = Image.open(tar) + im.load() + assert_equal(im.mode, "RGB") + assert_equal(im.size, (128, 128)) + assert_equal(im.format, "PNG") - tar = TarIO.TarIO(tarfile, 'lena.jpg') - im = Image.open(tar) - im.load() - assert_equal(im.mode, "RGB") - assert_equal(im.size, (128, 128)) - assert_equal(im.format, "JPEG") + if "jpeg_decoder" in codecs: + tar = TarIO.TarIO(tarfile, 'lena.jpg') + im = Image.open(tar) + im.load() + assert_equal(im.mode, "RGB") + assert_equal(im.size, (128, 128)) + assert_equal(im.format, "JPEG") From 6cdc8b08dbbbbeb76002ad7842534bc513be6219 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Sun, 21 Apr 2013 10:13:33 +0200 Subject: [PATCH 02/10] test_imagefile: handle missing PNG & JPEG encoders gracefully. --- Tests/test_imagefile.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/Tests/test_imagefile.py b/Tests/test_imagefile.py index 7493e0846..382ae27f2 100644 --- a/Tests/test_imagefile.py +++ b/Tests/test_imagefile.py @@ -3,6 +3,8 @@ from tester import * from PIL import Image from PIL import ImageFile +codecs = dir(Image.core) + # save original block sizes MAXBLOCK = ImageFile.MAXBLOCK SAFEBLOCK = ImageFile.SAFEBLOCK @@ -31,12 +33,13 @@ def test_parser(): assert_image_equal(*roundtrip("GIF")) assert_image_equal(*roundtrip("IM")) assert_image_equal(*roundtrip("MSP")) - try: - # force multiple blocks in PNG driver - ImageFile.MAXBLOCK = 8192 - assert_image_equal(*roundtrip("PNG")) - finally: - ImageFile.MAXBLOCK = MAXBLOCK + if "zip_encoder" in codecs: + try: + # force multiple blocks in PNG driver + ImageFile.MAXBLOCK = 8192 + assert_image_equal(*roundtrip("PNG")) + finally: + ImageFile.MAXBLOCK = MAXBLOCK assert_image_equal(*roundtrip("PPM")) assert_image_equal(*roundtrip("TIFF")) assert_image_equal(*roundtrip("XBM")) @@ -44,8 +47,9 @@ def test_parser(): assert_image_equal(*roundtrip("TGA")) assert_image_equal(*roundtrip("PCX")) - im1, im2 = roundtrip("JPEG") # lossy compression - assert_image(im1, im2.mode, im2.size) + if "jpeg_encoder" in codecs: + im1, im2 = roundtrip("JPEG") # lossy compression + assert_image(im1, im2.mode, im2.size) # XXX Why assert exception and why does it fail? # https://github.com/python-imaging/Pillow/issues/78 @@ -55,6 +59,9 @@ def test_safeblock(): im1 = lena() + if "zip_encoder" not in codecs: + skip("PNG (zlib) encoder not available") + try: ImageFile.SAFEBLOCK = 1 im2 = fromstring(tostring(im1, "PNG")) From e2221de8f568b05d37dcea80effbcd0f5cd2a008 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Sun, 21 Apr 2013 10:18:32 +0200 Subject: [PATCH 03/10] Support (most of) test_image_split without PNG. If PNG (zlib) support is disabled, use .pcx for test_image_split which is unconditional. Since it does not support RGBA, skip the RGBA test. Otherwise, just use PNG and do the full test. --- Tests/test_image_split.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Tests/test_image_split.py b/Tests/test_image_split.py index 7fc70182b..07a779664 100644 --- a/Tests/test_image_split.py +++ b/Tests/test_image_split.py @@ -30,7 +30,13 @@ def test_split_merge(): assert_image_equal(lena("YCbCr"), split_merge("YCbCr")) def test_split_open(): - file = tempfile("temp.png") + codecs = dir(Image.core) + + if 'zip_encoder' in codecs: + file = tempfile("temp.png") + else: + file = tempfile("temp.pcx") + def split_open(mode): lena(mode).save(file) im = Image.open(file) @@ -39,4 +45,5 @@ def test_split_open(): assert_equal(split_open("L"), 1) assert_equal(split_open("P"), 1) assert_equal(split_open("RGB"), 3) - assert_equal(split_open("RGBA"), 4) + if 'zip_encoder' in codecs: + assert_equal(split_open("RGBA"), 4) From a5a5c854b896026ceac46ed3baa2f29d42f7aed2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Sun, 21 Apr 2013 10:27:27 +0200 Subject: [PATCH 04/10] test_image_draft: skip if no JPEG support. --- Tests/test_image_draft.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Tests/test_image_draft.py b/Tests/test_image_draft.py index 41df761a6..e512aa033 100644 --- a/Tests/test_image_draft.py +++ b/Tests/test_image_draft.py @@ -2,6 +2,11 @@ from tester import * from PIL import Image +codecs = dir(Image.core) + +if "jpeg_encoder" not in codecs or "jpeg_decoder" not in codecs: + skip("jpeg support not available") + filename = "Images/lena.jpg" data = tostring(Image.open(filename).resize((512, 512)), "JPEG") From a83530f47544baf7da2b71d3d274ee7875b68157 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Sun, 21 Apr 2013 10:30:59 +0200 Subject: [PATCH 05/10] test_font_pcf: skip if zlib is not available. --- Tests/test_font_pcf.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Tests/test_font_pcf.py b/Tests/test_font_pcf.py index 958657eaa..60e6e0e26 100644 --- a/Tests/test_font_pcf.py +++ b/Tests/test_font_pcf.py @@ -3,6 +3,11 @@ from tester import * from PIL import Image, FontFile, PcfFontFile from PIL import ImageFont, ImageDraw +codecs = dir(Image.core) + +if "zip_encoder" not in codecs or "zip_decoder" not in codecs: + skip("zlib support not available") + fontname = "Tests/fonts/helvO18.pcf" tempname = tempfile("temp.pil", "temp.pbm") From 995fe2b041290739ba976ceef2f68409517a4751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Sun, 21 Apr 2013 10:32:42 +0200 Subject: [PATCH 06/10] test_file_tiff: skip if TIFF is not available. --- Tests/test_file_tiff.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Tests/test_file_tiff.py b/Tests/test_file_tiff.py index 6db12c4ff..cd3f2915b 100644 --- a/Tests/test_file_tiff.py +++ b/Tests/test_file_tiff.py @@ -4,6 +4,11 @@ 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") From 945b6bf53c38c0c3cde866142ca22a357bc3bf52 Mon Sep 17 00:00:00 2001 From: wiredfool Date: Sun, 21 Apr 2013 13:51:16 -0700 Subject: [PATCH 07/10] Split tiff tests so that test_file_tiff tests the builtins, and test_file_libtiff tests only things that depend on libtiff --- Tests/test_file_libtiff.py | 89 +++++++++++++++++++++++++++++++++++ Tests/test_file_tiff.py | 86 --------------------------------- Tests/test_file_tiff_small.py | 2 +- 3 files changed, 90 insertions(+), 87 deletions(-) create mode 100644 Tests/test_file_libtiff.py diff --git a/Tests/test_file_libtiff.py b/Tests/test_file_libtiff.py new file mode 100644 index 000000000..b838bf9d6 --- /dev/null +++ b/Tests/test_file_libtiff.py @@ -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()) + diff --git a/Tests/test_file_tiff.py b/Tests/test_file_tiff.py index cd3f2915b..d230bffa7 100644 --- a/Tests/test_file_tiff.py +++ b/Tests/test_file_tiff.py @@ -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()) diff --git a/Tests/test_file_tiff_small.py b/Tests/test_file_tiff_small.py index d0780fa87..6f00261a3 100644 --- a/Tests/test_file_tiff_small.py +++ b/Tests/test_file_tiff_small.py @@ -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 From d2c9ee14ad5eaefa5085f84458d16611d48d42b9 Mon Sep 17 00:00:00 2001 From: wiredfool Date: Sun, 21 Apr 2013 13:52:04 -0700 Subject: [PATCH 08/10] skipp these test is libtiff support is not included --- Tests/test_file_tiff_small.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Tests/test_file_tiff_small.py b/Tests/test_file_tiff_small.py index 6f00261a3..dbc16435f 100644 --- a/Tests/test_file_tiff_small.py +++ b/Tests/test_file_tiff_small.py @@ -4,6 +4,11 @@ from PIL import Image from test_file_libtiff import _assert_noerr +codecs = dir(Image.core) + +if "group4_encoder" not in codecs or "group4_decoder" not in codecs: + skip("tiff support not available") + """ The small lena image was failing on open in the libtiff decoder because the file pointer was set to the wrong place by a spurious seek. It wasn't failing with the byteio method. From 25f26f74e8168df83e335fcb16e75edd67713ef2 Mon Sep 17 00:00:00 2001 From: wiredfool Date: Sun, 21 Apr 2013 13:53:43 -0700 Subject: [PATCH 09/10] rename to include libtiff --- Tests/test_file_libtiff_small.py | 52 ++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Tests/test_file_libtiff_small.py diff --git a/Tests/test_file_libtiff_small.py b/Tests/test_file_libtiff_small.py new file mode 100644 index 000000000..dbc16435f --- /dev/null +++ b/Tests/test_file_libtiff_small.py @@ -0,0 +1,52 @@ +from tester import * + +from PIL import Image + +from test_file_libtiff import _assert_noerr + +codecs = dir(Image.core) + +if "group4_encoder" not in codecs or "group4_decoder" not in codecs: + skip("tiff support not available") + +""" The small lena image was failing on open in the libtiff + decoder because the file pointer was set to the wrong place + by a spurious seek. It wasn't failing with the byteio method. + + It was fixed by forcing an lseek to the beginning of the + file just before reading in libtiff. These tests remain + to ensure that it stays fixed. """ + + +def test_g4_lena_file(): + """Testing the open file load path""" + + file = "Tests/images/lena_g4.tif" + with open(file,'rb') as f: + im = Image.open(f) + + assert_equal(im.size, (128,128)) + _assert_noerr(im) + +def test_g4_lena_bytesio(): + """Testing the bytesio loading code path""" + from io import BytesIO + file = "Tests/images/lena_g4.tif" + s = BytesIO() + with open(file,'rb') as f: + s.write(f.read()) + s.seek(0) + im = Image.open(s) + + assert_equal(im.size, (128,128)) + _assert_noerr(im) + +def test_g4_lena(): + """The 128x128 lena image fails for some reason. Investigating""" + + file = "Tests/images/lena_g4.tif" + im = Image.open(file) + + assert_equal(im.size, (128,128)) + _assert_noerr(im) + From 52cbacf0286ee8f94aeaaa693944c002a3afc4bc Mon Sep 17 00:00:00 2001 From: wiredfool Date: Sun, 21 Apr 2013 13:54:30 -0700 Subject: [PATCH 10/10] renamed --- Tests/test_file_tiff_small.py | 52 ----------------------------------- 1 file changed, 52 deletions(-) delete mode 100644 Tests/test_file_tiff_small.py diff --git a/Tests/test_file_tiff_small.py b/Tests/test_file_tiff_small.py deleted file mode 100644 index dbc16435f..000000000 --- a/Tests/test_file_tiff_small.py +++ /dev/null @@ -1,52 +0,0 @@ -from tester import * - -from PIL import Image - -from test_file_libtiff import _assert_noerr - -codecs = dir(Image.core) - -if "group4_encoder" not in codecs or "group4_decoder" not in codecs: - skip("tiff support not available") - -""" The small lena image was failing on open in the libtiff - decoder because the file pointer was set to the wrong place - by a spurious seek. It wasn't failing with the byteio method. - - It was fixed by forcing an lseek to the beginning of the - file just before reading in libtiff. These tests remain - to ensure that it stays fixed. """ - - -def test_g4_lena_file(): - """Testing the open file load path""" - - file = "Tests/images/lena_g4.tif" - with open(file,'rb') as f: - im = Image.open(f) - - assert_equal(im.size, (128,128)) - _assert_noerr(im) - -def test_g4_lena_bytesio(): - """Testing the bytesio loading code path""" - from io import BytesIO - file = "Tests/images/lena_g4.tif" - s = BytesIO() - with open(file,'rb') as f: - s.write(f.read()) - s.seek(0) - im = Image.open(s) - - assert_equal(im.size, (128,128)) - _assert_noerr(im) - -def test_g4_lena(): - """The 128x128 lena image fails for some reason. Investigating""" - - file = "Tests/images/lena_g4.tif" - im = Image.open(file) - - assert_equal(im.size, (128,128)) - _assert_noerr(im) -