From a06b59bd52f8bbcd311b6a96d6d6ab4a1229331f Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 3 Jul 2015 15:03:25 +1000 Subject: [PATCH 1/2] Added various tests --- Tests/check_imaging_leaks.py | 2 +- Tests/test_cffi.py | 12 ++++++++++++ Tests/test_file_bmp.py | 6 +++++- Tests/test_file_bufrstub.py | 15 +++++++++++++++ Tests/test_file_cur.py | 3 +++ Tests/test_file_dcx.py | 4 ++++ Tests/test_file_eps.py | 3 +++ Tests/test_file_fitsstub.py | 15 +++++++++++++++ Tests/test_file_fli.py | 5 ++++- Tests/test_file_fpx.py | 15 +++++++++++++++ Tests/test_file_gbr.py | 15 +++++++++++++++ Tests/test_file_gif.py | 3 +++ Tests/test_file_gribstub.py | 15 +++++++++++++++ Tests/test_file_hdf5stub.py | 15 +++++++++++++++ Tests/test_file_ico.py | 6 +++++- Tests/test_file_im.py | 6 +++++- Tests/test_file_jpeg2k.py | 5 ++++- Tests/test_file_mcidas.py | 15 +++++++++++++++ Tests/test_file_mic.py | 15 +++++++++++++++ Tests/test_file_msp.py | 5 ++++- Tests/test_file_pcx.py | 5 ++++- Tests/test_file_pdf.py | 6 ++++++ Tests/test_file_png.py | 3 +++ Tests/test_file_psd.py | 5 ++++- Tests/test_file_sgi.py | 5 ++++- Tests/test_file_sun.py | 4 +++- Tests/test_file_tga.py | 19 +++++++++++++++++++ Tests/test_file_webp.py | 5 +++++ Tests/test_file_xpm.py | 5 ++++- Tests/test_font_bdf.py | 4 ++++ Tests/test_font_pcf.py | 4 ++++ Tests/test_image_filter.py | 6 ++++++ Tests/test_image_mode.py | 2 ++ Tests/test_imagecolor.py | 2 ++ Tests/test_imagedraw.py | 5 +++++ Tests/test_imagefile.py | 3 +++ Tests/test_imagesequence.py | 2 ++ Tests/test_olefileio.py | 27 +++++++++++---------------- 38 files changed, 264 insertions(+), 28 deletions(-) create mode 100644 Tests/test_file_bufrstub.py create mode 100644 Tests/test_file_fitsstub.py create mode 100644 Tests/test_file_fpx.py create mode 100644 Tests/test_file_gbr.py create mode 100644 Tests/test_file_gribstub.py create mode 100644 Tests/test_file_hdf5stub.py create mode 100644 Tests/test_file_mcidas.py create mode 100644 Tests/test_file_mic.py diff --git a/Tests/check_imaging_leaks.py b/Tests/check_imaging_leaks.py index c6d99b8d1..e79429f8f 100644 --- a/Tests/check_imaging_leaks.py +++ b/Tests/check_imaging_leaks.py @@ -3,7 +3,7 @@ from __future__ import division from helper import unittest, PillowTestCase import sys -from PIL import Image, ImageFilter +from PIL import Image min_iterations = 100 max_iterations = 10000 diff --git a/Tests/test_cffi.py b/Tests/test_cffi.py index cea0db093..361b59a39 100644 --- a/Tests/test_cffi.py +++ b/Tests/test_cffi.py @@ -61,6 +61,10 @@ class TestCffi(PillowTestCase): for y in range(0, h, 10): self.assertEqual(access[(x, y)], caccess[(x, y)]) + # Access an out-of-range pixel + self.assertRaises(ValueError, + lambda: access[(access.xsize+1, access.ysize+1)]) + def test_get_vs_c(self): rgb = hopper('RGB') rgb.load() @@ -103,6 +107,14 @@ class TestCffi(PillowTestCase): access[(x, y)] = color self.assertEqual(color, caccess[(x, y)]) + # Attempt to set the value on a read-only image + access = PyAccess.new(im, True) + try: + access[(0, 0)] = color + except ValueError: + return + self.fail("Putpixel did not fail on a read-only image") + def test_set_vs_c(self): rgb = hopper('RGB') rgb.load() diff --git a/Tests/test_file_bmp.py b/Tests/test_file_bmp.py index fd0f29470..15d470c90 100644 --- a/Tests/test_file_bmp.py +++ b/Tests/test_file_bmp.py @@ -1,6 +1,6 @@ from helper import unittest, PillowTestCase, hopper -from PIL import Image +from PIL import Image, BmpImagePlugin import io @@ -25,6 +25,10 @@ class TestFileBmp(PillowTestCase): self.roundtrip(hopper("P")) self.roundtrip(hopper("RGB")) + def test_invalid_file(self): + with open("Tests/images/flower.jpg", "rb") as fp: + self.assertRaises(SyntaxError, lambda: BmpImagePlugin.BmpImageFile(fp)) + def test_save_to_bytes(self): output = io.BytesIO() im = hopper() diff --git a/Tests/test_file_bufrstub.py b/Tests/test_file_bufrstub.py new file mode 100644 index 000000000..8cf496533 --- /dev/null +++ b/Tests/test_file_bufrstub.py @@ -0,0 +1,15 @@ +from helper import unittest, PillowTestCase + +from PIL import BufrStubImagePlugin + + +class TestFileBufrStub(PillowTestCase): + + def test_invalid_file(self): + self.assertRaises(SyntaxError, lambda: BufrStubImagePlugin.BufrStubImageFile("Tests/images/flower.jpg")) + + +if __name__ == '__main__': + unittest.main() + +# End of file diff --git a/Tests/test_file_cur.py b/Tests/test_file_cur.py index 07bf3a750..d9acb5f78 100644 --- a/Tests/test_file_cur.py +++ b/Tests/test_file_cur.py @@ -20,6 +20,9 @@ class TestFileCur(PillowTestCase): self.assertEqual(im.getpixel((11, 1)), (253, 254, 254, 1)) self.assertEqual(im.getpixel((16, 16)), (84, 87, 86, 255)) + def test_invalid_file(self): + self.assertRaises(SyntaxError, lambda: CurImagePlugin.CurImageFile("Tests/images/flower.jpg")) + if __name__ == '__main__': unittest.main() diff --git a/Tests/test_file_dcx.py b/Tests/test_file_dcx.py index 7f804eb89..62760fd0c 100644 --- a/Tests/test_file_dcx.py +++ b/Tests/test_file_dcx.py @@ -20,6 +20,10 @@ class TestFileDcx(PillowTestCase): orig = hopper() self.assert_image_equal(im, orig) + def test_invalid_file(self): + with open("Tests/images/flower.jpg", "rb") as fp: + self.assertRaises(SyntaxError, lambda: DcxImagePlugin.DcxImageFile(fp)) + def test_tell(self): # Arrange im = Image.open(TEST_FILE) diff --git a/Tests/test_file_eps.py b/Tests/test_file_eps.py index 08d2d875a..931b788a3 100644 --- a/Tests/test_file_eps.py +++ b/Tests/test_file_eps.py @@ -51,6 +51,9 @@ class TestFileEps(PillowTestCase): self.assertEqual(image2_scale2.size, (720, 504)) self.assertEqual(image2_scale2.format, "EPS") + def test_invalid_file(self): + self.assertRaises(SyntaxError, lambda: EpsImagePlugin.EpsImageFile("Tests/images/flower.jpg")) + def test_file_object(self): # issue 479 image1 = Image.open(file1) diff --git a/Tests/test_file_fitsstub.py b/Tests/test_file_fitsstub.py new file mode 100644 index 000000000..189d002d6 --- /dev/null +++ b/Tests/test_file_fitsstub.py @@ -0,0 +1,15 @@ +from helper import unittest, PillowTestCase + +from PIL import FitsStubImagePlugin + + +class TestFileFitsStub(PillowTestCase): + + def test_invalid_file(self): + self.assertRaises(SyntaxError, lambda: FitsStubImagePlugin.FITSStubImageFile("Tests/images/flower.jpg")) + + +if __name__ == '__main__': + unittest.main() + +# End of file diff --git a/Tests/test_file_fli.py b/Tests/test_file_fli.py index a0ea6af04..daaebdc69 100644 --- a/Tests/test_file_fli.py +++ b/Tests/test_file_fli.py @@ -1,6 +1,6 @@ from helper import unittest, PillowTestCase -from PIL import Image +from PIL import Image, FliImagePlugin # sample ppm stream # created as an export of a palette image from Gimp2.6 @@ -18,6 +18,9 @@ class TestFileFli(PillowTestCase): self.assertEqual(im.size, (128, 128)) self.assertEqual(im.format, "FLI") + def test_invalid_file(self): + self.assertRaises(SyntaxError, lambda: FliImagePlugin.FliImageFile("Tests/images/flower.jpg")) + def test_n_frames(self): im = Image.open(test_file) self.assertEqual(im.n_frames, 1) diff --git a/Tests/test_file_fpx.py b/Tests/test_file_fpx.py new file mode 100644 index 000000000..4b3756fb9 --- /dev/null +++ b/Tests/test_file_fpx.py @@ -0,0 +1,15 @@ +from helper import unittest, PillowTestCase + +from PIL import FpxImagePlugin + + +class TestFileFpx(PillowTestCase): + + def test_invalid_file(self): + self.assertRaises(SyntaxError, lambda: FpxImagePlugin.FpxImageFile("Tests/images/flower.jpg")) + + +if __name__ == '__main__': + unittest.main() + +# End of file diff --git a/Tests/test_file_gbr.py b/Tests/test_file_gbr.py new file mode 100644 index 000000000..ecec0189b --- /dev/null +++ b/Tests/test_file_gbr.py @@ -0,0 +1,15 @@ +from helper import unittest, PillowTestCase + +from PIL import GbrImagePlugin + + +class TestFileGbr(PillowTestCase): + + def test_invalid_file(self): + self.assertRaises(SyntaxError, lambda: GbrImagePlugin.GbrImageFile("Tests/images/flower.jpg")) + + +if __name__ == '__main__': + unittest.main() + +# End of file diff --git a/Tests/test_file_gif.py b/Tests/test_file_gif.py index 666e1f16d..33e04cb5e 100644 --- a/Tests/test_file_gif.py +++ b/Tests/test_file_gif.py @@ -25,6 +25,9 @@ class TestFileGif(PillowTestCase): self.assertEqual(im.size, (128, 128)) self.assertEqual(im.format, "GIF") + def test_invalid_file(self): + self.assertRaises(SyntaxError, lambda: GifImagePlugin.GifImageFile("Tests/images/flower.jpg")) + def test_optimize(self): from io import BytesIO diff --git a/Tests/test_file_gribstub.py b/Tests/test_file_gribstub.py new file mode 100644 index 000000000..84bf8a5be --- /dev/null +++ b/Tests/test_file_gribstub.py @@ -0,0 +1,15 @@ +from helper import unittest, PillowTestCase + +from PIL import GribStubImagePlugin + + +class TestFileGribStub(PillowTestCase): + + def test_invalid_file(self): + self.assertRaises(SyntaxError, lambda: GribStubImagePlugin.GribStubImageFile("Tests/images/flower.jpg")) + + +if __name__ == '__main__': + unittest.main() + +# End of file diff --git a/Tests/test_file_hdf5stub.py b/Tests/test_file_hdf5stub.py new file mode 100644 index 000000000..2b7e208d2 --- /dev/null +++ b/Tests/test_file_hdf5stub.py @@ -0,0 +1,15 @@ +from helper import unittest, PillowTestCase + +from PIL import Hdf5StubImagePlugin + + +class TestFileHdf5Stub(PillowTestCase): + + def test_invalid_file(self): + self.assertRaises(SyntaxError, lambda: Hdf5StubImagePlugin.HDF5StubImageFile("Tests/images/flower.jpg")) + + +if __name__ == '__main__': + unittest.main() + +# End of file diff --git a/Tests/test_file_ico.py b/Tests/test_file_ico.py index f7b52b124..d2adf8dcc 100644 --- a/Tests/test_file_ico.py +++ b/Tests/test_file_ico.py @@ -1,7 +1,7 @@ from helper import unittest, PillowTestCase, hopper import io -from PIL import Image +from PIL import Image, IcoImagePlugin # sample ppm stream TEST_ICO_FILE = "Tests/images/hopper.ico" @@ -17,6 +17,10 @@ class TestFileIco(PillowTestCase): self.assertEqual(im.size, (16, 16)) self.assertEqual(im.format, "ICO") + def test_invalid_file(self): + with open("Tests/images/flower.jpg", "rb") as fp: + self.assertRaises(SyntaxError, lambda: IcoImagePlugin.IcoImageFile(fp)) + def test_save_to_bytes(self): output = io.BytesIO() im = hopper() diff --git a/Tests/test_file_im.py b/Tests/test_file_im.py index 602db4b1d..01b6fd561 100644 --- a/Tests/test_file_im.py +++ b/Tests/test_file_im.py @@ -1,6 +1,6 @@ from helper import unittest, PillowTestCase, hopper -from PIL import Image +from PIL import Image, ImImagePlugin # sample im TEST_IM = "Tests/images/hopper.im" @@ -40,6 +40,10 @@ class TestFileIm(PillowTestCase): self.assert_image_equal(reread, im) + def test_invalid_file(self): + self.assertRaises(SyntaxError, lambda: ImImagePlugin.ImImageFile("Tests/images/flower.jpg")) + + if __name__ == '__main__': unittest.main() diff --git a/Tests/test_file_jpeg2k.py b/Tests/test_file_jpeg2k.py index 9768a881d..a97a7e9da 100644 --- a/Tests/test_file_jpeg2k.py +++ b/Tests/test_file_jpeg2k.py @@ -1,6 +1,6 @@ from helper import unittest, PillowTestCase -from PIL import Image +from PIL import Image, Jpeg2KImagePlugin from io import BytesIO codecs = dir(Image.core) @@ -39,6 +39,9 @@ class TestFileJpeg2k(PillowTestCase): self.assertEqual(im.size, (640, 480)) self.assertEqual(im.format, 'JPEG2000') + def test_invalid_file(self): + self.assertRaises(SyntaxError, lambda: Jpeg2KImagePlugin.Jpeg2KImageFile("Tests/images/flower.jpg")) + def test_bytesio(self): with open('Tests/images/test-card-lossless.jp2', 'rb') as f: data = BytesIO(f.read()) diff --git a/Tests/test_file_mcidas.py b/Tests/test_file_mcidas.py new file mode 100644 index 000000000..44130746a --- /dev/null +++ b/Tests/test_file_mcidas.py @@ -0,0 +1,15 @@ +from helper import unittest, PillowTestCase + +from PIL import McIdasImagePlugin + + +class TestFileMcIdas(PillowTestCase): + + def test_invalid_file(self): + self.assertRaises(SyntaxError, lambda: McIdasImagePlugin.McIdasImageFile("Tests/images/flower.jpg")) + + +if __name__ == '__main__': + unittest.main() + +# End of file diff --git a/Tests/test_file_mic.py b/Tests/test_file_mic.py new file mode 100644 index 000000000..de106bc14 --- /dev/null +++ b/Tests/test_file_mic.py @@ -0,0 +1,15 @@ +from helper import unittest, PillowTestCase + +from PIL import MicImagePlugin + + +class TestFileMic(PillowTestCase): + + def test_invalid_file(self): + self.assertRaises(SyntaxError, lambda: MicImagePlugin.MicImageFile("Tests/images/flower.jpg")) + + +if __name__ == '__main__': + unittest.main() + +# End of file diff --git a/Tests/test_file_msp.py b/Tests/test_file_msp.py index f4b1af75e..94fcfd895 100644 --- a/Tests/test_file_msp.py +++ b/Tests/test_file_msp.py @@ -1,6 +1,6 @@ from helper import unittest, PillowTestCase, hopper -from PIL import Image +from PIL import Image, MspImagePlugin TEST_FILE = "Tests/images/hopper.msp" @@ -18,6 +18,9 @@ class TestFileMsp(PillowTestCase): self.assertEqual(im.size, (128, 128)) self.assertEqual(im.format, "MSP") + def test_invalid_file(self): + self.assertRaises(SyntaxError, lambda: MspImagePlugin.MspImageFile("Tests/images/flower.jpg")) + def test_open(self): # Arrange # Act diff --git a/Tests/test_file_pcx.py b/Tests/test_file_pcx.py index 10d17d349..5a1a2e9a6 100644 --- a/Tests/test_file_pcx.py +++ b/Tests/test_file_pcx.py @@ -1,6 +1,6 @@ from helper import unittest, PillowTestCase, hopper -from PIL import Image +from PIL import Image, PcxImagePlugin class TestFilePcx(PillowTestCase): @@ -19,6 +19,9 @@ class TestFilePcx(PillowTestCase): for mode in ('1', 'L', 'P', 'RGB'): self._roundtrip(hopper(mode)) + def test_invalid_file(self): + self.assertRaises(SyntaxError, lambda: PcxImagePlugin.PcxImageFile("Tests/images/flower.jpg")) + def test_odd(self): # see issue #523, odd sized images should have a stride that's even. # not that imagemagick or gimp write pcx that way. diff --git a/Tests/test_file_pdf.py b/Tests/test_file_pdf.py index 9424bc09d..8dad9822c 100644 --- a/Tests/test_file_pdf.py +++ b/Tests/test_file_pdf.py @@ -52,6 +52,12 @@ class TestFilePdf(PillowTestCase): # Act / Assert self.helper_save_as_pdf(mode) + def test_unsupported_mode(self): + im = hopper("LA") + outfile = self.tempfile("temp_LA.pdf") + + self.assertRaises(ValueError, lambda: im.save(outfile)) + if __name__ == '__main__': unittest.main() diff --git a/Tests/test_file_png.py b/Tests/test_file_png.py index f438e24cc..dfd83baa6 100644 --- a/Tests/test_file_png.py +++ b/Tests/test_file_png.py @@ -81,6 +81,9 @@ class TestFilePng(PillowTestCase): hopper("I").save(test_file) im = Image.open(test_file) + def test_invalid_file(self): + self.assertRaises(SyntaxError, lambda: PngImagePlugin.PngImageFile("Tests/images/flower.jpg")) + def test_broken(self): # Check reading of totally broken files. In this case, the test # file was checked into Subversion as a text file. diff --git a/Tests/test_file_psd.py b/Tests/test_file_psd.py index 6492787ec..af1780d9d 100644 --- a/Tests/test_file_psd.py +++ b/Tests/test_file_psd.py @@ -1,6 +1,6 @@ from helper import unittest, PillowTestCase -from PIL import Image +from PIL import Image, PsdImagePlugin # sample ppm stream test_file = "Tests/images/hopper.psd" @@ -16,6 +16,9 @@ class TestImagePsd(PillowTestCase): self.assertEqual(im.size, (128, 128)) self.assertEqual(im.format, "PSD") + def test_invalid_file(self): + self.assertRaises(SyntaxError, lambda: PsdImagePlugin.PsdImageFile("Tests/images/flower.jpg")) + def test_n_frames(self): im = Image.open("Tests/images/hopper_merged.psd") self.assertEqual(im.n_frames, 1) diff --git a/Tests/test_file_sgi.py b/Tests/test_file_sgi.py index d49086c51..9842b3991 100644 --- a/Tests/test_file_sgi.py +++ b/Tests/test_file_sgi.py @@ -1,6 +1,6 @@ from helper import unittest, PillowTestCase -from PIL import Image +from PIL import Image, SgiImagePlugin class TestFileSgi(PillowTestCase): @@ -32,6 +32,9 @@ class TestFileSgi(PillowTestCase): # Act / Assert self.assertRaises(ValueError, lambda: Image.open(test_file)) + def test_invalid_file(self): + self.assertRaises(ValueError, lambda: SgiImagePlugin.SgiImageFile("Tests/images/flower.jpg")) + if __name__ == '__main__': unittest.main() diff --git a/Tests/test_file_sun.py b/Tests/test_file_sun.py index 332104062..e476ebf13 100644 --- a/Tests/test_file_sun.py +++ b/Tests/test_file_sun.py @@ -1,6 +1,6 @@ from helper import unittest, PillowTestCase -from PIL import Image +from PIL import Image, SunImagePlugin class TestFileSun(PillowTestCase): @@ -16,6 +16,8 @@ class TestFileSun(PillowTestCase): # Assert self.assertEqual(im.size, (128, 128)) + self.assertRaises(SyntaxError, lambda: SunImagePlugin.SunImageFile("Tests/images/flower.jpg")) + if __name__ == '__main__': unittest.main() diff --git a/Tests/test_file_tga.py b/Tests/test_file_tga.py index ea94dee64..cccd9bf96 100644 --- a/Tests/test_file_tga.py +++ b/Tests/test_file_tga.py @@ -15,6 +15,25 @@ class TestFileTga(PillowTestCase): # Assert self.assertEqual(im.size, (100, 100)) + def test_save(self): + test_file = "Tests/images/tga_id_field.tga" + im = Image.open(test_file) + + test_file = self.tempfile("temp.tga") + + # Save + im.save(test_file) + test_im = Image.open(test_file) + self.assertEqual(test_im.size, (100, 100)) + + # RGBA save + im.convert("RGBA").save(test_file) + test_im = Image.open(test_file) + self.assertEqual(test_im.size, (100, 100)) + + # Unsupported mode save + self.assertRaises(IOError, lambda: im.convert("LA").save(test_file)) + if __name__ == '__main__': unittest.main() diff --git a/Tests/test_file_webp.py b/Tests/test_file_webp.py index 8c8313dd9..d1c8e580e 100644 --- a/Tests/test_file_webp.py +++ b/Tests/test_file_webp.py @@ -72,6 +72,11 @@ class TestFileWebp(PillowTestCase): target = hopper("RGB") self.assert_image_similar(image, target, 12) + def test_write_unsupported_mode(self): + temp_file = self.tempfile("temp.webp") + + self.assertRaises(IOError, lambda: hopper("L").save(temp_file)) + if __name__ == '__main__': unittest.main() diff --git a/Tests/test_file_xpm.py b/Tests/test_file_xpm.py index 6a6817048..3e3c35e18 100644 --- a/Tests/test_file_xpm.py +++ b/Tests/test_file_xpm.py @@ -1,6 +1,6 @@ from helper import unittest, PillowTestCase, hopper -from PIL import Image +from PIL import Image, XpmImagePlugin # sample ppm stream TEST_FILE = "Tests/images/hopper.xpm" @@ -18,6 +18,9 @@ class TestFileXpm(PillowTestCase): # large error due to quantization->44 colors. self.assert_image_similar(im.convert('RGB'), hopper('RGB'), 60) + def test_invalid_file(self): + self.assertRaises(SyntaxError, lambda: XpmImagePlugin.XpmImageFile("Tests/images/flower.jpg")) + def test_load_read(self): # Arrange im = Image.open(TEST_FILE) diff --git a/Tests/test_font_bdf.py b/Tests/test_font_bdf.py index b844f1228..4d88ae46f 100644 --- a/Tests/test_font_bdf.py +++ b/Tests/test_font_bdf.py @@ -15,6 +15,10 @@ class TestFontBdf(PillowTestCase): self.assertIsInstance(font, FontFile.FontFile) self.assertEqual(len([_f for _f in font.glyph if _f]), 190) + def test_invalid_file(self): + with open("Tests/images/flower.jpg", "rb") as fp: + self.assertRaises(SyntaxError, lambda: BdfFontFile.BdfFontFile(fp)) + if __name__ == '__main__': unittest.main() diff --git a/Tests/test_font_pcf.py b/Tests/test_font_pcf.py index 3cc6afa64..f6dd9265e 100644 --- a/Tests/test_font_pcf.py +++ b/Tests/test_font_pcf.py @@ -30,6 +30,10 @@ class TestFontPcf(PillowTestCase): def test_sanity(self): self.save_font() + def test_invalid_file(self): + with open("Tests/images/flower.jpg", "rb") as fp: + self.assertRaises(SyntaxError, lambda: PcfFontFile.PcfFontFile(fp)) + def xtest_draw(self): tempname = self.save_font() diff --git a/Tests/test_image_filter.py b/Tests/test_image_filter.py index 6a694b3ca..a62431dd9 100644 --- a/Tests/test_image_filter.py +++ b/Tests/test_image_filter.py @@ -88,6 +88,12 @@ class TestImageFilter(PillowTestCase): self.assertEqual(rankfilter("I"), (0, 4, 8)) self.assertEqual(rankfilter("F"), (0.0, 4.0, 8.0)) + def test_rankfilter_properties(self): + rankfilter = ImageFilter.RankFilter(1,2) + + self.assertEqual(rankfilter.size, 1) + self.assertEqual(rankfilter.rank, 2) + if __name__ == '__main__': unittest.main() diff --git a/Tests/test_image_mode.py b/Tests/test_image_mode.py index 6441c7d1b..c20db50aa 100644 --- a/Tests/test_image_mode.py +++ b/Tests/test_image_mode.py @@ -21,12 +21,14 @@ class TestImageMode(PillowTestCase): m = ImageMode.getmode("1") self.assertEqual(m.mode, "1") + self.assertEqual(str(m), "1") self.assertEqual(m.bands, ("1",)) self.assertEqual(m.basemode, "L") self.assertEqual(m.basetype, "L") m = ImageMode.getmode("RGB") self.assertEqual(m.mode, "RGB") + self.assertEqual(str(m), "RGB") self.assertEqual(m.bands, ("R", "G", "B")) self.assertEqual(m.basemode, "RGB") self.assertEqual(m.basetype, "L") diff --git a/Tests/test_imagecolor.py b/Tests/test_imagecolor.py index 5d8944852..d55e73b9c 100644 --- a/Tests/test_imagecolor.py +++ b/Tests/test_imagecolor.py @@ -18,6 +18,8 @@ class TestImageColor(PillowTestCase): (255, 0, 0, 0), ImageColor.getrgb("rgba(255, 0, 0, 0)")) self.assertEqual((255, 0, 0), ImageColor.getrgb("red")) + self.assertRaises(ValueError, lambda: ImageColor.getrgb("invalid color")) + # look for rounding errors (based on code by Tim Hatch) def test_rounding_errors(self): diff --git a/Tests/test_imagedraw.py b/Tests/test_imagedraw.py index ffefa6504..2e746438d 100644 --- a/Tests/test_imagedraw.py +++ b/Tests/test_imagedraw.py @@ -52,6 +52,11 @@ class TestImageDraw(PillowTestCase): self.assert_warning(DeprecationWarning, lambda: draw.setink(0)) self.assert_warning(DeprecationWarning, lambda: draw.setfill(0)) + def test_mode_mismatch(self): + im = hopper("RGB").copy() + + self.assertRaises(ValueError, lambda: ImageDraw.ImageDraw(im, mode="L")) + def helper_arc(self, bbox): # Arrange im = Image.new("RGB", (W, H)) diff --git a/Tests/test_imagefile.py b/Tests/test_imagefile.py index bc81575b6..fbd10d47b 100644 --- a/Tests/test_imagefile.py +++ b/Tests/test_imagefile.py @@ -93,6 +93,9 @@ class TestImageFile(PillowTestCase): self.assert_image_equal(im1, im2) + def test_raise_ioerror(self): + self.assertRaises(IOError, lambda: ImageFile.raise_ioerror(1)) + if __name__ == '__main__': unittest.main() diff --git a/Tests/test_imagesequence.py b/Tests/test_imagesequence.py index d2aa17df7..3bd6dc582 100644 --- a/Tests/test_imagesequence.py +++ b/Tests/test_imagesequence.py @@ -22,6 +22,8 @@ class TestImageSequence(PillowTestCase): self.assertEqual(index, 1) + self.assertRaises(AttributeError, lambda: ImageSequence.Iterator(0)) + def _test_multipage_tiff(self, dbg=False): im = Image.open('Tests/images/multipage.tiff') for index, frame in enumerate(ImageSequence.Iterator(im)): diff --git a/Tests/test_olefileio.py b/Tests/test_olefileio.py index 1cff273a1..d3842e977 100644 --- a/Tests/test_olefileio.py +++ b/Tests/test_olefileio.py @@ -7,25 +7,20 @@ import PIL.OleFileIO as OleFileIO class TestOleFileIo(PillowTestCase): - def test_isOleFile_false(self): - # Arrange - non_ole_file = "Tests/images/flower.jpg" - - # Act - is_ole = OleFileIO.isOleFile(non_ole_file) - - # Assert - self.assertFalse(is_ole) - - def test_isOleFile_true(self): - # Arrange + def test_isOleFile(self): ole_file = "Tests/images/test-ole-file.doc" - # Act - is_ole = OleFileIO.isOleFile(ole_file) + self.assertTrue(OleFileIO.isOleFile(ole_file)) + with open(ole_file, 'rb') as fp: + self.assertTrue(OleFileIO.isOleFile(fp)) + self.assertTrue(OleFileIO.isOleFile(fp.read())) - # Assert - self.assertTrue(is_ole) + non_ole_file = "Tests/images/flower.jpg" + + self.assertFalse(OleFileIO.isOleFile(non_ole_file)) + with open(non_ole_file, 'rb') as fp: + self.assertFalse(OleFileIO.isOleFile(fp)) + self.assertFalse(OleFileIO.isOleFile(fp.read())) def test_exists_worddocument(self): # Arrange From 309ab1fc3d167b38a463e6bd75438aba4dc3419e Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 3 Jul 2015 16:22:56 +1000 Subject: [PATCH 2/2] Various Flake8 fixes --- Tests/check_imaging_leaks.py | 3 ++- Tests/check_png_dos.py | 3 ++- Tests/test_cffi.py | 2 +- Tests/test_file_bmp.py | 3 ++- Tests/test_file_bufrstub.py | 6 +++++- Tests/test_file_cur.py | 5 ++++- Tests/test_file_dcx.py | 3 ++- Tests/test_file_eps.py | 9 +++++++-- Tests/test_file_fitsstub.py | 6 +++++- Tests/test_file_fli.py | 5 ++++- Tests/test_file_fpx.py | 5 ++++- Tests/test_file_gbr.py | 5 ++++- Tests/test_file_gif.py | 5 ++++- Tests/test_file_gribstub.py | 6 +++++- Tests/test_file_hdf5stub.py | 6 +++++- Tests/test_file_ico.py | 9 ++++++--- Tests/test_file_im.py | 5 ++++- Tests/test_file_jpeg.py | 17 ++++++++++------- Tests/test_file_jpeg2k.py | 6 +++++- Tests/test_file_mcidas.py | 6 +++++- Tests/test_file_mic.py | 5 ++++- Tests/test_file_msp.py | 5 ++++- Tests/test_file_pcx.py | 5 ++++- Tests/test_file_png.py | 5 ++++- Tests/test_file_psd.py | 5 ++++- Tests/test_file_sgi.py | 6 +++++- Tests/test_file_sun.py | 4 +++- Tests/test_file_tga.py | 2 +- Tests/test_file_tiff.py | 3 ++- Tests/test_file_webp_alpha.py | 3 ++- Tests/test_file_xpm.py | 5 ++++- Tests/test_image_filter.py | 2 +- Tests/test_imagecolor.py | 7 ++++--- Tests/test_imagedraw.py | 3 ++- Tests/test_imagefont_bitmap.py | 11 +++++++---- Tests/test_imageops_usm.py | 4 +++- Tests/test_imagewin.py | 3 ++- Tests/test_scipy.py | 4 ++-- 38 files changed, 144 insertions(+), 53 deletions(-) diff --git a/Tests/check_imaging_leaks.py b/Tests/check_imaging_leaks.py index e79429f8f..a31cd2180 100644 --- a/Tests/check_imaging_leaks.py +++ b/Tests/check_imaging_leaks.py @@ -31,7 +31,8 @@ class TestImagingLeaks(PillowTestCase): def test_leak_putdata(self): im = Image.new('RGB', (25, 25)) - self._test_leak(min_iterations, max_iterations, im.putdata, im.getdata()) + self._test_leak(min_iterations, max_iterations, + im.putdata, im.getdata()) def test_leak_getlist(self): im = Image.new('P', (25, 25)) diff --git a/Tests/check_png_dos.py b/Tests/check_png_dos.py index 762c9607a..c24eeb359 100644 --- a/Tests/check_png_dos.py +++ b/Tests/check_png_dos.py @@ -42,7 +42,8 @@ class TestPngDos(PillowTestCase): total_len = 0 for txt in im2.text.values(): total_len += len(txt) - self.assertLess(total_len, 64*1024*1024, "Total text chunks greater than 64M") + self.assertLess(total_len, 64*1024*1024, + "Total text chunks greater than 64M") if __name__ == '__main__': unittest.main() diff --git a/Tests/test_cffi.py b/Tests/test_cffi.py index 361b59a39..02d1ff7d3 100644 --- a/Tests/test_cffi.py +++ b/Tests/test_cffi.py @@ -74,7 +74,7 @@ class TestCffi(PillowTestCase): self._test_get_access(hopper('LA')) self._test_get_access(hopper('1')) self._test_get_access(hopper('P')) - # self._test_get_access(hopper('PA')) # PA -- how do I make a PA image? + # self._test_get_access(hopper('PA')) # PA -- how do I make a PA image? self._test_get_access(hopper('F')) im = Image.new('I;16', (10, 10), 40000) diff --git a/Tests/test_file_bmp.py b/Tests/test_file_bmp.py index 15d470c90..25f70139d 100644 --- a/Tests/test_file_bmp.py +++ b/Tests/test_file_bmp.py @@ -27,7 +27,8 @@ class TestFileBmp(PillowTestCase): def test_invalid_file(self): with open("Tests/images/flower.jpg", "rb") as fp: - self.assertRaises(SyntaxError, lambda: BmpImagePlugin.BmpImageFile(fp)) + self.assertRaises(SyntaxError, + lambda: BmpImagePlugin.BmpImageFile(fp)) def test_save_to_bytes(self): output = io.BytesIO() diff --git a/Tests/test_file_bufrstub.py b/Tests/test_file_bufrstub.py index 8cf496533..05266e9fd 100644 --- a/Tests/test_file_bufrstub.py +++ b/Tests/test_file_bufrstub.py @@ -6,7 +6,11 @@ from PIL import BufrStubImagePlugin class TestFileBufrStub(PillowTestCase): def test_invalid_file(self): - self.assertRaises(SyntaxError, lambda: BufrStubImagePlugin.BufrStubImageFile("Tests/images/flower.jpg")) + invalid_file = "Tests/images/flower.jpg" + + self.assertRaises(SyntaxError, + lambda: + BufrStubImagePlugin.BufrStubImageFile(invalid_file)) if __name__ == '__main__': diff --git a/Tests/test_file_cur.py b/Tests/test_file_cur.py index d9acb5f78..fa4242629 100644 --- a/Tests/test_file_cur.py +++ b/Tests/test_file_cur.py @@ -21,7 +21,10 @@ class TestFileCur(PillowTestCase): self.assertEqual(im.getpixel((16, 16)), (84, 87, 86, 255)) def test_invalid_file(self): - self.assertRaises(SyntaxError, lambda: CurImagePlugin.CurImageFile("Tests/images/flower.jpg")) + invalid_file = "Tests/images/flower.jpg" + + self.assertRaises(SyntaxError, + lambda: CurImagePlugin.CurImageFile(invalid_file)) if __name__ == '__main__': diff --git a/Tests/test_file_dcx.py b/Tests/test_file_dcx.py index 62760fd0c..2c0f90c1f 100644 --- a/Tests/test_file_dcx.py +++ b/Tests/test_file_dcx.py @@ -22,7 +22,8 @@ class TestFileDcx(PillowTestCase): def test_invalid_file(self): with open("Tests/images/flower.jpg", "rb") as fp: - self.assertRaises(SyntaxError, lambda: DcxImagePlugin.DcxImageFile(fp)) + self.assertRaises(SyntaxError, + lambda: DcxImagePlugin.DcxImageFile(fp)) def test_tell(self): # Arrange diff --git a/Tests/test_file_eps.py b/Tests/test_file_eps.py index 931b788a3..6e4c63e4f 100644 --- a/Tests/test_file_eps.py +++ b/Tests/test_file_eps.py @@ -52,7 +52,10 @@ class TestFileEps(PillowTestCase): self.assertEqual(image2_scale2.format, "EPS") def test_invalid_file(self): - self.assertRaises(SyntaxError, lambda: EpsImagePlugin.EpsImageFile("Tests/images/flower.jpg")) + invalid_file = "Tests/images/flower.jpg" + + self.assertRaises(SyntaxError, + lambda: EpsImagePlugin.EpsImageFile(invalid_file)) def test_file_object(self): # issue 479 @@ -152,7 +155,9 @@ class TestFileEps(PillowTestCase): Image.open(file3) def _test_readline(self, t, ending): - ending = "Failure with line ending: %s" % ("".join("%s" % ord(s) for s in ending)) + ending = "Failure with line ending: %s" % ("".join( + "%s" % ord(s) + for s in ending)) self.assertEqual(t.readline().strip('\r\n'), 'something', ending) self.assertEqual(t.readline().strip('\r\n'), 'else', ending) self.assertEqual(t.readline().strip('\r\n'), 'baz', ending) diff --git a/Tests/test_file_fitsstub.py b/Tests/test_file_fitsstub.py index 189d002d6..cc38b4a3a 100644 --- a/Tests/test_file_fitsstub.py +++ b/Tests/test_file_fitsstub.py @@ -6,7 +6,11 @@ from PIL import FitsStubImagePlugin class TestFileFitsStub(PillowTestCase): def test_invalid_file(self): - self.assertRaises(SyntaxError, lambda: FitsStubImagePlugin.FITSStubImageFile("Tests/images/flower.jpg")) + invalid_file = "Tests/images/flower.jpg" + + self.assertRaises(SyntaxError, + lambda: + FitsStubImagePlugin.FITSStubImageFile(invalid_file)) if __name__ == '__main__': diff --git a/Tests/test_file_fli.py b/Tests/test_file_fli.py index daaebdc69..aa2fa5ae5 100644 --- a/Tests/test_file_fli.py +++ b/Tests/test_file_fli.py @@ -19,7 +19,10 @@ class TestFileFli(PillowTestCase): self.assertEqual(im.format, "FLI") def test_invalid_file(self): - self.assertRaises(SyntaxError, lambda: FliImagePlugin.FliImageFile("Tests/images/flower.jpg")) + invalid_file = "Tests/images/flower.jpg" + + self.assertRaises(SyntaxError, + lambda: FliImagePlugin.FliImageFile(invalid_file)) def test_n_frames(self): im = Image.open(test_file) diff --git a/Tests/test_file_fpx.py b/Tests/test_file_fpx.py index 4b3756fb9..35119a612 100644 --- a/Tests/test_file_fpx.py +++ b/Tests/test_file_fpx.py @@ -6,7 +6,10 @@ from PIL import FpxImagePlugin class TestFileFpx(PillowTestCase): def test_invalid_file(self): - self.assertRaises(SyntaxError, lambda: FpxImagePlugin.FpxImageFile("Tests/images/flower.jpg")) + invalid_file = "Tests/images/flower.jpg" + + self.assertRaises(SyntaxError, + lambda: FpxImagePlugin.FpxImageFile(invalid_file)) if __name__ == '__main__': diff --git a/Tests/test_file_gbr.py b/Tests/test_file_gbr.py index ecec0189b..57b301ada 100644 --- a/Tests/test_file_gbr.py +++ b/Tests/test_file_gbr.py @@ -6,7 +6,10 @@ from PIL import GbrImagePlugin class TestFileGbr(PillowTestCase): def test_invalid_file(self): - self.assertRaises(SyntaxError, lambda: GbrImagePlugin.GbrImageFile("Tests/images/flower.jpg")) + invalid_file = "Tests/images/flower.jpg" + + self.assertRaises(SyntaxError, + lambda: GbrImagePlugin.GbrImageFile(invalid_file)) if __name__ == '__main__': diff --git a/Tests/test_file_gif.py b/Tests/test_file_gif.py index 33e04cb5e..c40e5f6b0 100644 --- a/Tests/test_file_gif.py +++ b/Tests/test_file_gif.py @@ -26,7 +26,10 @@ class TestFileGif(PillowTestCase): self.assertEqual(im.format, "GIF") def test_invalid_file(self): - self.assertRaises(SyntaxError, lambda: GifImagePlugin.GifImageFile("Tests/images/flower.jpg")) + invalid_file = "Tests/images/flower.jpg" + + self.assertRaises(SyntaxError, + lambda: GifImagePlugin.GifImageFile(invalid_file)) def test_optimize(self): from io import BytesIO diff --git a/Tests/test_file_gribstub.py b/Tests/test_file_gribstub.py index 84bf8a5be..dd4ee84ff 100644 --- a/Tests/test_file_gribstub.py +++ b/Tests/test_file_gribstub.py @@ -6,7 +6,11 @@ from PIL import GribStubImagePlugin class TestFileGribStub(PillowTestCase): def test_invalid_file(self): - self.assertRaises(SyntaxError, lambda: GribStubImagePlugin.GribStubImageFile("Tests/images/flower.jpg")) + invalid_file = "Tests/images/flower.jpg" + + self.assertRaises(SyntaxError, + lambda: + GribStubImagePlugin.GribStubImageFile(invalid_file)) if __name__ == '__main__': diff --git a/Tests/test_file_hdf5stub.py b/Tests/test_file_hdf5stub.py index 2b7e208d2..485931b36 100644 --- a/Tests/test_file_hdf5stub.py +++ b/Tests/test_file_hdf5stub.py @@ -6,7 +6,11 @@ from PIL import Hdf5StubImagePlugin class TestFileHdf5Stub(PillowTestCase): def test_invalid_file(self): - self.assertRaises(SyntaxError, lambda: Hdf5StubImagePlugin.HDF5StubImageFile("Tests/images/flower.jpg")) + test_file = "Tests/images/flower.jpg" + + self.assertRaises(SyntaxError, + lambda: + Hdf5StubImagePlugin.HDF5StubImageFile(test_file)) if __name__ == '__main__': diff --git a/Tests/test_file_ico.py b/Tests/test_file_ico.py index d2adf8dcc..70e00c083 100644 --- a/Tests/test_file_ico.py +++ b/Tests/test_file_ico.py @@ -19,7 +19,8 @@ class TestFileIco(PillowTestCase): def test_invalid_file(self): with open("Tests/images/flower.jpg", "rb") as fp: - self.assertRaises(SyntaxError, lambda: IcoImagePlugin.IcoImageFile(fp)) + self.assertRaises(SyntaxError, + lambda: IcoImagePlugin.IcoImageFile(fp)) def test_save_to_bytes(self): output = io.BytesIO() @@ -34,7 +35,8 @@ class TestFileIco(PillowTestCase): self.assertEqual(im.mode, reloaded.mode) self.assertEqual((64, 64), reloaded.size) self.assertEqual(reloaded.format, "ICO") - self.assert_image_equal(reloaded, hopper().resize((64, 64), Image.LANCZOS)) + self.assert_image_equal(reloaded, + hopper().resize((64, 64), Image.LANCZOS)) # the other one output.seek(0) @@ -44,7 +46,8 @@ class TestFileIco(PillowTestCase): self.assertEqual(im.mode, reloaded.mode) self.assertEqual((32, 32), reloaded.size) self.assertEqual(reloaded.format, "ICO") - self.assert_image_equal(reloaded, hopper().resize((32, 32), Image.LANCZOS)) + self.assert_image_equal(reloaded, + hopper().resize((32, 32), Image.LANCZOS)) if __name__ == '__main__': diff --git a/Tests/test_file_im.py b/Tests/test_file_im.py index 01b6fd561..e3d92d1d5 100644 --- a/Tests/test_file_im.py +++ b/Tests/test_file_im.py @@ -41,7 +41,10 @@ class TestFileIm(PillowTestCase): self.assert_image_equal(reread, im) def test_invalid_file(self): - self.assertRaises(SyntaxError, lambda: ImImagePlugin.ImImageFile("Tests/images/flower.jpg")) + invalid_file = "Tests/images/flower.jpg" + + self.assertRaises(SyntaxError, + lambda: ImImagePlugin.ImImageFile(invalid_file)) if __name__ == '__main__': diff --git a/Tests/test_file_jpeg.py b/Tests/test_file_jpeg.py index d4929dd58..bb2d7b61e 100644 --- a/Tests/test_file_jpeg.py +++ b/Tests/test_file_jpeg.py @@ -291,22 +291,24 @@ class TestFileJpeg(PillowTestCase): # dict of qtable lists self.assert_image_similar(im, - self.roundtrip(im, - qtables={0: standard_l_qtable, - 1: standard_chrominance_qtable}), - 30) + self.roundtrip(im, qtables={ + 0: standard_l_qtable, + 1: standard_chrominance_qtable + }), 30) # not a sequence self.assertRaises(Exception, lambda: self.roundtrip(im, qtables='a')) # sequence wrong length self.assertRaises(Exception, lambda: self.roundtrip(im, qtables=[])) # sequence wrong length - self.assertRaises(Exception, lambda: self.roundtrip(im, qtables=[1, 2, 3, 4, 5])) + self.assertRaises(Exception, + lambda: self.roundtrip(im, qtables=[1, 2, 3, 4, 5])) # qtable entry not a sequence self.assertRaises(Exception, lambda: self.roundtrip(im, qtables=[1])) # qtable entry has wrong number of items - self.assertRaises(Exception, lambda: self.roundtrip(im, qtables=[[1, 2, 3, 4]])) + self.assertRaises(Exception, + lambda: self.roundtrip(im, qtables=[[1, 2, 3, 4]])) @unittest.skipUnless(djpeg_available(), "djpeg not available") def test_load_djpeg(self): @@ -337,7 +339,8 @@ class TestFileJpeg(PillowTestCase): """ Generates a very hard to compress file :param size: tuple """ - return Image.frombytes('RGB', size, os.urandom(size[0]*size[1] * 3)) + return Image.frombytes('RGB', + size, os.urandom(size[0]*size[1] * 3)) im = gen_random_image((512, 512)) f = self.tempfile("temp.jpeg") diff --git a/Tests/test_file_jpeg2k.py b/Tests/test_file_jpeg2k.py index a97a7e9da..4b7286a20 100644 --- a/Tests/test_file_jpeg2k.py +++ b/Tests/test_file_jpeg2k.py @@ -40,7 +40,11 @@ class TestFileJpeg2k(PillowTestCase): self.assertEqual(im.format, 'JPEG2000') def test_invalid_file(self): - self.assertRaises(SyntaxError, lambda: Jpeg2KImagePlugin.Jpeg2KImageFile("Tests/images/flower.jpg")) + invalid_file = "Tests/images/flower.jpg" + + self.assertRaises(SyntaxError, + lambda: + Jpeg2KImagePlugin.Jpeg2KImageFile(invalid_file)) def test_bytesio(self): with open('Tests/images/test-card-lossless.jp2', 'rb') as f: diff --git a/Tests/test_file_mcidas.py b/Tests/test_file_mcidas.py index 44130746a..d547011e2 100644 --- a/Tests/test_file_mcidas.py +++ b/Tests/test_file_mcidas.py @@ -6,7 +6,11 @@ from PIL import McIdasImagePlugin class TestFileMcIdas(PillowTestCase): def test_invalid_file(self): - self.assertRaises(SyntaxError, lambda: McIdasImagePlugin.McIdasImageFile("Tests/images/flower.jpg")) + invalid_file = "Tests/images/flower.jpg" + + self.assertRaises(SyntaxError, + lambda: + McIdasImagePlugin.McIdasImageFile(invalid_file)) if __name__ == '__main__': diff --git a/Tests/test_file_mic.py b/Tests/test_file_mic.py index de106bc14..0a574422a 100644 --- a/Tests/test_file_mic.py +++ b/Tests/test_file_mic.py @@ -6,7 +6,10 @@ from PIL import MicImagePlugin class TestFileMic(PillowTestCase): def test_invalid_file(self): - self.assertRaises(SyntaxError, lambda: MicImagePlugin.MicImageFile("Tests/images/flower.jpg")) + invalid_file = "Tests/images/flower.jpg" + + self.assertRaises(SyntaxError, + lambda: MicImagePlugin.MicImageFile(invalid_file)) if __name__ == '__main__': diff --git a/Tests/test_file_msp.py b/Tests/test_file_msp.py index 94fcfd895..3dbca6e60 100644 --- a/Tests/test_file_msp.py +++ b/Tests/test_file_msp.py @@ -19,7 +19,10 @@ class TestFileMsp(PillowTestCase): self.assertEqual(im.format, "MSP") def test_invalid_file(self): - self.assertRaises(SyntaxError, lambda: MspImagePlugin.MspImageFile("Tests/images/flower.jpg")) + invalid_file = "Tests/images/flower.jpg" + + self.assertRaises(SyntaxError, + lambda: MspImagePlugin.MspImageFile(invalid_file)) def test_open(self): # Arrange diff --git a/Tests/test_file_pcx.py b/Tests/test_file_pcx.py index 5a1a2e9a6..f6342bed9 100644 --- a/Tests/test_file_pcx.py +++ b/Tests/test_file_pcx.py @@ -20,7 +20,10 @@ class TestFilePcx(PillowTestCase): self._roundtrip(hopper(mode)) def test_invalid_file(self): - self.assertRaises(SyntaxError, lambda: PcxImagePlugin.PcxImageFile("Tests/images/flower.jpg")) + invalid_file = "Tests/images/flower.jpg" + + self.assertRaises(SyntaxError, + lambda: PcxImagePlugin.PcxImageFile(invalid_file)) def test_odd(self): # see issue #523, odd sized images should have a stride that's even. diff --git a/Tests/test_file_png.py b/Tests/test_file_png.py index dfd83baa6..cb72b2d73 100644 --- a/Tests/test_file_png.py +++ b/Tests/test_file_png.py @@ -82,7 +82,10 @@ class TestFilePng(PillowTestCase): im = Image.open(test_file) def test_invalid_file(self): - self.assertRaises(SyntaxError, lambda: PngImagePlugin.PngImageFile("Tests/images/flower.jpg")) + invalid_file = "Tests/images/flower.jpg" + + self.assertRaises(SyntaxError, + lambda: PngImagePlugin.PngImageFile(invalid_file)) def test_broken(self): # Check reading of totally broken files. In this case, the test diff --git a/Tests/test_file_psd.py b/Tests/test_file_psd.py index af1780d9d..4890839f1 100644 --- a/Tests/test_file_psd.py +++ b/Tests/test_file_psd.py @@ -17,7 +17,10 @@ class TestImagePsd(PillowTestCase): self.assertEqual(im.format, "PSD") def test_invalid_file(self): - self.assertRaises(SyntaxError, lambda: PsdImagePlugin.PsdImageFile("Tests/images/flower.jpg")) + invalid_file = "Tests/images/flower.jpg" + + self.assertRaises(SyntaxError, + lambda: PsdImagePlugin.PsdImageFile(invalid_file)) def test_n_frames(self): im = Image.open("Tests/images/hopper_merged.psd") diff --git a/Tests/test_file_sgi.py b/Tests/test_file_sgi.py index 9842b3991..e78488913 100644 --- a/Tests/test_file_sgi.py +++ b/Tests/test_file_sgi.py @@ -33,7 +33,11 @@ class TestFileSgi(PillowTestCase): self.assertRaises(ValueError, lambda: Image.open(test_file)) def test_invalid_file(self): - self.assertRaises(ValueError, lambda: SgiImagePlugin.SgiImageFile("Tests/images/flower.jpg")) + invalid_file = "Tests/images/flower.jpg" + + self.assertRaises(ValueError, + lambda: + SgiImagePlugin.SgiImageFile(invalid_file)) if __name__ == '__main__': diff --git a/Tests/test_file_sun.py b/Tests/test_file_sun.py index e476ebf13..16c43b921 100644 --- a/Tests/test_file_sun.py +++ b/Tests/test_file_sun.py @@ -16,7 +16,9 @@ class TestFileSun(PillowTestCase): # Assert self.assertEqual(im.size, (128, 128)) - self.assertRaises(SyntaxError, lambda: SunImagePlugin.SunImageFile("Tests/images/flower.jpg")) + invalid_file = "Tests/images/flower.jpg" + self.assertRaises(SyntaxError, + lambda: SunImagePlugin.SunImageFile(invalid_file)) if __name__ == '__main__': diff --git a/Tests/test_file_tga.py b/Tests/test_file_tga.py index cccd9bf96..459e766d5 100644 --- a/Tests/test_file_tga.py +++ b/Tests/test_file_tga.py @@ -30,7 +30,7 @@ class TestFileTga(PillowTestCase): im.convert("RGBA").save(test_file) test_im = Image.open(test_file) self.assertEqual(test_im.size, (100, 100)) - + # Unsupported mode save self.assertRaises(IOError, lambda: im.convert("LA").save(test_file)) diff --git a/Tests/test_file_tiff.py b/Tests/test_file_tiff.py index 98b346016..e1702bcfe 100644 --- a/Tests/test_file_tiff.py +++ b/Tests/test_file_tiff.py @@ -86,7 +86,8 @@ class TestFileTiff(PillowTestCase): try: Image.open('Tests/images/hopper_bad_exif.jpg')._getexif() except struct.error: - self.fail("Bad EXIF data should not pass incorrect values to _binary unpack") + self.fail( + "Bad EXIF data passed incorrect values to _binary unpack") def test_little_endian(self): im = Image.open('Tests/images/16bit.cropped.tif') diff --git a/Tests/test_file_webp_alpha.py b/Tests/test_file_webp_alpha.py index f316b71e1..e7df62ee6 100644 --- a/Tests/test_file_webp_alpha.py +++ b/Tests/test_file_webp_alpha.py @@ -83,7 +83,8 @@ class TestFileWebpAlpha(PillowTestCase): image.load() image.getdata() - # early versions of webp are known to produce higher deviations: deal with it + # early versions of webp are known to produce higher deviations: + # deal with it if _webp.WebPDecoderVersion(self) <= 0x201: self.assert_image_similar(image, pil_image, 3.0) else: diff --git a/Tests/test_file_xpm.py b/Tests/test_file_xpm.py index 3e3c35e18..e589a8d26 100644 --- a/Tests/test_file_xpm.py +++ b/Tests/test_file_xpm.py @@ -19,7 +19,10 @@ class TestFileXpm(PillowTestCase): self.assert_image_similar(im.convert('RGB'), hopper('RGB'), 60) def test_invalid_file(self): - self.assertRaises(SyntaxError, lambda: XpmImagePlugin.XpmImageFile("Tests/images/flower.jpg")) + invalid_file = "Tests/images/flower.jpg" + + self.assertRaises(SyntaxError, + lambda: XpmImagePlugin.XpmImageFile(invalid_file)) def test_load_read(self): # Arrange diff --git a/Tests/test_image_filter.py b/Tests/test_image_filter.py index a62431dd9..f75a1891d 100644 --- a/Tests/test_image_filter.py +++ b/Tests/test_image_filter.py @@ -89,7 +89,7 @@ class TestImageFilter(PillowTestCase): self.assertEqual(rankfilter("F"), (0.0, 4.0, 8.0)) def test_rankfilter_properties(self): - rankfilter = ImageFilter.RankFilter(1,2) + rankfilter = ImageFilter.RankFilter(1, 2) self.assertEqual(rankfilter.size, 1) self.assertEqual(rankfilter.rank, 2) diff --git a/Tests/test_imagecolor.py b/Tests/test_imagecolor.py index d55e73b9c..a38c8b070 100644 --- a/Tests/test_imagecolor.py +++ b/Tests/test_imagecolor.py @@ -18,7 +18,8 @@ class TestImageColor(PillowTestCase): (255, 0, 0, 0), ImageColor.getrgb("rgba(255, 0, 0, 0)")) self.assertEqual((255, 0, 0), ImageColor.getrgb("red")) - self.assertRaises(ValueError, lambda: ImageColor.getrgb("invalid color")) + self.assertRaises(ValueError, + lambda: ImageColor.getrgb("invalid color")) # look for rounding errors (based on code by Tim Hatch) def test_rounding_errors(self): @@ -45,8 +46,8 @@ class TestImageColor(PillowTestCase): self.assertEqual(0, ImageColor.getcolor("black", "L")) self.assertEqual(255, ImageColor.getcolor("white", "L")) - self.assertEqual( - 162, ImageColor.getcolor("rgba(0, 255, 115, 33)", "L")) + self.assertEqual(162, + ImageColor.getcolor("rgba(0, 255, 115, 33)", "L")) Image.new("L", (1, 1), "white") self.assertEqual(0, ImageColor.getcolor("black", "1")) diff --git a/Tests/test_imagedraw.py b/Tests/test_imagedraw.py index 2e746438d..803677616 100644 --- a/Tests/test_imagedraw.py +++ b/Tests/test_imagedraw.py @@ -55,7 +55,8 @@ class TestImageDraw(PillowTestCase): def test_mode_mismatch(self): im = hopper("RGB").copy() - self.assertRaises(ValueError, lambda: ImageDraw.ImageDraw(im, mode="L")) + self.assertRaises(ValueError, + lambda: ImageDraw.ImageDraw(im, mode="L")) def helper_arc(self, bbox): # Arrange diff --git a/Tests/test_imagefont_bitmap.py b/Tests/test_imagefont_bitmap.py index 27141f4b3..a9d745b22 100644 --- a/Tests/test_imagefont_bitmap.py +++ b/Tests/test_imagefont_bitmap.py @@ -5,16 +5,19 @@ from PIL import Image, ImageFont, ImageDraw class TestImageFontBitmap(PillowTestCase): def test_similar(self): text = 'EmbeddedBitmap' - font_outline = ImageFont.truetype(font='Tests/fonts/DejaVuSans.ttf', size=24) - font_bitmap = ImageFont.truetype(font='Tests/fonts/DejaVuSans-bitmap.ttf', size=24) + font_outline = ImageFont.truetype( + font='Tests/fonts/DejaVuSans.ttf', size=24) + font_bitmap = ImageFont.truetype( + font='Tests/fonts/DejaVuSans-bitmap.ttf', size=24) size_outline, size_bitmap = font_outline.getsize(text), font_bitmap.getsize(text) size_final = max(size_outline[0], size_bitmap[0]), max(size_outline[1], size_bitmap[1]) im_bitmap = Image.new('RGB', size_final, (255, 255, 255)) im_outline = im_bitmap.copy() draw_bitmap, draw_outline = ImageDraw.Draw(im_bitmap), ImageDraw.Draw(im_outline) - # Metrics are different on the bitmap and ttf fonts, more so on some platforms - # and versions of freetype than others. Mac has a 1px difference, linux doesn't. + # Metrics are different on the bitmap and ttf fonts, + # more so on some platforms and versions of freetype than others. + # Mac has a 1px difference, linux doesn't. draw_bitmap.text((0, size_final[1] - size_bitmap[1]), text, fill=(0, 0, 0), font=font_bitmap) draw_outline.text((0, size_final[1] - size_outline[1]), diff --git a/Tests/test_imageops_usm.py b/Tests/test_imageops_usm.py index f6eae640b..89c63c774 100644 --- a/Tests/test_imageops_usm.py +++ b/Tests/test_imageops_usm.py @@ -75,7 +75,9 @@ class TestImageOpsUsm(PillowTestCase): (4, 3, 2), (4, 2, 2)]: self.assertGreaterEqual(i.im.getpixel((x, y))[c], 250) # Fuzzy match. - gp = lambda x, y: i.im.getpixel((x, y)) + + def gp(x, y): + return i.im.getpixel((x, y)) self.assertTrue(236 <= gp(7, 4)[0] <= 239) self.assertTrue(236 <= gp(7, 5)[2] <= 239) self.assertTrue(236 <= gp(7, 6)[2] <= 239) diff --git a/Tests/test_imagewin.py b/Tests/test_imagewin.py index 7ceea86ee..8a5bc125f 100644 --- a/Tests/test_imagewin.py +++ b/Tests/test_imagewin.py @@ -115,7 +115,8 @@ class TestImageWinDib(PillowTestCase): # Act/Assert self.assert_warning(DeprecationWarning, dib.tostring) - self.assert_warning(DeprecationWarning, lambda: dib.fromstring(test_buffer)) + self.assert_warning(DeprecationWarning, + lambda: dib.fromstring(test_buffer)) if __name__ == '__main__': diff --git a/Tests/test_scipy.py b/Tests/test_scipy.py index 1632d9475..1d7568148 100644 --- a/Tests/test_scipy.py +++ b/Tests/test_scipy.py @@ -30,10 +30,10 @@ class Test_scipy_resize(PillowTestCase): def test_imresize4(self): im = np.array([[1, 2], [3, 4]]) - res = np.array([[1. , 1.25, 1.75, 2. ], + res = np.array([[1., 1.25, 1.75, 2.], [1.5, 1.75, 2.25, 2.5], [2.5, 2.75, 3.25, 3.5], - [3. , 3.25, 3.75, 4. ]], dtype=np.float32) + [3., 3.25, 3.75, 4.]], dtype=np.float32) # Check that resizing by target size, float and int are the same im2 = misc.imresize(im, (4, 4), mode='F') # output size im3 = misc.imresize(im, 2., mode='F') # fraction