mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-10-31 07:57:27 +03:00 
			
		
		
		
	Merge pull request #201 from wiredfool/pr199
Skip tests for features that aren't compiled in, includes #199
This commit is contained in:
		
						commit
						c3d6b0d7f6
					
				
							
								
								
									
										89
									
								
								Tests/test_file_libtiff.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										89
									
								
								Tests/test_file_libtiff.py
									
									
									
									
									
										Normal file
									
								
							|  | @ -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()) | ||||||
|  | 
 | ||||||
|  | @ -2,7 +2,12 @@ from tester import * | ||||||
| 
 | 
 | ||||||
| from PIL import Image | from PIL import Image | ||||||
| 
 | 
 | ||||||
| from test_file_tiff import _assert_noerr | 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 | """ The small lena image was failing on open in the libtiff | ||||||
|     decoder because the file pointer was set to the wrong place |     decoder because the file pointer was set to the wrong place | ||||||
|  | @ -2,21 +2,27 @@ from tester import * | ||||||
| 
 | 
 | ||||||
| from PIL import Image, TarIO | 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 | # sample ppm stream | ||||||
| tarfile = "Images/lena.tar" | tarfile = "Images/lena.tar" | ||||||
| 
 | 
 | ||||||
| def test_sanity(): | def test_sanity(): | ||||||
|     tar = TarIO.TarIO(tarfile, 'lena.png') |     if "zip_decoder" in codecs: | ||||||
|     im = Image.open(tar) |         tar = TarIO.TarIO(tarfile, 'lena.png') | ||||||
|     im.load() |         im = Image.open(tar) | ||||||
|     assert_equal(im.mode, "RGB") |         im.load() | ||||||
|     assert_equal(im.size, (128, 128)) |         assert_equal(im.mode, "RGB") | ||||||
|     assert_equal(im.format, "PNG") |         assert_equal(im.size, (128, 128)) | ||||||
|  |         assert_equal(im.format, "PNG") | ||||||
| 
 | 
 | ||||||
|     tar = TarIO.TarIO(tarfile, 'lena.jpg') |     if "jpeg_decoder" in codecs: | ||||||
|     im = Image.open(tar) |         tar = TarIO.TarIO(tarfile, 'lena.jpg') | ||||||
|     im.load() |         im = Image.open(tar) | ||||||
|     assert_equal(im.mode, "RGB") |         im.load() | ||||||
|     assert_equal(im.size, (128, 128)) |         assert_equal(im.mode, "RGB") | ||||||
|     assert_equal(im.format, "JPEG") |         assert_equal(im.size, (128, 128)) | ||||||
|  |         assert_equal(im.format, "JPEG") | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -2,8 +2,6 @@ from tester import * | ||||||
| 
 | 
 | ||||||
| from PIL import Image | from PIL import Image | ||||||
| 
 | 
 | ||||||
| import random |  | ||||||
| 
 |  | ||||||
| def test_sanity(): | def test_sanity(): | ||||||
| 
 | 
 | ||||||
|     file = tempfile("temp.tif") |     file = tempfile("temp.tif") | ||||||
|  | @ -58,83 +56,4 @@ def test_gimp_tiff(): | ||||||
|             ]) |             ]) | ||||||
|     assert_no_exception(lambda: im.load()) |     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()) |  | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -3,6 +3,11 @@ from tester import * | ||||||
| from PIL import Image, FontFile, PcfFontFile | from PIL import Image, FontFile, PcfFontFile | ||||||
| from PIL import ImageFont, ImageDraw | 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" | fontname = "Tests/fonts/helvO18.pcf" | ||||||
| tempname = tempfile("temp.pil", "temp.pbm") | tempname = tempfile("temp.pil", "temp.pbm") | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -2,6 +2,11 @@ from tester import * | ||||||
| 
 | 
 | ||||||
| from PIL import Image | 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" | filename = "Images/lena.jpg" | ||||||
| 
 | 
 | ||||||
| data = tostring(Image.open(filename).resize((512, 512)), "JPEG") | data = tostring(Image.open(filename).resize((512, 512)), "JPEG") | ||||||
|  |  | ||||||
|  | @ -30,7 +30,13 @@ def test_split_merge(): | ||||||
|     assert_image_equal(lena("YCbCr"), split_merge("YCbCr")) |     assert_image_equal(lena("YCbCr"), split_merge("YCbCr")) | ||||||
| 
 | 
 | ||||||
| def test_split_open(): | 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): |     def split_open(mode): | ||||||
|         lena(mode).save(file) |         lena(mode).save(file) | ||||||
|         im = Image.open(file) |         im = Image.open(file) | ||||||
|  | @ -39,4 +45,5 @@ def test_split_open(): | ||||||
|     assert_equal(split_open("L"), 1) |     assert_equal(split_open("L"), 1) | ||||||
|     assert_equal(split_open("P"), 1) |     assert_equal(split_open("P"), 1) | ||||||
|     assert_equal(split_open("RGB"), 3) |     assert_equal(split_open("RGB"), 3) | ||||||
|     assert_equal(split_open("RGBA"), 4) |     if 'zip_encoder' in codecs: | ||||||
|  |         assert_equal(split_open("RGBA"), 4) | ||||||
|  |  | ||||||
|  | @ -3,6 +3,8 @@ from tester import * | ||||||
| from PIL import Image | from PIL import Image | ||||||
| from PIL import ImageFile | from PIL import ImageFile | ||||||
| 
 | 
 | ||||||
|  | codecs = dir(Image.core) | ||||||
|  | 
 | ||||||
| # save original block sizes | # save original block sizes | ||||||
| MAXBLOCK = ImageFile.MAXBLOCK | MAXBLOCK = ImageFile.MAXBLOCK | ||||||
| SAFEBLOCK = ImageFile.SAFEBLOCK | SAFEBLOCK = ImageFile.SAFEBLOCK | ||||||
|  | @ -31,12 +33,13 @@ def test_parser(): | ||||||
|     assert_image_equal(*roundtrip("GIF")) |     assert_image_equal(*roundtrip("GIF")) | ||||||
|     assert_image_equal(*roundtrip("IM")) |     assert_image_equal(*roundtrip("IM")) | ||||||
|     assert_image_equal(*roundtrip("MSP")) |     assert_image_equal(*roundtrip("MSP")) | ||||||
|     try: |     if "zip_encoder" in codecs: | ||||||
|         # force multiple blocks in PNG driver |         try: | ||||||
|         ImageFile.MAXBLOCK = 8192 |             # force multiple blocks in PNG driver | ||||||
|         assert_image_equal(*roundtrip("PNG")) |             ImageFile.MAXBLOCK = 8192 | ||||||
|     finally: |             assert_image_equal(*roundtrip("PNG")) | ||||||
|         ImageFile.MAXBLOCK = MAXBLOCK |         finally: | ||||||
|  |             ImageFile.MAXBLOCK = MAXBLOCK | ||||||
|     assert_image_equal(*roundtrip("PPM")) |     assert_image_equal(*roundtrip("PPM")) | ||||||
|     assert_image_equal(*roundtrip("TIFF")) |     assert_image_equal(*roundtrip("TIFF")) | ||||||
|     assert_image_equal(*roundtrip("XBM")) |     assert_image_equal(*roundtrip("XBM")) | ||||||
|  | @ -44,8 +47,9 @@ def test_parser(): | ||||||
|     assert_image_equal(*roundtrip("TGA")) |     assert_image_equal(*roundtrip("TGA")) | ||||||
|     assert_image_equal(*roundtrip("PCX")) |     assert_image_equal(*roundtrip("PCX")) | ||||||
| 
 | 
 | ||||||
|     im1, im2 = roundtrip("JPEG") # lossy compression |     if "jpeg_encoder" in codecs: | ||||||
|     assert_image(im1, im2.mode, im2.size) |         im1, im2 = roundtrip("JPEG") # lossy compression | ||||||
|  |         assert_image(im1, im2.mode, im2.size) | ||||||
| 
 | 
 | ||||||
|     # XXX Why assert exception and why does it fail? |     # XXX Why assert exception and why does it fail? | ||||||
|     # https://github.com/python-imaging/Pillow/issues/78 |     # https://github.com/python-imaging/Pillow/issues/78 | ||||||
|  | @ -55,6 +59,9 @@ def test_safeblock(): | ||||||
| 
 | 
 | ||||||
|     im1 = lena() |     im1 = lena() | ||||||
| 
 | 
 | ||||||
|  |     if "zip_encoder" not in codecs: | ||||||
|  |         skip("PNG (zlib) encoder not available") | ||||||
|  | 
 | ||||||
|     try: |     try: | ||||||
|         ImageFile.SAFEBLOCK = 1 |         ImageFile.SAFEBLOCK = 1 | ||||||
|         im2 = fromstring(tostring(im1, "PNG")) |         im2 = fromstring(tostring(im1, "PNG")) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user