diff --git a/Tests/helper.py b/Tests/helper.py index 3f7913b11..637e77f9c 100644 --- a/Tests/helper.py +++ b/Tests/helper.py @@ -180,6 +180,26 @@ def tostring(im, format, **options): return out.getvalue() +def hopper(mode="RGB", cache={}): + from PIL import Image + im = None + # FIXME: Implement caching to reduce reading from disk but so an original + # copy is returned each time and the cached image isn't modified by tests + # (for fast, isolated, repeatable tests). + # im = cache.get(mode) + if im is None: + if mode == "RGB": + im = Image.open("Tests/images/hopper.ppm") + elif mode == "F": + im = lena("L").convert(mode) + elif mode[:4] == "I;16": + im = lena("I").convert(mode) + else: + im = lena("RGB").convert(mode) + # cache[mode] = im + return im + + def lena(mode="RGB", cache={}): from PIL import Image im = None diff --git a/Tests/images/effect_spread.png b/Tests/images/effect_spread.png index df7cfa474..01016355a 100644 Binary files a/Tests/images/effect_spread.png and b/Tests/images/effect_spread.png differ diff --git a/Tests/images/hopper.bw b/Tests/images/hopper.bw new file mode 100644 index 000000000..c9dabf64a Binary files /dev/null and b/Tests/images/hopper.bw differ diff --git a/Tests/images/hopper.dcx b/Tests/images/hopper.dcx new file mode 100644 index 000000000..ba6bd062e Binary files /dev/null and b/Tests/images/hopper.dcx differ diff --git a/Tests/images/hopper.gif b/Tests/images/hopper.gif new file mode 100644 index 000000000..2e7f5ade8 Binary files /dev/null and b/Tests/images/hopper.gif differ diff --git a/Tests/images/hopper.ico b/Tests/images/hopper.ico new file mode 100644 index 000000000..0c6fd8c70 Binary files /dev/null and b/Tests/images/hopper.ico differ diff --git a/Tests/images/hopper.jpg b/Tests/images/hopper.jpg new file mode 100644 index 000000000..82ab5b967 Binary files /dev/null and b/Tests/images/hopper.jpg differ diff --git a/Tests/images/hopper.png b/Tests/images/hopper.png new file mode 100644 index 000000000..60ac671a2 Binary files /dev/null and b/Tests/images/hopper.png differ diff --git a/Tests/images/hopper.ppm b/Tests/images/hopper.ppm new file mode 100644 index 000000000..346e42392 Binary files /dev/null and b/Tests/images/hopper.ppm differ diff --git a/Tests/images/hopper.ras b/Tests/images/hopper.ras new file mode 100644 index 000000000..70f3c80d0 Binary files /dev/null and b/Tests/images/hopper.ras differ diff --git a/Tests/images/hopper.rgb b/Tests/images/hopper.rgb new file mode 100644 index 000000000..a72fc5b15 Binary files /dev/null and b/Tests/images/hopper.rgb differ diff --git a/Tests/images/hopper.spider b/Tests/images/hopper.spider new file mode 100644 index 000000000..70e31b07c Binary files /dev/null and b/Tests/images/hopper.spider differ diff --git a/Tests/images/hopper.tar b/Tests/images/hopper.tar new file mode 100644 index 000000000..593429c9a Binary files /dev/null and b/Tests/images/hopper.tar differ diff --git a/Tests/images/lena.bw b/Tests/images/lena.bw deleted file mode 100644 index e2981ef5c..000000000 Binary files a/Tests/images/lena.bw and /dev/null differ diff --git a/Tests/images/lena.dcx b/Tests/images/lena.dcx deleted file mode 100644 index d05370be8..000000000 Binary files a/Tests/images/lena.dcx and /dev/null differ diff --git a/Tests/images/lena.gif b/Tests/images/lena.gif deleted file mode 100644 index 64a9b93c8..000000000 Binary files a/Tests/images/lena.gif and /dev/null differ diff --git a/Tests/images/lena.ico b/Tests/images/lena.ico deleted file mode 100644 index 6fadbe29e..000000000 Binary files a/Tests/images/lena.ico and /dev/null differ diff --git a/Tests/images/lena.png b/Tests/images/lena.png deleted file mode 100644 index 192875931..000000000 Binary files a/Tests/images/lena.png and /dev/null differ diff --git a/Tests/images/lena.ras b/Tests/images/lena.ras deleted file mode 100644 index b5893e758..000000000 Binary files a/Tests/images/lena.ras and /dev/null differ diff --git a/Tests/images/lena.rgb b/Tests/images/lena.rgb deleted file mode 100644 index 82552c758..000000000 Binary files a/Tests/images/lena.rgb and /dev/null differ diff --git a/Tests/images/lena.spider b/Tests/images/lena.spider deleted file mode 100644 index df963c1c3..000000000 Binary files a/Tests/images/lena.spider and /dev/null differ diff --git a/Tests/images/lena.tar b/Tests/images/lena.tar deleted file mode 100644 index 3afb1f542..000000000 Binary files a/Tests/images/lena.tar and /dev/null differ diff --git a/Tests/test_file_dcx.py b/Tests/test_file_dcx.py index 9a6183651..2acf7b459 100644 --- a/Tests/test_file_dcx.py +++ b/Tests/test_file_dcx.py @@ -1,9 +1,9 @@ -from helper import unittest, PillowTestCase, lena +from helper import unittest, PillowTestCase, hopper from PIL import Image, DcxImagePlugin -# Created with ImageMagick: convert lena.ppm lena.dcx -TEST_FILE = "Tests/images/lena.dcx" +# Created with ImageMagick: convert hopper.ppm hopper.dcx +TEST_FILE = "Tests/images/hopper.dcx" class TestFileDcx(PillowTestCase): @@ -17,7 +17,7 @@ class TestFileDcx(PillowTestCase): # Assert self.assertEqual(im.size, (128, 128)) self.assertIsInstance(im, DcxImagePlugin.DcxImageFile) - orig = lena() + orig = hopper() self.assert_image_equal(im, orig) def test_tell(self): diff --git a/Tests/test_file_gif.py b/Tests/test_file_gif.py index bd4a6e76c..72c9d9db4 100644 --- a/Tests/test_file_gif.py +++ b/Tests/test_file_gif.py @@ -1,4 +1,4 @@ -from helper import unittest, PillowTestCase, lena, netpbm_available +from helper import unittest, PillowTestCase, hopper, netpbm_available from PIL import Image from PIL import GifImagePlugin @@ -6,8 +6,9 @@ from PIL import GifImagePlugin codecs = dir(Image.core) # sample gif stream -file = "Tests/images/lena.gif" -with open(file, "rb") as f: +TEST_GIF = "Tests/images/hopper.gif" + +with open(TEST_GIF, "rb") as f: data = f.read() @@ -18,7 +19,7 @@ class TestFileGif(PillowTestCase): self.skipTest("gif support not available") # can this happen? def test_sanity(self): - im = Image.open(file) + im = Image.open(TEST_GIF) im.load() self.assertEqual(im.mode, "P") self.assertEqual(im.size, (128, 128)) @@ -45,7 +46,7 @@ class TestFileGif(PillowTestCase): def test_roundtrip(self): out = self.tempfile('temp.gif') - im = lena() + im = hopper() im.save(out) reread = Image.open(out) @@ -54,17 +55,17 @@ class TestFileGif(PillowTestCase): def test_roundtrip2(self): # see https://github.com/python-pillow/Pillow/issues/403 out = self.tempfile('temp.gif') - im = Image.open('Tests/images/lena.gif') + im = Image.open(TEST_GIF) im2 = im.copy() im2.save(out) reread = Image.open(out) - self.assert_image_similar(reread.convert('RGB'), lena(), 50) + self.assert_image_similar(reread.convert('RGB'), hopper(), 50) def test_palette_handling(self): # see https://github.com/python-pillow/Pillow/issues/513 - im = Image.open('Tests/images/lena.gif') + im = Image.open(TEST_GIF) im = im.convert('RGB') im = im.resize((100, 100), Image.ANTIALIAS) @@ -100,7 +101,7 @@ class TestFileGif(PillowTestCase): @unittest.skipUnless(netpbm_available(), "netpbm not available") def test_save_netpbm_bmp_mode(self): - img = Image.open(file).convert("RGB") + img = Image.open(TEST_GIF).convert("RGB") tempfile = self.tempfile("temp.gif") GifImagePlugin._save_netpbm(img, 0, tempfile) @@ -108,7 +109,7 @@ class TestFileGif(PillowTestCase): @unittest.skipUnless(netpbm_available(), "netpbm not available") def test_save_netpbm_l_mode(self): - img = Image.open(file).convert("L") + img = Image.open(TEST_GIF).convert("L") tempfile = self.tempfile("temp.gif") GifImagePlugin._save_netpbm(img, 0, tempfile) diff --git a/Tests/test_file_ico.py b/Tests/test_file_ico.py index c3bf7a992..12f4ed3f3 100644 --- a/Tests/test_file_ico.py +++ b/Tests/test_file_ico.py @@ -3,14 +3,14 @@ from helper import unittest, PillowTestCase from PIL import Image # sample ppm stream -file = "Tests/images/lena.ico" -data = open(file, "rb").read() +TEST_ICO_FILE = "Tests/images/hopper.ico" +TEST_DATA = open(TEST_ICO_FILE, "rb").read() class TestFileIco(PillowTestCase): def test_sanity(self): - im = Image.open(file) + im = Image.open(TEST_ICO_FILE) im.load() self.assertEqual(im.mode, "RGBA") self.assertEqual(im.size, (16, 16)) diff --git a/Tests/test_file_png.py b/Tests/test_file_png.py index 8ef166347..32dc10cd1 100644 --- a/Tests/test_file_png.py +++ b/Tests/test_file_png.py @@ -1,4 +1,4 @@ -from helper import unittest, PillowTestCase, lena +from helper import unittest, PillowTestCase, hopper from io import BytesIO @@ -10,8 +10,8 @@ codecs = dir(Image.core) # sample png stream -file = "Tests/images/lena.png" -data = open(file, "rb").read() +TEST_PNG_FILE = "Tests/images/hopper.png" +TEST_DATA = open(TEST_PNG_FILE, "rb").read() # stuff to create inline PNG images @@ -58,7 +58,7 @@ class TestFilePng(PillowTestCase): file = self.tempfile("temp.png") - lena("RGB").save(file) + hopper("RGB").save(file) im = Image.open(file) im.load() @@ -66,19 +66,19 @@ class TestFilePng(PillowTestCase): self.assertEqual(im.size, (128, 128)) self.assertEqual(im.format, "PNG") - lena("1").save(file) + hopper("1").save(file) im = Image.open(file) - lena("L").save(file) + hopper("L").save(file) im = Image.open(file) - lena("P").save(file) + hopper("P").save(file) im = Image.open(file) - lena("RGB").save(file) + hopper("RGB").save(file) im = Image.open(file) - lena("I").save(file) + hopper("I").save(file) im = Image.open(file) def test_broken(self): @@ -237,17 +237,17 @@ class TestFilePng(PillowTestCase): def test_load_verify(self): # Check open/load/verify exception (@PIL150) - im = Image.open("Tests/images/lena.png") + im = Image.open(TEST_PNG_FILE) im.verify() - im = Image.open("Tests/images/lena.png") + im = Image.open(TEST_PNG_FILE) im.load() self.assertRaises(RuntimeError, lambda: im.verify()) def test_roundtrip_dpi(self): # Check dpi roundtripping - im = Image.open(file) + im = Image.open(TEST_PNG_FILE) im = roundtrip(im, dpi=(100, 100)) self.assertEqual(im.info["dpi"], (100, 100)) @@ -255,7 +255,7 @@ class TestFilePng(PillowTestCase): def test_roundtrip_text(self): # Check text roundtripping - im = Image.open(file) + im = Image.open(TEST_PNG_FILE) info = PngImagePlugin.PngInfo() info.add_text("TXT", "VALUE") @@ -338,7 +338,7 @@ class TestFilePng(PillowTestCase): def test_trns_p(self): # Check writing a transparency of 0, issue #528 - im = lena('P') + im = hopper('P') im.info['transparency'] = 0 f = self.tempfile("temp.png") @@ -360,7 +360,7 @@ class TestFilePng(PillowTestCase): def test_roundtrip_icc_profile(self): # check that we can roundtrip the icc profile - im = lena('RGB') + im = hopper('RGB') jpeg_image = Image.open('Tests/images/flower2.jpg') expected_icc = jpeg_image.info['icc_profile'] diff --git a/Tests/test_file_sgi.py b/Tests/test_file_sgi.py index 84b184b63..d49086c51 100644 --- a/Tests/test_file_sgi.py +++ b/Tests/test_file_sgi.py @@ -8,8 +8,8 @@ class TestFileSgi(PillowTestCase): def test_rgb(self): # Arrange # Created with ImageMagick then renamed: - # convert lena.ppm lena.sgi - test_file = "Tests/images/lena.rgb" + # convert hopper.ppm hopper.sgi + test_file = "Tests/images/hopper.rgb" # Act / Assert self.assertRaises(ValueError, lambda: Image.open(test_file)) @@ -17,8 +17,8 @@ class TestFileSgi(PillowTestCase): def test_l(self): # Arrange # Created with ImageMagick then renamed: - # convert lena.ppm -monochrome lena.sgi - test_file = "Tests/images/lena.bw" + # convert hopper.ppm -monochrome hopper.sgi + test_file = "Tests/images/hopper.bw" # Act / Assert self.assertRaises(ValueError, lambda: Image.open(test_file)) diff --git a/Tests/test_file_spider.py b/Tests/test_file_spider.py index 65e4d2782..7bfedad1a 100644 --- a/Tests/test_file_spider.py +++ b/Tests/test_file_spider.py @@ -1,9 +1,9 @@ -from helper import unittest, PillowTestCase, lena +from helper import unittest, PillowTestCase, hopper from PIL import Image from PIL import SpiderImagePlugin -TEST_FILE = "Tests/images/lena.spider" +TEST_FILE = "Tests/images/hopper.spider" class TestImageSpider(PillowTestCase): @@ -18,7 +18,7 @@ class TestImageSpider(PillowTestCase): def test_save(self): # Arrange temp = self.tempfile('temp.spider') - im = lena() + im = hopper() # Act im.save(temp, "SPIDER") @@ -44,7 +44,7 @@ class TestImageSpider(PillowTestCase): def test_loadImageSeries(self): # Arrange - not_spider_file = "Tests/images/lena.ppm" + not_spider_file = "Tests/images/hopper.ppm" file_list = [TEST_FILE, not_spider_file, "path/not_found.ext"] # Act diff --git a/Tests/test_file_sun.py b/Tests/test_file_sun.py index c52564f91..332104062 100644 --- a/Tests/test_file_sun.py +++ b/Tests/test_file_sun.py @@ -7,8 +7,8 @@ class TestFileSun(PillowTestCase): def test_sanity(self): # Arrange - # Created with ImageMagick: convert lena.ppm lena.ras - test_file = "Tests/images/lena.ras" + # Created with ImageMagick: convert hopper.jpg hopper.ras + test_file = "Tests/images/hopper.ras" # Act im = Image.open(test_file) diff --git a/Tests/test_file_tar.py b/Tests/test_file_tar.py index 7010973ce..958b2f4df 100644 --- a/Tests/test_file_tar.py +++ b/Tests/test_file_tar.py @@ -4,8 +4,8 @@ from PIL import Image, TarIO codecs = dir(Image.core) -# sample ppm stream -tarfile = "Tests/images/lena.tar" +# Sample tar archive +TEST_TAR_FILE = "Tests/images/hopper.tar" class TestFileTar(PillowTestCase): @@ -16,7 +16,7 @@ class TestFileTar(PillowTestCase): def test_sanity(self): if "zip_decoder" in codecs: - tar = TarIO.TarIO(tarfile, 'lena.png') + tar = TarIO.TarIO(TEST_TAR_FILE, 'hopper.png') im = Image.open(tar) im.load() self.assertEqual(im.mode, "RGB") @@ -24,7 +24,7 @@ class TestFileTar(PillowTestCase): self.assertEqual(im.format, "PNG") if "jpeg_decoder" in codecs: - tar = TarIO.TarIO(tarfile, 'lena.jpg') + tar = TarIO.TarIO(TEST_TAR_FILE, 'hopper.jpg') im = Image.open(tar) im.load() self.assertEqual(im.mode, "RGB") diff --git a/Tests/test_image.py b/Tests/test_image.py index 46669db4b..26e45b10a 100644 --- a/Tests/test_image.py +++ b/Tests/test_image.py @@ -1,4 +1,4 @@ -from helper import unittest, PillowTestCase, lena +from helper import unittest, PillowTestCase, hopper from PIL import Image import sys @@ -58,7 +58,7 @@ class TestImage(PillowTestCase): def test_expand_x(self): # Arrange - im = lena() + im = hopper() orig_size = im.size xmargin = 5 @@ -71,7 +71,7 @@ class TestImage(PillowTestCase): def test_expand_xy(self): # Arrange - im = lena() + im = hopper() orig_size = im.size xmargin = 5 ymargin = 3 @@ -85,7 +85,7 @@ class TestImage(PillowTestCase): def test_getbands(self): # Arrange - im = lena() + im = hopper() # Act bands = im.getbands() @@ -95,7 +95,7 @@ class TestImage(PillowTestCase): def test_getbbox(self): # Arrange - im = lena() + im = hopper() # Act bbox = im.getbbox() @@ -185,7 +185,7 @@ class TestImage(PillowTestCase): def test_effect_spread(self): # Arrange - im = lena() + im = hopper() distance = 10 # Act @@ -194,7 +194,7 @@ class TestImage(PillowTestCase): # Assert self.assertEqual(im.size, (128, 128)) im3 = Image.open('Tests/images/effect_spread.png') - self.assert_image_similar(im2, im3, 80) + self.assert_image_similar(im2, im3, 110) if __name__ == '__main__': unittest.main() diff --git a/Tests/test_image_load.py b/Tests/test_image_load.py index 786cd6ad8..b1fc73182 100644 --- a/Tests/test_image_load.py +++ b/Tests/test_image_load.py @@ -1,4 +1,4 @@ -from helper import unittest, PillowTestCase, lena +from helper import unittest, PillowTestCase, hopper from PIL import Image @@ -9,21 +9,21 @@ class TestImageLoad(PillowTestCase): def test_sanity(self): - im = lena() + im = hopper() pix = im.load() - self.assertEqual(pix[0, 0], (223, 162, 133)) + self.assertEqual(pix[0, 0], (20, 20, 70)) def test_close(self): - im = Image.open("Tests/images/lena.gif") + im = Image.open("Tests/images/hopper.gif") im.close() self.assertRaises(ValueError, lambda: im.load()) self.assertRaises(ValueError, lambda: im.getpixel((0, 0))) def test_contextmanager(self): fn = None - with Image.open("Tests/images/lena.gif") as im: + with Image.open("Tests/images/hopper.gif") as im: fn = im.fp.fileno() os.fstat(fn) diff --git a/Tests/test_shell_injection.py b/Tests/test_shell_injection.py index ef80bfc98..d6d08c2d4 100644 --- a/Tests/test_shell_injection.py +++ b/Tests/test_shell_injection.py @@ -6,8 +6,8 @@ import shutil from PIL import Image, JpegImagePlugin, GifImagePlugin -test_jpg = "Tests/images/lena.jpg" -test_gif = "Tests/images/lena.gif" +TEST_JPG = "Tests/images/hopper.jpg" +TEST_GIF = "Tests/images/hopper.gif" test_filenames = ( "temp_';", @@ -31,24 +31,24 @@ class TestShellInjection(PillowTestCase): def test_load_djpeg_filename(self): for filename in test_filenames: src_file = self.tempfile(filename) - shutil.copy(test_jpg, src_file) + shutil.copy(TEST_JPG, src_file) im = Image.open(src_file) im.load_djpeg() @unittest.skipUnless(cjpeg_available(), "cjpeg not available") def test_save_cjpeg_filename(self): - im = Image.open(test_jpg) + im = Image.open(TEST_JPG) self.assert_save_filename_check(im, JpegImagePlugin._save_cjpeg) @unittest.skipUnless(netpbm_available(), "netpbm not available") def test_save_netpbm_filename_bmp_mode(self): - im = Image.open(test_gif).convert("RGB") + im = Image.open(TEST_GIF).convert("RGB") self.assert_save_filename_check(im, GifImagePlugin._save_netpbm) @unittest.skipUnless(netpbm_available(), "netpbm not available") def test_save_netpbm_filename_l_mode(self): - im = Image.open(test_gif).convert("L") + im = Image.open(TEST_GIF).convert("L") self.assert_save_filename_check(im, GifImagePlugin._save_netpbm) diff --git a/selftest.py b/selftest.py index 29af34ad2..b13dfec28 100644 --- a/selftest.py +++ b/selftest.py @@ -49,13 +49,13 @@ def testimage(): Or open existing files: - >>> im = Image.open(os.path.join(ROOT, "Tests/images/lena.gif")) + >>> im = Image.open(os.path.join(ROOT, "Tests/images/hopper.gif")) >>> _info(im) ('GIF', 'P', (128, 128)) - >>> _info(Image.open(os.path.join(ROOT, "Tests/images/lena.ppm"))) + >>> _info(Image.open(os.path.join(ROOT, "Tests/images/hopper.ppm"))) ('PPM', 'RGB', (128, 128)) >>> try: - ... _info(Image.open(os.path.join(ROOT, "Tests/images/lena.jpg"))) + ... _info(Image.open(os.path.join(ROOT, "Tests/images/hopper.jpg"))) ... except IOError as v: ... print(v) ('JPEG', 'RGB', (128, 128)) @@ -63,7 +63,7 @@ def testimage(): PIL doesn't actually load the image data until it's needed, or you call the "load" method: - >>> im = Image.open(os.path.join(ROOT, "Tests/images/lena.ppm")) + >>> im = Image.open(os.path.join(ROOT, "Tests/images/hopper.ppm")) >>> print(im.im) # internal image attribute None >>> a = im.load() @@ -73,7 +73,7 @@ def testimage(): You can apply many different operations on images. Most operations return a new image: - >>> im = Image.open(os.path.join(ROOT, "Tests/images/lena.ppm")) + >>> im = Image.open(os.path.join(ROOT, "Tests/images/hopper.ppm")) >>> _info(im.convert("L")) (None, 'L', (128, 128)) >>> _info(im.copy()) @@ -89,9 +89,9 @@ def testimage(): >>> len(im.getdata()) 16384 >>> im.getextrema() - ((61, 255), (26, 234), (44, 223)) + ((0, 255), (0, 255), (0, 255)) >>> im.getpixel((0, 0)) - (223, 162, 133) + (20, 20, 70) >>> len(im.getprojection()) 2 >>> len(im.histogram())