diff --git a/Tests/check_imaging_leaks.py b/Tests/check_imaging_leaks.py index eb9426eee..0c41b6da1 100755 --- a/Tests/check_imaging_leaks.py +++ b/Tests/check_imaging_leaks.py @@ -25,9 +25,8 @@ class TestImagingLeaks(PillowTestCase): if i < min_iterations: mem_limit = mem + 1 continue - self.assertLessEqual(mem, mem_limit, - msg='memory usage limit exceeded after %d iterations' - % (i + 1)) + msg = 'memory usage limit exceeded after %d iterations' % (i + 1) + self.assertLessEqual(mem, mem_limit, msg) def test_leak_putdata(self): im = Image.new('RGB', (25, 25)) diff --git a/Tests/helper.py b/Tests/helper.py index b6ef6dc13..8fb34848b 100644 --- a/Tests/helper.py +++ b/Tests/helper.py @@ -272,8 +272,8 @@ class PillowLeakTestCase(PillowTestCase): for cycle in range(self.iterations): core() mem = (self._get_mem_usage() - start_mem) - self.assertLess(mem, self.mem_limit, - msg='memory usage limit exceeded in iteration %d' % cycle) + msg = 'memory usage limit exceeded in iteration %d' % cycle + self.assertLess(mem, self.mem_limit, msg) # helpers diff --git a/Tests/test_bmp_reference.py b/Tests/test_bmp_reference.py index 015a9ebdf..af25f7162 100644 --- a/Tests/test_bmp_reference.py +++ b/Tests/test_bmp_reference.py @@ -42,7 +42,8 @@ class TestBmpReference(PillowTestCase): im = Image.open(f) im.load() if os.path.basename(f) not in supported: - print("Please add %s to the partially supported bmp specs." % f) + print("Please add %s to the partially supported" + " bmp specs." % f) except Exception: # as msg: if os.path.basename(f) in supported: raise diff --git a/Tests/test_color_lut.py b/Tests/test_color_lut.py index 6d0b76fed..ec370f70a 100644 --- a/Tests/test_color_lut.py +++ b/Tests/test_color_lut.py @@ -335,35 +335,35 @@ class TestColorLut3DFilter(PillowTestCase): g.transpose(Image.ROTATE_180)]) lut = ImageFilter.Color3DLUT.generate((7, 9, 11), - lambda r, g, b: (r, g, b)) + lambda r, g, b: (r, g, b)) lut.table = numpy.array(lut.table, dtype=numpy.float32)[:-1] with self.assertRaisesRegex(ValueError, "should have table_channels"): im.filter(lut) lut = ImageFilter.Color3DLUT.generate((7, 9, 11), - lambda r, g, b: (r, g, b)) + lambda r, g, b: (r, g, b)) lut.table = (numpy.array(lut.table, dtype=numpy.float32) .reshape((7 * 9 * 11), 3)) with self.assertRaisesRegex(ValueError, "should have table_channels"): im.filter(lut) lut = ImageFilter.Color3DLUT.generate((7, 9, 11), - lambda r, g, b: (r, g, b)) + lambda r, g, b: (r, g, b)) lut.table = numpy.array(lut.table, dtype=numpy.float16) self.assert_image_equal(im, im.filter(lut)) lut = ImageFilter.Color3DLUT.generate((7, 9, 11), - lambda r, g, b: (r, g, b)) + lambda r, g, b: (r, g, b)) lut.table = numpy.array(lut.table, dtype=numpy.float32) self.assert_image_equal(im, im.filter(lut)) lut = ImageFilter.Color3DLUT.generate((7, 9, 11), - lambda r, g, b: (r, g, b)) + lambda r, g, b: (r, g, b)) lut.table = numpy.array(lut.table, dtype=numpy.float64) self.assert_image_equal(im, im.filter(lut)) lut = ImageFilter.Color3DLUT.generate((7, 9, 11), - lambda r, g, b: (r, g, b)) + lambda r, g, b: (r, g, b)) lut.table = numpy.array(lut.table, dtype=numpy.int32) im.filter(lut) lut.table = numpy.array(lut.table, dtype=numpy.int8) diff --git a/Tests/test_file_gd.py b/Tests/test_file_gd.py index 326b0c4b2..b303369b4 100644 --- a/Tests/test_file_gd.py +++ b/Tests/test_file_gd.py @@ -2,8 +2,6 @@ from helper import unittest, PillowTestCase from PIL import GdImageFile -import io - TEST_GD_FILE = "Tests/images/hopper.gd" diff --git a/Tests/test_file_tiff.py b/Tests/test_file_tiff.py index 68429f249..cbfc63d74 100644 --- a/Tests/test_file_tiff.py +++ b/Tests/test_file_tiff.py @@ -1,6 +1,5 @@ import logging from io import BytesIO -import struct import sys from helper import unittest, PillowTestCase, hopper @@ -59,7 +58,8 @@ class TestFileTiff(PillowTestCase): self.assertEqual(im.mode, "RGBA") self.assertEqual(im.size, (52, 53)) - self.assertEqual(im.tile, [('raw', (0, 0, 52, 53), 160, ('RGBA', 0, 1))]) + self.assertEqual(im.tile, + [('raw', (0, 0, 52, 53), 160, ('RGBA', 0, 1))]) im.load() def test_set_legacy_api(self): diff --git a/Tests/test_file_tiff_metadata.py b/Tests/test_file_tiff_metadata.py index 0a958454c..d1e2b577e 100644 --- a/Tests/test_file_tiff_metadata.py +++ b/Tests/test_file_tiff_metadata.py @@ -56,7 +56,8 @@ class TestFileTiffMetadata(PillowTestCase): loaded = Image.open(f) self.assertEqual(loaded.tag[ImageJMetaDataByteCounts], (len(bindata),)) - self.assertEqual(loaded.tag_v2[ImageJMetaDataByteCounts], (len(bindata),)) + self.assertEqual(loaded.tag_v2[ImageJMetaDataByteCounts], + (len(bindata),)) self.assertEqual(loaded.tag[ImageJMetaData], bindata) self.assertEqual(loaded.tag_v2[ImageJMetaData], bindata) @@ -75,8 +76,10 @@ class TestFileTiffMetadata(PillowTestCase): img.save(f, tiffinfo=info) loaded = Image.open(f) - self.assertEqual(loaded.tag[ImageJMetaDataByteCounts], (8, len(bindata) - 8)) - self.assertEqual(loaded.tag_v2[ImageJMetaDataByteCounts], (8, len(bindata) - 8)) + self.assertEqual(loaded.tag[ImageJMetaDataByteCounts], + (8, len(bindata) - 8)) + self.assertEqual(loaded.tag_v2[ImageJMetaDataByteCounts], + (8, len(bindata) - 8)) def test_read_metadata(self): img = Image.open('Tests/images/hopper_g4.tif') @@ -133,8 +136,8 @@ class TestFileTiffMetadata(PillowTestCase): if isinstance(v, IFDRational): original[k] = IFDRational(*_limit_rational(v, 2**31)) if isinstance(v, tuple) and isinstance(v[0], IFDRational): - original[k] = tuple([IFDRational( - *_limit_rational(elt, 2**31)) for elt in v]) + original[k] = tuple([IFDRational(*_limit_rational(elt, 2**31)) + for elt in v]) ignored = ['StripByteCounts', 'RowsPerStrip', 'PageNumber', 'StripOffsets'] @@ -184,7 +187,8 @@ class TestFileTiffMetadata(PillowTestCase): def test_iccprofile_binary(self): # https://github.com/python-pillow/Pillow/issues/1526 - # We should be able to load this, but probably won't be able to save it. + # We should be able to load this, + # but probably won't be able to save it. im = Image.open('Tests/images/hopper.iccprofile_binary.tif') self.assertEqual(im.tag_v2.tagtype[34675], 1) diff --git a/Tests/test_file_webp.py b/Tests/test_file_webp.py index 25d3cb462..fa01cf93e 100644 --- a/Tests/test_file_webp.py +++ b/Tests/test_file_webp.py @@ -38,7 +38,8 @@ class TestFileWebp(PillowTestCase): # generated with: # dwebp -ppm ../../Tests/images/hopper.webp -o hopper_webp_bits.ppm - self.assert_image_similar_tofile(image, 'Tests/images/hopper_webp_bits.ppm', 1.0) + self.assert_image_similar_tofile( + image, 'Tests/images/hopper_webp_bits.ppm', 1.0) def test_write_rgb(self): """ @@ -58,7 +59,8 @@ class TestFileWebp(PillowTestCase): image.getdata() # generated with: dwebp -ppm temp.webp -o hopper_webp_write.ppm - self.assert_image_similar_tofile(image, 'Tests/images/hopper_webp_write.ppm', 12.0) + self.assert_image_similar_tofile( + image, 'Tests/images/hopper_webp_write.ppm', 12.0) # This test asserts that the images are similar. If the average pixel # difference between the two images is less than the epsilon value, diff --git a/Tests/test_image_convert.py b/Tests/test_image_convert.py index 84c1cc82e..1b3815d80 100644 --- a/Tests/test_image_convert.py +++ b/Tests/test_image_convert.py @@ -204,7 +204,8 @@ class TestImageConvert(PillowTestCase): target = Image.open('Tests/images/hopper-XYZ.png') if converted_im.mode == 'RGB': self.assert_image_similar(converted_im, target, 3) - self.assertEqual(converted_im.info['transparency'], (105, 54, 4)) + self.assertEqual(converted_im.info['transparency'], + (105, 54, 4)) else: self.assert_image_similar(converted_im, target.getchannel(0), 1) diff --git a/Tests/test_image_rotate.py b/Tests/test_image_rotate.py index 17d394a02..e788e722f 100644 --- a/Tests/test_image_rotate.py +++ b/Tests/test_image_rotate.py @@ -114,15 +114,16 @@ class TestImageRotate(PillowTestCase): # Alpha images are handled differently internally im = Image.new('RGBA', (10, 10), 'green') im = im.rotate(45, expand=1) - corner = im.getpixel((0,0)) + corner = im.getpixel((0, 0)) self.assertEqual(corner, (0, 0, 0, 0)) def test_alpha_rotate_with_fill(self): # Alpha images are handled differently internally im = Image.new('RGBA', (10, 10), 'green') im = im.rotate(45, expand=1, fillcolor=(255, 0, 0, 255)) - corner = im.getpixel((0,0)) + corner = im.getpixel((0, 0)) self.assertEqual(corner, (255, 0, 0, 255)) + if __name__ == '__main__': unittest.main() diff --git a/Tests/test_imagecms.py b/Tests/test_imagecms.py index 1fdfe916d..dc6c85f05 100644 --- a/Tests/test_imagecms.py +++ b/Tests/test_imagecms.py @@ -175,11 +175,11 @@ class TestImageCms(PillowTestCase): def test_unsupported_color_space(self): self.assertRaises(ImageCms.PyCMSError, - ImageCms.createProfile, "unsupported") + ImageCms.createProfile, "unsupported") def test_invalid_color_temperature(self): self.assertRaises(ImageCms.PyCMSError, - ImageCms.createProfile, "LAB", "invalid") + ImageCms.createProfile, "LAB", "invalid") def test_simple_lab(self): i = Image.new('RGB', (10, 10), (128, 128, 128)) @@ -446,20 +446,20 @@ class TestImageCms(PillowTestCase): self.assert_image_equal(source_image_aux, result_image_aux) def test_preserve_auxiliary_channels_rgba(self): - self.assert_aux_channel_preserved(mode='RGBA', - transform_in_place=False, preserved_channel='A') + self.assert_aux_channel_preserved( + mode='RGBA', transform_in_place=False, preserved_channel='A') def test_preserve_auxiliary_channels_rgba_in_place(self): - self.assert_aux_channel_preserved(mode='RGBA', - transform_in_place=True, preserved_channel='A') + self.assert_aux_channel_preserved( + mode='RGBA', transform_in_place=True, preserved_channel='A') def test_preserve_auxiliary_channels_rgbx(self): - self.assert_aux_channel_preserved(mode='RGBX', - transform_in_place=False, preserved_channel='X') + self.assert_aux_channel_preserved( + mode='RGBX', transform_in_place=False, preserved_channel='X') def test_preserve_auxiliary_channels_rgbx_in_place(self): - self.assert_aux_channel_preserved(mode='RGBX', - transform_in_place=True, preserved_channel='X') + self.assert_aux_channel_preserved( + mode='RGBX', transform_in_place=True, preserved_channel='X') def test_auxiliary_channels_isolated(self): # test data in aux channels does not affect non-aux channels diff --git a/Tests/test_imagedraw.py b/Tests/test_imagedraw.py index ad3e8b2cb..5a945e8b2 100644 --- a/Tests/test_imagedraw.py +++ b/Tests/test_imagedraw.py @@ -622,12 +622,12 @@ class TestImageDraw(PillowTestCase): ["red", "#f00"] ]: for operation, args in { - 'chord':[BBOX1, 0, 180], - 'ellipse':[BBOX1], - 'shape':[s], - 'pieslice':[BBOX1, -90, 45], - 'polygon':[[(18, 30), (85, 30), (60, 72)]], - 'rectangle':[BBOX1] + 'chord': [BBOX1, 0, 180], + 'ellipse': [BBOX1], + 'shape': [s], + 'pieslice': [BBOX1, -90, 45], + 'polygon': [[(18, 30), (85, 30), (60, 72)]], + 'rectangle': [BBOX1] }.items(): # Arrange im = Image.new(mode, (W, H)) diff --git a/Tests/test_imageops.py b/Tests/test_imageops.py index ce8a6629d..70b1659d9 100644 --- a/Tests/test_imageops.py +++ b/Tests/test_imageops.py @@ -84,7 +84,7 @@ class TestImageOps(PillowTestCase): ("h", None, (im.width * 4, im.height * 2)), ("v", "#f00", (im.width * 2, im.height * 4)) ]: - for i, centering in enumerate([(0,0), (0.5, 0.5), (1, 1)]): + for i, centering in enumerate([(0, 0), (0.5, 0.5), (1, 1)]): new_im = ImageOps.pad(im, new_size, color=color, centering=centering) self.assertEqual(new_im.size, new_size) @@ -93,7 +93,6 @@ class TestImageOps(PillowTestCase): "Tests/images/imageops_pad_"+label+"_"+str(i)+".jpg") self.assert_image_similar(new_im, target, 6) - def test_pil163(self): # Division by zero in equalize if < 255 pixels in image (@PIL163) diff --git a/Tests/test_imagetk.py b/Tests/test_imagetk.py index 2df35c584..14ce74eb1 100644 --- a/Tests/test_imagetk.py +++ b/Tests/test_imagetk.py @@ -25,7 +25,7 @@ class TestImageTk(PillowTestCase): self.skipTest("Tk not installed") try: # setup tk - app = tk.Frame() + tk.Frame() # root = tk.Tk() except (tk.TclError) as v: self.skipTest("TCL Error: %s" % v) diff --git a/Tests/test_lib_pack.py b/Tests/test_lib_pack.py index 635b5679a..2fb7da281 100644 --- a/Tests/test_lib_pack.py +++ b/Tests/test_lib_pack.py @@ -221,7 +221,8 @@ class TestLibUnpack(PillowTestCase): data_len = data * len(pixels) data = bytes(bytearray(range(1, data_len + 1))) - im = Image.frombytes(mode, (len(pixels), 1), data, "raw", rawmode, 0, 1) + im = Image.frombytes(mode, (len(pixels), 1), data, + "raw", rawmode, 0, 1) for x, pixel in enumerate(pixels): self.assertEqual(pixel, im.getpixel((x, 0))) @@ -265,9 +266,11 @@ class TestLibUnpack(PillowTestCase): def test_P(self): self.assert_unpack("P", "P;1", b'\xe4', 1, 1, 1, 0, 0, 1, 0, 0) self.assert_unpack("P", "P;2", b'\xe4', 3, 2, 1, 0) - # self.assert_unpack("P", "P;2L", b'\xe4', 1, 1, 1, 0) # erroneous? + # erroneous? + # self.assert_unpack("P", "P;2L", b'\xe4', 1, 1, 1, 0) self.assert_unpack("P", "P;4", b'\x02\xef', 0, 2, 14, 15) - # self.assert_unpack("P", "P;4L", b'\x02\xef', 2, 10, 10, 0) # erroneous? + # erroneous? + # self.assert_unpack("P", "P;4L", b'\x02\xef', 2, 10, 10, 0) self.assert_unpack("P", "P", 1, 1, 2, 3, 4) self.assert_unpack("P", "P;R", 1, 128, 64, 192, 32) @@ -373,7 +376,8 @@ class TestLibUnpack(PillowTestCase): self.assert_unpack( "RGBA", "YCCA;P", b']bE\x04\xdd\xbej\xed57T\xce\xac\xce:\x11', # random data - (0, 161, 0, 4), (255, 255, 255, 237), (27, 158, 0, 206), (0, 118, 0, 17)) + (0, 161, 0, 4), (255, 255, 255, 237), + (27, 158, 0, 206), (0, 118, 0, 17)) self.assert_unpack( "RGBA", "R", 1, (1, 0, 0, 0), (2, 0, 0, 0), (3, 0, 0, 0)) self.assert_unpack( @@ -425,7 +429,8 @@ class TestLibUnpack(PillowTestCase): self.assert_unpack( "RGBX", "YCC;P", b'D]\x9c\x82\x1a\x91\xfaOC\xe7J\x12', # random data - (127, 102, 0, X), (192, 227, 0, X), (213, 255, 170, X), (98, 255, 133, X)) + (127, 102, 0, X), (192, 227, 0, X), + (213, 255, 170, X), (98, 255, 133, X)) self.assert_unpack("RGBX", "R", 1, (1, 0, 0, 0), (2, 0, 0, 0), (3, 0, 0, 0)) self.assert_unpack("RGBX", "G", 1, diff --git a/Tests/test_pdfparser.py b/Tests/test_pdfparser.py index 42c813520..b7373842e 100644 --- a/Tests/test_pdfparser.py +++ b/Tests/test_pdfparser.py @@ -26,7 +26,9 @@ class TestPdfParser(PillowTestCase): def test_parsing(self): self.assertEqual(PdfParser.interpret_name(b"Name#23Hash"), b"Name#Hash") - self.assertEqual(PdfParser.interpret_name(b"Name#23Hash", as_text=True), "Name#Hash") + self.assertEqual(PdfParser.interpret_name( + b"Name#23Hash", as_text=True + ), "Name#Hash") self.assertEqual(PdfParser.get_value(b"1 2 R ", 0), (IndirectReference(1, 2), 5)) self.assertEqual(PdfParser.get_value(b"true[", 0), (True, 4)) @@ -72,7 +74,9 @@ class TestPdfParser(PillowTestCase): self.assertIsInstance(a, list) self.assertEqual(len(a), 4) self.assertEqual(a[0], PdfName("Name")) - s = PdfParser.get_value(b"<>\nstream\nabcde\nendstream<<...", 0)[0] + s = PdfParser.get_value( + b"<>\nstream\nabcde\nendstream<<...", 0 + )[0] self.assertIsInstance(s, PdfStream) self.assertEqual(s.dictionary.Name, "value") self.assertEqual(s.decode(), b"abcde") diff --git a/src/PIL/GdImageFile.py b/src/PIL/GdImageFile.py index 2ca1e8218..1a0b2c910 100644 --- a/src/PIL/GdImageFile.py +++ b/src/PIL/GdImageFile.py @@ -61,7 +61,8 @@ class GdImageFile(ImageFile.ImageFile): self.palette = ImagePalette.raw("XBGR", s[7+trueColorOffset+4:7+trueColorOffset+4+256*4]) - self.tile = [("raw", (0, 0)+self.size, 7+trueColorOffset+4+256*4, ("L", 0, 1))] + self.tile = [("raw", (0, 0)+self.size, 7+trueColorOffset+4+256*4, + ("L", 0, 1))] def open(fp, mode="r"): diff --git a/src/PIL/ImageFile.py b/src/PIL/ImageFile.py index bdcc43d1f..915557a57 100644 --- a/src/PIL/ImageFile.py +++ b/src/PIL/ImageFile.py @@ -30,7 +30,6 @@ from . import Image from ._util import isPath import io -import os import sys import struct diff --git a/src/PIL/ImageFont.py b/src/PIL/ImageFont.py index 099ccc4ff..5384a725b 100644 --- a/src/PIL/ImageFont.py +++ b/src/PIL/ImageFont.py @@ -162,7 +162,8 @@ class FreeTypeFont(object): size, offset = self.font.getsize(text, direction, features) return (size[0] + offset[0], size[1] + offset[1]) - def getsize_multiline(self, text, direction=None, spacing=4, features=None): + def getsize_multiline(self, text, direction=None, + spacing=4, features=None): max_width = 0 lines = self._multiline_split(text) line_spacing = self.getsize('A')[1] + spacing diff --git a/src/PIL/ImageQt.py b/src/PIL/ImageQt.py index 5ce685916..e60261360 100644 --- a/src/PIL/ImageQt.py +++ b/src/PIL/ImageQt.py @@ -28,7 +28,8 @@ qt_versions = [ ['side', 'PySide'] ] # If a version has already been imported, attempt it first -qt_versions.sort(key=lambda qt_version: qt_version[1] in sys.modules, reverse=True) +qt_versions.sort(key=lambda qt_version: qt_version[1] in sys.modules, + reverse=True) for qt_version, qt_module in qt_versions: try: if qt_module == 'PyQt5': diff --git a/src/PIL/PdfParser.py b/src/PIL/PdfParser.py index 971f44514..e99040bce 100644 --- a/src/PIL/PdfParser.py +++ b/src/PIL/PdfParser.py @@ -450,12 +450,12 @@ class PdfParser: self.pages_ref = self.next_object_id(0) self.rewrite_pages() self.write_obj(self.root_ref, - Type=PdfName(b"Catalog"), - Pages=self.pages_ref) + Type=PdfName(b"Catalog"), + Pages=self.pages_ref) self.write_obj(self.pages_ref, - Type=PdfName(b"Pages"), - Count=len(self.pages), - Kids=self.pages) + Type=PdfName(b"Pages"), + Count=len(self.pages), + Kids=self.pages) return self.root_ref def rewrite_pages(self):