diff --git a/PIL/EpsImagePlugin.py b/PIL/EpsImagePlugin.py index 62e438f0d..e2e7fa5e9 100644 --- a/PIL/EpsImagePlugin.py +++ b/PIL/EpsImagePlugin.py @@ -288,7 +288,7 @@ class EpsImageFile(ImageFile.ImageFile): if s[:11] == "%ImageData:": # Encoded bitmapped image. - [x, y, bi, mo, z3, z4, en, id] = s[11:].split(None, 7) + x, y, bi, mo = s[11:].split(None, 7)[:4] if int(bi) != 8: break diff --git a/PIL/GbrImagePlugin.py b/PIL/GbrImagePlugin.py index 0e686326c..e1580e718 100644 --- a/PIL/GbrImagePlugin.py +++ b/PIL/GbrImagePlugin.py @@ -39,8 +39,8 @@ class GbrImageFile(ImageFile.ImageFile): width = i32(self.fp.read(4)) height = i32(self.fp.read(4)) - bytes = i32(self.fp.read(4)) - if width <= 0 or height <= 0 or bytes != 1: + color_depth = i32(self.fp.read(4)) + if width <= 0 or height <= 0 or color_depth != 1: raise SyntaxError("not a GIMP brush") comment = self.fp.read(header_size - 20)[:-1] diff --git a/PIL/IcnsImagePlugin.py b/PIL/IcnsImagePlugin.py index a1ebee704..1bb1066d8 100644 --- a/PIL/IcnsImagePlugin.py +++ b/PIL/IcnsImagePlugin.py @@ -94,7 +94,7 @@ def read_32(fobj, start_length, size): def read_mk(fobj, start_length, size): # Alpha masks seem to be uncompressed - (start, length) = start_length + start = start_length[0] fobj.seek(start) pixel_size = (size[0] * size[2], size[1] * size[2]) sizesq = pixel_size[0] * pixel_size[1] diff --git a/PIL/ImageFile.py b/PIL/ImageFile.py index 79faff797..01c3e0303 100644 --- a/PIL/ImageFile.py +++ b/PIL/ImageFile.py @@ -322,6 +322,7 @@ class Parser: image = None data = None decoder = None + offset = 0 finished = 0 def reset(self): diff --git a/PIL/JpegImagePlugin.py b/PIL/JpegImagePlugin.py index 0ecc902e4..01a173b5b 100644 --- a/PIL/JpegImagePlugin.py +++ b/PIL/JpegImagePlugin.py @@ -454,13 +454,13 @@ def _getmp(self): data = self.info["mp"] except KeyError: return None - file = io.BytesIO(data) - head = file.read(8) + file_contents = io.BytesIO(data) + head = file_contents.read(8) endianness = '>' if head[:4] == b'\x4d\x4d\x00\x2a' else '<' mp = {} # process dictionary info = TiffImagePlugin.ImageFileDirectory(head) - info.load(file) + info.load(file_contents) for key, value in info.items(): mp[key] = _fixup(value) # it's an error not to have a number of images diff --git a/PIL/MicImagePlugin.py b/PIL/MicImagePlugin.py index d1f8b082a..5aed618ac 100644 --- a/PIL/MicImagePlugin.py +++ b/PIL/MicImagePlugin.py @@ -54,9 +54,9 @@ class MicImageFile(TiffImagePlugin.TiffImageFile): # best way to identify MIC files, but what the... ;-) self.images = [] - for file in self.ole.listdir(): - if file[1:] and file[0][-4:] == ".ACI" and file[1] == "Image": - self.images.append(file) + for path in self.ole.listdir(): + if path[1:] and path[0][-4:] == ".ACI" and path[1] == "Image": + self.images.append(path) # if we didn't find any images, this is probably not # an MIC file. diff --git a/PIL/PyAccess.py b/PIL/PyAccess.py index 87a6d4915..4924facd5 100644 --- a/PIL/PyAccess.py +++ b/PIL/PyAccess.py @@ -194,7 +194,7 @@ class _PyAccessI16_L(PyAccess): pixel = self.pixels[y][x] try: color = min(color, 65535) - except: + except TypeError: color = min(color[0], 65535) pixel.l = color & 0xFF diff --git a/PIL/SpiderImagePlugin.py b/PIL/SpiderImagePlugin.py index 306b348bc..f1ccb67f6 100644 --- a/PIL/SpiderImagePlugin.py +++ b/PIL/SpiderImagePlugin.py @@ -48,7 +48,7 @@ def isInt(f): return 1 else: return 0 - except: + except ValueError: return 0 iforms = [1, 3, -11, -12, -21, -22] @@ -173,11 +173,11 @@ class SpiderImageFile(ImageFile.ImageFile): # returns a byte image after rescaling to 0..255 def convert2byte(self, depth=255): - (min, max) = self.getextrema() + (minimum, maximum) = self.getextrema() m = 1 - if max != min: - m = depth / (max-min) - b = -m * min + if maximum != minimum: + m = depth / (maximum-minimum) + b = -m * minimum return self.point(lambda i, m=m, b=b: i * m + b).convert("L") # returns a ImageTk.PhotoImage object, after rescaling to 0..255 @@ -271,7 +271,7 @@ def _save(im, fp, filename): def _save_spider(im, fp, filename): # get the filename extension and register it with Image - fn, ext = os.path.splitext(filename) + ext = os.path.splitext(filename)[1] Image.register_extension("SPIDER", ext) _save(im, fp, filename) diff --git a/Scripts/enhancer.py b/Scripts/enhancer.py index 34becf873..6393c983f 100644 --- a/Scripts/enhancer.py +++ b/Scripts/enhancer.py @@ -8,9 +8,9 @@ # try: - from tkinter import * + from tkinter import Tk, Toplevel, Frame, Label, Scale, HORIZONTAL except ImportError: - from Tkinter import * + from Tkinter import Tk, Toplevel, Frame, Label, Scale, HORIZONTAL from PIL import Image, ImageTk, ImageEnhance import sys diff --git a/Scripts/painter.py b/Scripts/painter.py index 6f1c19484..234f06171 100644 --- a/Scripts/painter.py +++ b/Scripts/painter.py @@ -10,9 +10,9 @@ # try: - from tkinter import * + from tkinter import Tk, Canvas, NW except ImportError: - from Tkinter import * + from Tkinter import Tk, Canvas, NW from PIL import Image, ImageTk import sys diff --git a/Scripts/viewer.py b/Scripts/viewer.py index c0fc59d96..f9bccec4f 100644 --- a/Scripts/viewer.py +++ b/Scripts/viewer.py @@ -7,9 +7,9 @@ from __future__ import print_function try: - from tkinter import * + from tkinter import Tk, Label except ImportError: - from Tkinter import * + from Tkinter import Tk, Label from PIL import Image, ImageTk diff --git a/Tests/check_jpeg_leaks.py b/Tests/check_jpeg_leaks.py index b8a82a5ec..4d13978f8 100644 --- a/Tests/check_jpeg_leaks.py +++ b/Tests/check_jpeg_leaks.py @@ -169,7 +169,8 @@ post patch: test_output = BytesIO() im.save(test_output, "JPEG", exif=exif) - """ + def test_base_save(self): + """ base case: MB 20.99^ ::::: :::::::::::::::::::::::::::::::::::::::::::@::: @@ -195,8 +196,6 @@ base case: 0 +----------------------------------------------------------------------->Gi 0 7.882 """ - - def test_base_save(self): im = hopper('RGB') for _ in range(iterations): diff --git a/Tests/test_bmp_reference.py b/Tests/test_bmp_reference.py index b45ea76f6..79ad439ba 100644 --- a/Tests/test_bmp_reference.py +++ b/Tests/test_bmp_reference.py @@ -58,10 +58,10 @@ class TestBmpReference(PillowTestCase): } def get_compare(f): - (head, name) = os.path.split(f) + name = os.path.split(f)[1] if name in file_map: return os.path.join(base, 'html', file_map[name]) - (name, ext) = os.path.splitext(name) + name = os.path.splitext(name)[0] return os.path.join(base, 'html', "%s.png" % name) for f in self.get_files('g'): diff --git a/Tests/test_file_fli.py b/Tests/test_file_fli.py index 3580edc18..e6634c799 100644 --- a/Tests/test_file_fli.py +++ b/Tests/test_file_fli.py @@ -5,14 +5,14 @@ from PIL import Image # sample ppm stream # created as an export of a palette image from Gimp2.6 # save as...-> hopper.fli, default options. -file = "Tests/images/hopper.fli" -data = open(file, "rb").read() +test_file = "Tests/images/hopper.fli" +data = open(test_file, "rb").read() class TestFileFli(PillowTestCase): def test_sanity(self): - im = Image.open(file) + im = Image.open(test_file) im.load() self.assertEqual(im.mode, "P") self.assertEqual(im.size, (128, 128)) diff --git a/Tests/test_file_gif.py b/Tests/test_file_gif.py index 2ce728801..1aa8a36bc 100644 --- a/Tests/test_file_gif.py +++ b/Tests/test_file_gif.py @@ -36,9 +36,9 @@ class TestFileGif(PillowTestCase): def test_bilevel(optimize): im = Image.new("1", (1, 1), 0) - file = BytesIO() - im.save(file, "GIF", optimize=optimize) - return len(file.getvalue()) + test_file = BytesIO() + im.save(test_file, "GIF", optimize=optimize) + return len(test_file.getvalue()) self.assertEqual(test_grayscale(0), 800) self.assertEqual(test_grayscale(1), 38) @@ -49,8 +49,8 @@ class TestFileGif(PillowTestCase): from io import BytesIO im = Image.frombytes("L", (16, 16), bytes(bytearray(range(256)))) - file = BytesIO() - im.save(file, "GIF", optimize=True) + test_file = BytesIO() + im.save(test_file, "GIF", optimize=True) self.assertEqual(im.mode, "L") def test_roundtrip(self): diff --git a/Tests/test_file_icns.py b/Tests/test_file_icns.py index 23d22df1b..2edf9dd20 100644 --- a/Tests/test_file_icns.py +++ b/Tests/test_file_icns.py @@ -5,8 +5,8 @@ from PIL import Image import sys # sample icon file -file = "Tests/images/pillow.icns" -data = open(file, "rb").read() +test_file = "Tests/images/pillow.icns" +data = open(test_file, "rb").read() enable_jpeg2k = hasattr(Image.core, 'jp2klib_version') @@ -16,7 +16,7 @@ class TestFileIcns(PillowTestCase): def test_sanity(self): # Loading this icon by default should result in the largest size # (512x512@2x) being loaded - im = Image.open(file) + im = Image.open(test_file) im.load() self.assertEqual(im.mode, "RGBA") self.assertEqual(im.size, (1024, 1024)) @@ -39,11 +39,11 @@ class TestFileIcns(PillowTestCase): def test_sizes(self): # Check that we can load all of the sizes, and that the final pixel # dimensions are as expected - im = Image.open(file) + im = Image.open(test_file) for w, h, r in im.info['sizes']: wr = w * r hr = h * r - im2 = Image.open(file) + im2 = Image.open(test_file) im2.size = (w, h, r) im2.load() self.assertEqual(im2.mode, 'RGBA') diff --git a/Tests/test_file_jpeg.py b/Tests/test_file_jpeg.py index aa24582cc..d4929dd58 100644 --- a/Tests/test_file_jpeg.py +++ b/Tests/test_file_jpeg.py @@ -23,10 +23,10 @@ class TestFileJpeg(PillowTestCase): def roundtrip(self, im, **options): out = BytesIO() im.save(out, "JPEG", **options) - bytes = out.tell() + test_bytes = out.tell() out.seek(0) im = Image.open(out) - im.bytes = bytes # for testing only + im.bytes = test_bytes # for testing only return im def test_sanity(self): diff --git a/Tests/test_file_jpeg2k.py b/Tests/test_file_jpeg2k.py index db67e9551..9768a881d 100644 --- a/Tests/test_file_jpeg2k.py +++ b/Tests/test_file_jpeg2k.py @@ -22,10 +22,10 @@ class TestFileJpeg2k(PillowTestCase): def roundtrip(self, im, **options): out = BytesIO() im.save(out, "JPEG2000", **options) - bytes = out.tell() + test_bytes = out.tell() out.seek(0) im = Image.open(out) - im.bytes = bytes # for testing only + im.bytes = test_bytes # for testing only im.load() return im diff --git a/Tests/test_file_libtiff.py b/Tests/test_file_libtiff.py index 26a30ca30..4f798675b 100644 --- a/Tests/test_file_libtiff.py +++ b/Tests/test_file_libtiff.py @@ -46,8 +46,8 @@ class TestFileLibTiff(LibTiffTestCase): self._assert_noerr(im) def test_g4_large(self): - file = "Tests/images/pport_g4.tif" - im = Image.open(file) + test_file = "Tests/images/pport_g4.tif" + im = Image.open(test_file) self._assert_noerr(im) def test_g4_tiff_file(self): diff --git a/Tests/test_file_libtiff_small.py b/Tests/test_file_libtiff_small.py index cd16292a0..c6a639ae9 100644 --- a/Tests/test_file_libtiff_small.py +++ b/Tests/test_file_libtiff_small.py @@ -18,8 +18,8 @@ class TestFileLibTiffSmall(LibTiffTestCase): def test_g4_hopper_file(self): """Testing the open file load path""" - file = "Tests/images/hopper_g4.tif" - with open(file, 'rb') as f: + test_file = "Tests/images/hopper_g4.tif" + with open(test_file, 'rb') as f: im = Image.open(f) self.assertEqual(im.size, (128, 128)) @@ -28,9 +28,9 @@ class TestFileLibTiffSmall(LibTiffTestCase): def test_g4_hopper_bytesio(self): """Testing the bytesio loading code path""" from io import BytesIO - file = "Tests/images/hopper_g4.tif" + test_file = "Tests/images/hopper_g4.tif" s = BytesIO() - with open(file, 'rb') as f: + with open(test_file, 'rb') as f: s.write(f.read()) s.seek(0) im = Image.open(s) @@ -41,8 +41,8 @@ class TestFileLibTiffSmall(LibTiffTestCase): def test_g4_hopper(self): """The 128x128 lena image failed for some reason.""" - file = "Tests/images/hopper_g4.tif" - im = Image.open(file) + test_file = "Tests/images/hopper_g4.tif" + im = Image.open(test_file) self.assertEqual(im.size, (128, 128)) self._assert_noerr(im) diff --git a/Tests/test_file_mpo.py b/Tests/test_file_mpo.py index 066f39dc4..7850744af 100644 --- a/Tests/test_file_mpo.py +++ b/Tests/test_file_mpo.py @@ -17,10 +17,10 @@ class TestFileMpo(PillowTestCase): # Note that for now, there is no MPO saving functionality out = BytesIO() im.save(out, "MPO", **options) - bytes = out.tell() + test_bytes = out.tell() out.seek(0) im = Image.open(out) - im.bytes = bytes # for testing only + im.bytes = test_bytes # for testing only return im def test_sanity(self): diff --git a/Tests/test_file_pcx.py b/Tests/test_file_pcx.py index 36d6e0315..10d17d349 100644 --- a/Tests/test_file_pcx.py +++ b/Tests/test_file_pcx.py @@ -31,8 +31,8 @@ class TestFilePcx(PillowTestCase): def test_pil184(self): # Check reading of files where xmin/xmax is not zero. - file = "Tests/images/pil184.pcx" - im = Image.open(file) + test_file = "Tests/images/pil184.pcx" + im = Image.open(test_file) self.assertEqual(im.size, (447, 144)) self.assertEqual(im.tile[0][1], (0, 0, 447, 144)) diff --git a/Tests/test_file_png.py b/Tests/test_file_png.py index 505d48c81..b3169ed25 100644 --- a/Tests/test_file_png.py +++ b/Tests/test_file_png.py @@ -19,9 +19,9 @@ MAGIC = PngImagePlugin._MAGIC def chunk(cid, *data): - file = BytesIO() - PngImagePlugin.putchunk(*(file, cid) + data) - return file.getvalue() + test_file = BytesIO() + PngImagePlugin.putchunk(*(test_file, cid) + data) + return test_file.getvalue() o32 = PngImagePlugin.o32 @@ -56,37 +56,37 @@ class TestFilePng(PillowTestCase): self.assertRegexpMatches( Image.core.zlib_version, "\d+\.\d+\.\d+(\.\d+)?$") - file = self.tempfile("temp.png") + test_file = self.tempfile("temp.png") - hopper("RGB").save(file) + hopper("RGB").save(test_file) - im = Image.open(file) + im = Image.open(test_file) im.load() self.assertEqual(im.mode, "RGB") self.assertEqual(im.size, (128, 128)) self.assertEqual(im.format, "PNG") - hopper("1").save(file) - im = Image.open(file) + hopper("1").save(test_file) + im = Image.open(test_file) - hopper("L").save(file) - im = Image.open(file) + hopper("L").save(test_file) + im = Image.open(test_file) - hopper("P").save(file) - im = Image.open(file) + hopper("P").save(test_file) + im = Image.open(test_file) - hopper("RGB").save(file) - im = Image.open(file) + hopper("RGB").save(test_file) + im = Image.open(test_file) - hopper("I").save(file) - im = Image.open(file) + hopper("I").save(test_file) + im = Image.open(test_file) def test_broken(self): # Check reading of totally broken files. In this case, the test # file was checked into Subversion as a text file. - file = "Tests/images/broken.png" - self.assertRaises(IOError, lambda: Image.open(file)) + test_file = "Tests/images/broken.png" + self.assertRaises(IOError, lambda: Image.open(test_file)) def test_bad_text(self): # Make sure PIL can read malformed tEXt chunks (@PIL152) @@ -167,16 +167,16 @@ class TestFilePng(PillowTestCase): def test_interlace(self): - file = "Tests/images/pil123p.png" - im = Image.open(file) + test_file = "Tests/images/pil123p.png" + im = Image.open(test_file) self.assert_image(im, "P", (162, 150)) self.assertTrue(im.info.get("interlace")) im.load() - file = "Tests/images/pil123rgba.png" - im = Image.open(file) + test_file = "Tests/images/pil123rgba.png" + im = Image.open(test_file) self.assert_image(im, "RGBA", (162, 150)) self.assertTrue(im.info.get("interlace")) @@ -184,8 +184,8 @@ class TestFilePng(PillowTestCase): im.load() def test_load_transparent_p(self): - file = "Tests/images/pil123p.png" - im = Image.open(file) + test_file = "Tests/images/pil123p.png" + im = Image.open(test_file) self.assert_image(im, "P", (162, 150)) im = im.convert("RGBA") @@ -195,8 +195,8 @@ class TestFilePng(PillowTestCase): self.assertEqual(len(im.split()[3].getcolors()), 124) def test_load_transparent_rgb(self): - file = "Tests/images/rgb_trns.png" - im = Image.open(file) + test_file = "Tests/images/rgb_trns.png" + im = Image.open(test_file) self.assert_image(im, "RGB", (64, 64)) im = im.convert("RGBA") @@ -209,22 +209,22 @@ class TestFilePng(PillowTestCase): in_file = "Tests/images/pil123p.png" im = Image.open(in_file) - file = self.tempfile("temp.png") - im.save(file) + test_file = self.tempfile("temp.png") + im.save(test_file) def test_save_p_single_transparency(self): in_file = "Tests/images/p_trns_single.png" im = Image.open(in_file) - file = self.tempfile("temp.png") - im.save(file) + test_file = self.tempfile("temp.png") + im.save(test_file) def test_save_l_transparency(self): in_file = "Tests/images/l_trns.png" im = Image.open(in_file) - file = self.tempfile("temp.png") - im.save(file) + test_file = self.tempfile("temp.png") + im.save(test_file) # There are 559 transparent pixels. im = im.convert('RGBA') @@ -234,8 +234,8 @@ class TestFilePng(PillowTestCase): in_file = "Tests/images/caption_6_33_22.png" im = Image.open(in_file) - file = self.tempfile("temp.png") - im.save(file) + test_file = self.tempfile("temp.png") + im.save(test_file) def test_load_verify(self): # Check open/load/verify exception (@PIL150) @@ -329,8 +329,8 @@ class TestFilePng(PillowTestCase): # Check writing and reading of tRNS chunks for RGB images. # Independent file sample provided by Sebastian Spaeth. - file = "Tests/images/caption_6_33_22.png" - im = Image.open(file) + test_file = "Tests/images/caption_6_33_22.png" + im = Image.open(test_file) self.assertEqual(im.info["transparency"], (248, 248, 248)) # check saving transparency by default diff --git a/Tests/test_file_ppm.py b/Tests/test_file_ppm.py index 3731fd9b1..80c2e60da 100644 --- a/Tests/test_file_ppm.py +++ b/Tests/test_file_ppm.py @@ -3,14 +3,14 @@ from helper import unittest, PillowTestCase from PIL import Image # sample ppm stream -file = "Tests/images/hopper.ppm" -data = open(file, "rb").read() +test_file = "Tests/images/hopper.ppm" +data = open(test_file, "rb").read() class TestFilePpm(PillowTestCase): def test_sanity(self): - im = Image.open(file) + im = Image.open(test_file) im.load() self.assertEqual(im.mode, "RGB") self.assertEqual(im.size, (128, 128)) diff --git a/Tests/test_file_psd.py b/Tests/test_file_psd.py index 46cef4c78..51b8cf3f4 100644 --- a/Tests/test_file_psd.py +++ b/Tests/test_file_psd.py @@ -3,14 +3,14 @@ from helper import unittest, PillowTestCase from PIL import Image # sample ppm stream -file = "Tests/images/hopper.psd" -data = open(file, "rb").read() +test_file = "Tests/images/hopper.psd" +data = open(test_file, "rb").read() class TestImagePsd(PillowTestCase): def test_sanity(self): - im = Image.open(file) + im = Image.open(test_file) im.load() self.assertEqual(im.mode, "RGB") self.assertEqual(im.size, (128, 128)) diff --git a/Tests/test_file_webp_metadata.py b/Tests/test_file_webp_metadata.py index 9093f31ba..8b1254d61 100644 --- a/Tests/test_file_webp_metadata.py +++ b/Tests/test_file_webp_metadata.py @@ -41,12 +41,12 @@ class TestFileWebpMetadata(PillowTestCase): image = Image.open(file_path) expected_exif = image.info['exif'] - buffer = BytesIO() + test_buffer = BytesIO() - image.save(buffer, "webp", exif=expected_exif) + image.save(test_buffer, "webp", exif=expected_exif) - buffer.seek(0) - webp_image = Image.open(buffer) + test_buffer.seek(0) + webp_image = Image.open(test_buffer) webp_exif = webp_image.info.get('exif', None) self.assertTrue(webp_exif) @@ -76,12 +76,12 @@ class TestFileWebpMetadata(PillowTestCase): image = Image.open(file_path) expected_icc_profile = image.info['icc_profile'] - buffer = BytesIO() + test_buffer = BytesIO() - image.save(buffer, "webp", icc_profile=expected_icc_profile) + image.save(test_buffer, "webp", icc_profile=expected_icc_profile) - buffer.seek(0) - webp_image = Image.open(buffer) + test_buffer.seek(0) + webp_image = Image.open(test_buffer) webp_icc_profile = webp_image.info.get('icc_profile', None) @@ -98,12 +98,12 @@ class TestFileWebpMetadata(PillowTestCase): image = Image.open(file_path) self.assertTrue('exif' in image.info) - buffer = BytesIO() + test_buffer = BytesIO() - image.save(buffer, "webp") + image.save(test_buffer, "webp") - buffer.seek(0) - webp_image = Image.open(buffer) + test_buffer.seek(0) + webp_image = Image.open(test_buffer) self.assertFalse(webp_image._getexif()) diff --git a/Tests/test_font_bdf.py b/Tests/test_font_bdf.py index 0df8e866b..b844f1228 100644 --- a/Tests/test_font_bdf.py +++ b/Tests/test_font_bdf.py @@ -9,8 +9,8 @@ class TestFontBdf(PillowTestCase): def test_sanity(self): - file = open(filename, "rb") - font = BdfFontFile.BdfFontFile(file) + test_file = open(filename, "rb") + font = BdfFontFile.BdfFontFile(test_file) self.assertIsInstance(font, FontFile.FontFile) self.assertEqual(len([_f for _f in font.glyph if _f]), 190) diff --git a/Tests/test_font_pcf.py b/Tests/test_font_pcf.py index 5e9e02c8c..3cc6afa64 100644 --- a/Tests/test_font_pcf.py +++ b/Tests/test_font_pcf.py @@ -17,8 +17,8 @@ class TestFontPcf(PillowTestCase): self.skipTest("zlib support not available") def save_font(self): - file = open(fontname, "rb") - font = PcfFontFile.PcfFontFile(file) + test_file = open(fontname, "rb") + font = PcfFontFile.PcfFontFile(test_file) self.assertIsInstance(font, FontFile.FontFile) self.assertEqual(len([_f for _f in font.glyph if _f]), 192) diff --git a/Tests/test_image.py b/Tests/test_image.py index 0b84de630..caee70fec 100644 --- a/Tests/test_image.py +++ b/Tests/test_image.py @@ -41,8 +41,8 @@ class TestImage(PillowTestCase): im.paste(0, (0, 0, 100, 100)) self.assertFalse(im.readonly) - file = self.tempfile("temp.ppm") - im._dump(file) + test_file = self.tempfile("temp.ppm") + im._dump(test_file) def test_comparison_with_other_type(self): # Arrange diff --git a/Tests/test_image_filter.py b/Tests/test_image_filter.py index d29fd3dfd..6a694b3ca 100644 --- a/Tests/test_image_filter.py +++ b/Tests/test_image_filter.py @@ -76,10 +76,10 @@ class TestImageFilter(PillowTestCase): # 0 1 2 # 3 4 5 # 6 7 8 - min = im.filter(ImageFilter.MinFilter).getpixel((1, 1)) + minimum = im.filter(ImageFilter.MinFilter).getpixel((1, 1)) med = im.filter(ImageFilter.MedianFilter).getpixel((1, 1)) - max = im.filter(ImageFilter.MaxFilter).getpixel((1, 1)) - return min, med, max + maximum = im.filter(ImageFilter.MaxFilter).getpixel((1, 1)) + return minimum, med, maximum self.assertEqual(rankfilter("1"), (0, 4, 8)) self.assertEqual(rankfilter("L"), (0, 4, 8)) diff --git a/Tests/test_image_split.py b/Tests/test_image_split.py index 0e057523b..beab7b546 100644 --- a/Tests/test_image_split.py +++ b/Tests/test_image_split.py @@ -45,13 +45,13 @@ class TestImageSplit(PillowTestCase): codecs = dir(Image.core) if 'zip_encoder' in codecs: - file = self.tempfile("temp.png") + test_file = self.tempfile("temp.png") else: - file = self.tempfile("temp.pcx") + test_file = self.tempfile("temp.pcx") def split_open(mode): - hopper(mode).save(file) - im = Image.open(file) + hopper(mode).save(test_file) + im = Image.open(test_file) return len(im.split()) self.assertEqual(split_open("1"), 1) self.assertEqual(split_open("L"), 1) diff --git a/Tests/test_image_transpose.py b/Tests/test_image_transpose.py index 3069df61c..e13fc8605 100644 --- a/Tests/test_image_transpose.py +++ b/Tests/test_image_transpose.py @@ -1,4 +1,5 @@ -from helper import unittest, PillowTestCase, hopper +import helper +from helper import unittest, PillowTestCase from PIL.Image import (FLIP_LEFT_RIGHT, FLIP_TOP_BOTTOM, ROTATE_90, ROTATE_180, ROTATE_270, TRANSPOSE) @@ -7,8 +8,8 @@ from PIL.Image import (FLIP_LEFT_RIGHT, FLIP_TOP_BOTTOM, ROTATE_90, ROTATE_180, class TestImageTranspose(PillowTestCase): hopper = { - 'L': hopper('L').crop((0, 0, 121, 127)).copy(), - 'RGB': hopper('RGB').crop((0, 0, 121, 127)).copy(), + 'L': helper.hopper('L').crop((0, 0, 121, 127)).copy(), + 'RGB': helper.hopper('RGB').crop((0, 0, 121, 127)).copy(), } def test_flip_left_right(self): diff --git a/Tests/test_imagefile.py b/Tests/test_imagefile.py index 01503dff7..5311b899f 100644 --- a/Tests/test_imagefile.py +++ b/Tests/test_imagefile.py @@ -24,11 +24,11 @@ class TestImageFile(PillowTestCase): if format in ("MSP", "XBM"): im = im.convert("1") - file = BytesIO() + test_file = BytesIO() - im.save(file, format) + im.save(test_file, format) - data = file.getvalue() + data = test_file.getvalue() parser = ImageFile.Parser() parser.feed(data) diff --git a/Tests/test_imagefont.py b/Tests/test_imagefont.py index 627b28c67..f1d59ae43 100644 --- a/Tests/test_imagefont.py +++ b/Tests/test_imagefont.py @@ -94,7 +94,8 @@ try: def _render(self, font): txt = "Hello World!" ttf = ImageFont.truetype(font, FONT_SIZE) - w, h = ttf.getsize(txt) + ttf.getsize(txt) + img = Image.new("RGB", (256, 64), "white") d = ImageDraw.Draw(img) d.text((10, 10), txt, font=ttf, fill='black') diff --git a/Tests/test_imagepalette.py b/Tests/test_imagepalette.py index a16b590ba..707ab4080 100644 --- a/Tests/test_imagepalette.py +++ b/Tests/test_imagepalette.py @@ -17,11 +17,11 @@ class TestImagePalette(PillowTestCase): palette = ImagePalette() - map = {} + test_map = {} for i in range(256): - map[palette.getcolor((i, i, i))] = i + test_map[palette.getcolor((i, i, i))] = i - self.assertEqual(len(map), 256) + self.assertEqual(len(test_map), 256) self.assertRaises(ValueError, lambda: palette.getcolor((1, 2, 3))) def test_file(self): diff --git a/Tests/test_imagesequence.py b/Tests/test_imagesequence.py index 459a053d8..1b4bb3c02 100644 --- a/Tests/test_imagesequence.py +++ b/Tests/test_imagesequence.py @@ -7,10 +7,10 @@ class TestImageSequence(PillowTestCase): def test_sanity(self): - file = self.tempfile("temp.im") + test_file = self.tempfile("temp.im") im = hopper("RGB") - im.save(file) + im.save(test_file) seq = ImageSequence.Iterator(im) diff --git a/Tests/test_imagewin.py b/Tests/test_imagewin.py index c32290e43..7ceea86ee 100644 --- a/Tests/test_imagewin.py +++ b/Tests/test_imagewin.py @@ -100,8 +100,8 @@ class TestImageWinDib(PillowTestCase): # Act # Make one the same as the using tobytes()/frombytes() - buffer = dib1.tobytes() - dib2.frombytes(buffer) + test_buffer = dib1.tobytes() + dib2.frombytes(test_buffer) # Assert # Confirm they're the same @@ -111,11 +111,11 @@ class TestImageWinDib(PillowTestCase): # Arrange im = hopper() dib = ImageWin.Dib(im) - buffer = dib.tobytes() + test_buffer = dib.tobytes() # Act/Assert self.assert_warning(DeprecationWarning, dib.tostring) - self.assert_warning(DeprecationWarning, lambda: dib.fromstring(buffer)) + self.assert_warning(DeprecationWarning, lambda: dib.fromstring(test_buffer)) if __name__ == '__main__': diff --git a/Tests/test_mode_i16.py b/Tests/test_mode_i16.py index 20e39b235..0827e218b 100644 --- a/Tests/test_mode_i16.py +++ b/Tests/test_mode_i16.py @@ -64,15 +64,15 @@ class TestModeI16(PillowTestCase): self.assertEqual(imIn.getpixel((0, 0)), 2) if mode == "L": - max = 255 + maximum = 255 else: - max = 32767 + maximum = 32767 imIn = Image.new(mode, (1, 1), 256) - self.assertEqual(imIn.getpixel((0, 0)), min(256, max)) + self.assertEqual(imIn.getpixel((0, 0)), min(256, maximum)) imIn.putpixel((0, 0), 512) - self.assertEqual(imIn.getpixel((0, 0)), min(512, max)) + self.assertEqual(imIn.getpixel((0, 0)), min(512, maximum)) basic("L") diff --git a/Tests/test_pickle.py b/Tests/test_pickle.py index f1c594be9..52d64acee 100644 --- a/Tests/test_pickle.py +++ b/Tests/test_pickle.py @@ -60,7 +60,7 @@ class TestPickle(PillowTestCase): import pickle # Act / Assert - for file in [ + for test_file in [ "Tests/images/test-card.png", "Tests/images/zero_bb.png", "Tests/images/zero_bb_scale2.png", @@ -69,7 +69,7 @@ class TestPickle(PillowTestCase): "Tests/images/p_trns_single.png", "Tests/images/pil123p.png" ]: - self.helper_pickle_string(pickle, file=file) + self.helper_pickle_string(pickle, file=test_file) def test_pickle_l_mode(self): # Arrange diff --git a/Tests/threaded_save.py b/Tests/threaded_save.py index 376abe7bd..3bcbdd0b0 100644 --- a/Tests/threaded_save.py +++ b/Tests/threaded_save.py @@ -6,10 +6,7 @@ import sys import threading import time -try: - format = sys.argv[1] -except: - format = "PNG" +test_format = sys.argv[1] if len(sys.argv) > 1 else "PNG" im = Image.open("Tests/images/hopper.ppm") im.load() @@ -28,7 +25,7 @@ class Worker(threading.Thread): sys.stdout.write("x") break f = io.BytesIO() - im.save(f, format, optimize=1) + im.save(f, test_format, optimize=1) data = f.getvalue() result.append(len(data)) im = Image.open(io.BytesIO(data))