From 901c1e2aea0a080d50cfe26e81511bf8e8db155e Mon Sep 17 00:00:00 2001 From: Hugo Date: Sat, 4 Aug 2018 20:46:03 +0300 Subject: [PATCH 01/12] Simplify test skipping --- Tests/test_file_webp_alpha.py | 9 ++------- Tests/test_imagetk.py | 3 +-- Tests/test_pyroma.py | 2 +- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/Tests/test_file_webp_alpha.py b/Tests/test_file_webp_alpha.py index 60a324d18..85682e382 100644 --- a/Tests/test_file_webp_alpha.py +++ b/Tests/test_file_webp_alpha.py @@ -5,18 +5,13 @@ from PIL import Image try: from PIL import _webp except ImportError: - pass - # Skip in setUp() + _webp = None +@unittest.skipIf(_webp is None, "WebP support not installed") class TestFileWebpAlpha(PillowTestCase): def setUp(self): - try: - from PIL import _webp - except ImportError: - self.skipTest('WebP support not installed') - if _webp.WebPDecoderBuggyAlpha(self): self.skipTest("Buggy early version of WebP installed, " "not testing transparency") diff --git a/Tests/test_imagetk.py b/Tests/test_imagetk.py index 14ce74eb1..aec7429ce 100644 --- a/Tests/test_imagetk.py +++ b/Tests/test_imagetk.py @@ -18,11 +18,10 @@ except (OSError, ImportError) as v: TK_MODES = ('1', 'L', 'P', 'RGB', 'RGBA') +@unittest.skipIf(not HAS_TK, "Tk not installed") class TestImageTk(PillowTestCase): def setUp(self): - if not HAS_TK: - self.skipTest("Tk not installed") try: # setup tk tk.Frame() diff --git a/Tests/test_pyroma.py b/Tests/test_pyroma.py index e147161a7..8d23d024b 100644 --- a/Tests/test_pyroma.py +++ b/Tests/test_pyroma.py @@ -8,9 +8,9 @@ except ImportError: pyroma = None +@unittest.skipIf(pyroma is None, "Pyroma is not installed") class TestPyroma(PillowTestCase): - @unittest.skipUnless(pyroma, "Pyroma is not installed") def test_pyroma(self): # Arrange data = pyroma.projectdata.get_data(".") From d1ca4916e009cf13428347bdb97ea3ceabfd3276 Mon Sep 17 00:00:00 2001 From: Hugo Date: Sat, 4 Aug 2018 21:08:40 +0300 Subject: [PATCH 02/12] Use more specific assertions --- Tests/helper.py | 4 ++-- Tests/test_file_libtiff.py | 4 ++-- Tests/test_image.py | 2 +- Tests/test_image_convert.py | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Tests/helper.py b/Tests/helper.py index 8fb34848b..030335745 100644 --- a/Tests/helper.py +++ b/Tests/helper.py @@ -187,10 +187,10 @@ class PillowTestCase(unittest.TestCase): return result def assert_all_same(self, items, msg=None): - self.assertTrue(items.count(items[0]) == len(items), msg) + self.assertEqual(items.count(items[0]), len(items), msg) def assert_not_all_same(self, items, msg=None): - self.assertFalse(items.count(items[0]) == len(items), msg) + self.assertNotEqual(items.count(items[0]), len(items), msg) def assert_tuple_approx_equal(self, actuals, targets, threshold, msg): """Tests if actuals has values within threshold from targets""" diff --git a/Tests/test_file_libtiff.py b/Tests/test_file_libtiff.py index ddd39ba8c..5b0b0c46b 100644 --- a/Tests/test_file_libtiff.py +++ b/Tests/test_file_libtiff.py @@ -545,11 +545,11 @@ class TestFileLibTiff(LibTiffTestCase): def test_read_icc(self): with Image.open("Tests/images/hopper.iccprofile.tif") as img: icc = img.info.get('icc_profile') - self.assertNotEqual(icc, None) + self.assertIsNotNone(icc) TiffImagePlugin.READ_LIBTIFF = True with Image.open("Tests/images/hopper.iccprofile.tif") as img: icc_libtiff = img.info.get('icc_profile') - self.assertNotEqual(icc_libtiff, None) + self.assertIsNotNone(icc_libtiff) TiffImagePlugin.READ_LIBTIFF = False self.assertEqual(icc, icc_libtiff) diff --git a/Tests/test_image.py b/Tests/test_image.py index ad56a079a..715c588da 100644 --- a/Tests/test_image.py +++ b/Tests/test_image.py @@ -516,7 +516,7 @@ class TestImage(PillowTestCase): self.assertEqual(new_im.palette.tobytes(), palette_result.tobytes()) else: - self.assertEqual(new_im.palette, None) + self.assertIsNone(new_im.palette) _make_new(im, im_p, im_p.palette) _make_new(im_p, im, None) diff --git a/Tests/test_image_convert.py b/Tests/test_image_convert.py index 1b3815d80..e57ae4305 100644 --- a/Tests/test_image_convert.py +++ b/Tests/test_image_convert.py @@ -88,7 +88,7 @@ class TestImageConvert(PillowTestCase): # Assert self.assertNotIn('transparency', im_rgba.info) # https://github.com/python-pillow/Pillow/issues/2702 - self.assertEqual(im_rgba.palette, None) + self.assertIsNone(im_rgba.palette) def test_trns_l(self): im = hopper('L') From a3b06597903f556c4e2d1e5ea71ec114450a16e1 Mon Sep 17 00:00:00 2001 From: Hugo Date: Mon, 1 Oct 2018 13:22:18 +0300 Subject: [PATCH 03/12] flake8 --- Tests/helper.py | 2 +- Tests/test_file_libtiff.py | 2 +- Tests/test_image.py | 2 +- Tests/test_imagetk.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Tests/helper.py b/Tests/helper.py index 030335745..d2bcbb7f9 100644 --- a/Tests/helper.py +++ b/Tests/helper.py @@ -110,7 +110,7 @@ class PillowTestCase(unittest.TestCase): try: url = test_image_results.upload(a, b) logger.error("Url for test images: %s" % url) - except Exception as msg: + except Exception: pass self.fail(msg or "got different content") diff --git a/Tests/test_file_libtiff.py b/Tests/test_file_libtiff.py index 5b0b0c46b..58a3d38c5 100644 --- a/Tests/test_file_libtiff.py +++ b/Tests/test_file_libtiff.py @@ -415,7 +415,7 @@ class TestFileLibTiff(LibTiffTestCase): im = Image.open('Tests/images/multipage.tiff') frames = im.n_frames self.assertEqual(frames, 3) - for idx in range(frames): + for _ in range(frames): im.seek(0) # Should not raise ValueError: I/O operation on closed file im.load() diff --git a/Tests/test_image.py b/Tests/test_image.py index 715c588da..3d7e4dc4d 100644 --- a/Tests/test_image.py +++ b/Tests/test_image.py @@ -56,7 +56,7 @@ class TestImage(PillowTestCase): self.assertEqual(im.width, 1) self.assertEqual(im.height, 2) - with self.assertRaises(AttributeError) as e: + with self.assertRaises(AttributeError): im.size = (3, 4) def test_invalid_image(self): diff --git a/Tests/test_imagetk.py b/Tests/test_imagetk.py index aec7429ce..72ca91ca2 100644 --- a/Tests/test_imagetk.py +++ b/Tests/test_imagetk.py @@ -11,7 +11,7 @@ try: import Tkinter as tk dir(ImageTk) HAS_TK = True -except (OSError, ImportError) as v: +except (OSError, ImportError): # Skipped via setUp() HAS_TK = False From bab194b6f599bbec4c06421b24c31bdd2d13e694 Mon Sep 17 00:00:00 2001 From: Hugo Date: Tue, 2 Oct 2018 10:57:07 +0300 Subject: [PATCH 04/12] Fix DeprecationWarning: invalid escape sequence --- Tests/test_image_resample.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/test_image_resample.py b/Tests/test_image_resample.py index 1b7081d55..226e7873a 100644 --- a/Tests/test_image_resample.py +++ b/Tests/test_image_resample.py @@ -453,7 +453,7 @@ class CoreResampleBoxTest(PillowTestCase): # error with box should be much smaller than without self.assert_image_similar(reference, with_box, 6) - with self.assertRaisesRegex(AssertionError, "difference 29\."): + with self.assertRaisesRegex(AssertionError, r"difference 29\."): self.assert_image_similar(reference, without_box, 5) def test_formats(self): @@ -496,7 +496,7 @@ class CoreResampleBoxTest(PillowTestCase): try: res = im.resize(size, Image.LANCZOS, box) self.assertEqual(res.size, size) - with self.assertRaisesRegex(AssertionError, "difference \d"): + with self.assertRaisesRegex(AssertionError, r"difference \d"): # check that the difference at least that much self.assert_image_similar(res, im.crop(box), 20) except AssertionError: From cb8a4bac21d84a356bbb90fbb58643460b7e3a57 Mon Sep 17 00:00:00 2001 From: Hugo Date: Tue, 2 Oct 2018 11:22:00 +0300 Subject: [PATCH 05/12] Use set literal --- Tests/test_file_ico.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/test_file_ico.py b/Tests/test_file_ico.py index d3024ee90..e1ec27932 100644 --- a/Tests/test_file_ico.py +++ b/Tests/test_file_ico.py @@ -28,7 +28,7 @@ class TestFileIco(PillowTestCase): # the default image output.seek(0) reloaded = Image.open(output) - self.assertEqual(reloaded.info['sizes'], set([(32, 32), (64, 64)])) + self.assertEqual(reloaded.info['sizes'], {(32, 32), (64, 64)}) self.assertEqual(im.mode, reloaded.mode) self.assertEqual((64, 64), reloaded.size) @@ -81,7 +81,7 @@ class TestFileIco(PillowTestCase): # Assert self.assertEqual( im_saved.info['sizes'], - set([(16, 16), (24, 24), (32, 32), (48, 48)])) + {(16, 16), (24, 24), (32, 32), (48, 48)}) if __name__ == '__main__': From fc3a159c87ed0354330e5da8fa8238ac0477c817 Mon Sep 17 00:00:00 2001 From: Hugo Date: Tue, 2 Oct 2018 11:36:07 +0300 Subject: [PATCH 06/12] More specific exception clause --- Tests/test_features.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/test_features.py b/Tests/test_features.py index 312894cb4..03ad0d4c9 100644 --- a/Tests/test_features.py +++ b/Tests/test_features.py @@ -5,7 +5,7 @@ from PIL import features try: from PIL import _webp HAVE_WEBP = True -except: +except ImportError: HAVE_WEBP = False From 4352edb1ec9f7eb90684b60fd4b09d60a20150f0 Mon Sep 17 00:00:00 2001 From: Hugo Date: Tue, 2 Oct 2018 11:37:10 +0300 Subject: [PATCH 07/12] Assert all images in loop --- Tests/test_file_eps.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Tests/test_file_eps.py b/Tests/test_file_eps.py index 66fedee90..9d650e968 100644 --- a/Tests/test_file_eps.py +++ b/Tests/test_file_eps.py @@ -228,12 +228,10 @@ class TestFileEps(PillowTestCase): "Tests/images/illuCS6_no_preview.eps", "Tests/images/illuCS6_preview.eps"] - # Act + # Act / Assert for filename in FILES: img = Image.open(filename) - - # Assert - self.assertEqual(img.mode, "RGB") + self.assertEqual(img.mode, "RGB") def test_emptyline(self): # Test file includes an empty line in the header data From bac99bd5ae2c0e8746ee40d71b3bd724e594e677 Mon Sep 17 00:00:00 2001 From: Hugo Date: Tue, 2 Oct 2018 11:44:06 +0300 Subject: [PATCH 08/12] Add assert for previously unused 'lut' variable --- Tests/test_color_lut.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Tests/test_color_lut.py b/Tests/test_color_lut.py index ec370f70a..6c8a185df 100644 --- a/Tests/test_color_lut.py +++ b/Tests/test_color_lut.py @@ -294,6 +294,8 @@ class TestColorLut3DFilter(PillowTestCase): lut = ImageFilter.Color3DLUT((2, 2, 2), [(0, 1, 2, 3)] * 8, channels=4) + self.assertEqual(tuple(lut.size), (2, 2, 2)) + self.assertEqual(lut.table, list(range(4)) * 8) @unittest.skipIf(numpy is None, "Numpy is not installed") def test_numpy_sources(self): From 619e5fde8d1f78ce35e5811bf275fdafcd69b625 Mon Sep 17 00:00:00 2001 From: Hugo Date: Tue, 2 Oct 2018 11:44:43 +0300 Subject: [PATCH 09/12] Remove unused local variables --- Tests/helper.py | 1 - Tests/test_000_sanity.py | 12 ++++++------ Tests/test_file_png.py | 10 +++++----- Tests/test_file_tiff.py | 10 +++++----- Tests/test_imagefile.py | 4 ++-- Tests/test_qt_image_toqimage.py | 2 +- 6 files changed, 19 insertions(+), 20 deletions(-) diff --git a/Tests/helper.py b/Tests/helper.py index d2bcbb7f9..8905e4009 100644 --- a/Tests/helper.py +++ b/Tests/helper.py @@ -163,7 +163,6 @@ class PillowTestCase(unittest.TestCase): def assert_warning(self, warn_class, func, *args, **kwargs): import warnings - result = None with warnings.catch_warnings(record=True) as w: # Cause all warnings to always be triggered. warnings.simplefilter("always") diff --git a/Tests/test_000_sanity.py b/Tests/test_000_sanity.py index 67aff8ecc..62a9b5870 100644 --- a/Tests/test_000_sanity.py +++ b/Tests/test_000_sanity.py @@ -9,7 +9,7 @@ class TestSanity(PillowTestCase): def test_sanity(self): # Make sure we have the binary extension - im = PIL.Image.core.new("L", (100, 100)) + PIL.Image.core.new("L", (100, 100)) self.assertEqual(PIL.Image.VERSION[:3], '1.1') @@ -19,11 +19,11 @@ class TestSanity(PillowTestCase): self.assertEqual(len(im.tobytes()), 1300) # Create images in all remaining major modes. - im = PIL.Image.new("L", (100, 100)) - im = PIL.Image.new("P", (100, 100)) - im = PIL.Image.new("RGB", (100, 100)) - im = PIL.Image.new("I", (100, 100)) - im = PIL.Image.new("F", (100, 100)) + PIL.Image.new("L", (100, 100)) + PIL.Image.new("P", (100, 100)) + PIL.Image.new("RGB", (100, 100)) + PIL.Image.new("I", (100, 100)) + PIL.Image.new("F", (100, 100)) if __name__ == '__main__': diff --git a/Tests/test_file_png.py b/Tests/test_file_png.py index e9dcd5203..c958c0b39 100644 --- a/Tests/test_file_png.py +++ b/Tests/test_file_png.py @@ -82,19 +82,19 @@ class TestFilePng(PillowTestCase): self.assertEqual(im.format, "PNG") hopper("1").save(test_file) - im = Image.open(test_file) + Image.open(test_file) hopper("L").save(test_file) - im = Image.open(test_file) + Image.open(test_file) hopper("P").save(test_file) - im = Image.open(test_file) + Image.open(test_file) hopper("RGB").save(test_file) - im = Image.open(test_file) + Image.open(test_file) hopper("I").save(test_file) - im = Image.open(test_file) + Image.open(test_file) def test_invalid_file(self): invalid_file = "Tests/images/flower.jpg" diff --git a/Tests/test_file_tiff.py b/Tests/test_file_tiff.py index 96ad05933..b4a1221c4 100644 --- a/Tests/test_file_tiff.py +++ b/Tests/test_file_tiff.py @@ -26,19 +26,19 @@ class TestFileTiff(PillowTestCase): self.assertEqual(im.format, "TIFF") hopper("1").save(filename) - im = Image.open(filename) + Image.open(filename) hopper("L").save(filename) - im = Image.open(filename) + Image.open(filename) hopper("P").save(filename) - im = Image.open(filename) + Image.open(filename) hopper("RGB").save(filename) - im = Image.open(filename) + Image.open(filename) hopper("I").save(filename) - im = Image.open(filename) + Image.open(filename) def test_mac_tiff(self): # Read RGBa images from macOS [@PIL136] diff --git a/Tests/test_imagefile.py b/Tests/test_imagefile.py index c95611b08..8a8cdb64b 100644 --- a/Tests/test_imagefile.py +++ b/Tests/test_imagefile.py @@ -204,7 +204,7 @@ class TestPyDecoder(PillowTestCase): im = MockImageFile(buf) im.tile = [("MOCK", (xoff, yoff, -10, yoff+ysize), 32, None)] - d = self.get_decoder() + self.get_decoder() self.assertRaises(ValueError, im.load) @@ -218,7 +218,7 @@ class TestPyDecoder(PillowTestCase): im.tile = [ ("MOCK", (xoff, yoff, xoff+xsize + 100, yoff+ysize), 32, None) ] - d = self.get_decoder() + self.get_decoder() self.assertRaises(ValueError, im.load) diff --git a/Tests/test_qt_image_toqimage.py b/Tests/test_qt_image_toqimage.py index 28871d201..b9d095cd9 100644 --- a/Tests/test_qt_image_toqimage.py +++ b/Tests/test_qt_image_toqimage.py @@ -86,7 +86,7 @@ if ImageQt.qt_is_installed: pixmap1 = QtGui.QPixmap.fromImage(qimage) - hbox = QHBoxLayout(self) + QHBoxLayout(self) lbl = QLabel(self) # Segfault in the problem From d69ef6a529723649446c679ebf8cb128abb7f352 Mon Sep 17 00:00:00 2001 From: Hugo Date: Tue, 2 Oct 2018 11:55:28 +0300 Subject: [PATCH 10/12] Remove redundant parentheses --- Tests/check_large_memory.py | 2 +- Tests/test_file_webp_lossless.py | 2 +- Tests/test_image.py | 4 ++-- Tests/test_image_getdata.py | 2 +- Tests/test_image_getextrema.py | 2 +- Tests/test_image_resample.py | 2 +- Tests/test_imagedraw.py | 4 ++-- Tests/test_imagefile.py | 2 +- Tests/test_imagetk.py | 2 +- Tests/test_lib_pack.py | 4 ++-- Tests/test_qt_image_toqimage.py | 4 ++-- 11 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Tests/check_large_memory.py b/Tests/check_large_memory.py index ef0cd1f80..5c8dc10f7 100644 --- a/Tests/check_large_memory.py +++ b/Tests/check_large_memory.py @@ -21,7 +21,7 @@ class LargeMemoryTest(PillowTestCase): def _write_png(self, xdim, ydim): f = self.tempfile('temp.png') - im = Image.new('L', (xdim, ydim), (0)) + im = Image.new('L', (xdim, ydim), 0) im.save(f) def test_large(self): diff --git a/Tests/test_file_webp_lossless.py b/Tests/test_file_webp_lossless.py index 4c35dad73..4d9eff7f1 100644 --- a/Tests/test_file_webp_lossless.py +++ b/Tests/test_file_webp_lossless.py @@ -16,7 +16,7 @@ class TestFileWebpLossless(PillowTestCase): self.skipTest('WebP support not installed') return - if (_webp.WebPDecoderVersion() < 0x0200): + if _webp.WebPDecoderVersion() < 0x0200: self.skipTest('lossless not included') self.rgb_mode = "RGB" diff --git a/Tests/test_image.py b/Tests/test_image.py index 3d7e4dc4d..73f391734 100644 --- a/Tests/test_image.py +++ b/Tests/test_image.py @@ -286,9 +286,9 @@ class TestImage(PillowTestCase): source.alpha_composite, over, (0, 0), "invalid destination") self.assertRaises(ValueError, - source.alpha_composite, over, (0)) + source.alpha_composite, over, 0) self.assertRaises(ValueError, - source.alpha_composite, over, (0, 0), (0)) + source.alpha_composite, over, (0, 0), 0) self.assertRaises(ValueError, source.alpha_composite, over, (0, -1)) self.assertRaises(ValueError, diff --git a/Tests/test_image_getdata.py b/Tests/test_image_getdata.py index ef07844df..de502065b 100644 --- a/Tests/test_image_getdata.py +++ b/Tests/test_image_getdata.py @@ -23,7 +23,7 @@ class TestImageGetData(PillowTestCase): self.assertEqual(getdata("L"), (16, 960, 960)) self.assertEqual(getdata("I"), (16, 960, 960)) self.assertEqual(getdata("F"), (16.0, 960, 960)) - self.assertEqual(getdata("RGB"), (((11, 13, 52), 960, 960))) + self.assertEqual(getdata("RGB"), ((11, 13, 52), 960, 960)) self.assertEqual(getdata("RGBA"), ((11, 13, 52, 255), 960, 960)) self.assertEqual(getdata("CMYK"), ((244, 242, 203, 0), 960, 960)) self.assertEqual(getdata("YCbCr"), ((16, 147, 123), 960, 960)) diff --git a/Tests/test_image_getextrema.py b/Tests/test_image_getextrema.py index 9783141a3..f002419da 100644 --- a/Tests/test_image_getextrema.py +++ b/Tests/test_image_getextrema.py @@ -19,7 +19,7 @@ class TestImageGetExtrema(PillowTestCase): self.assertEqual( extrema("RGBA"), ((0, 255), (0, 255), (0, 255), (255, 255))) self.assertEqual( - extrema("CMYK"), (((0, 255), (0, 255), (0, 255), (0, 0)))) + extrema("CMYK"), ((0, 255), (0, 255), (0, 255), (0, 0))) self.assertEqual(extrema("I;16"), (0, 255)) def test_true_16(self): diff --git a/Tests/test_image_resample.py b/Tests/test_image_resample.py index 226e7873a..46a45833e 100644 --- a/Tests/test_image_resample.py +++ b/Tests/test_image_resample.py @@ -196,7 +196,7 @@ class TestImagingCoreResampleAccuracy(PillowTestCase): class CoreResampleConsistencyTest(PillowTestCase): def make_case(self, mode, fill): im = Image.new(mode, (512, 9), fill) - return (im.resize((9, 512), Image.LANCZOS), im.load()[0, 0]) + return im.resize((9, 512), Image.LANCZOS), im.load()[0, 0] def run_case(self, case): channel, color = case diff --git a/Tests/test_imagedraw.py b/Tests/test_imagedraw.py index bfc43b7b6..7f2accdcb 100644 --- a/Tests/test_imagedraw.py +++ b/Tests/test_imagedraw.py @@ -46,7 +46,7 @@ class TestImageDraw(PillowTestCase): im = Image.open("Tests/images/chi.gif") draw = ImageDraw.Draw(im) - draw.line(((0, 0)), fill=(0, 0, 0)) + draw.line((0, 0), fill=(0, 0, 0)) def test_mode_mismatch(self): im = hopper("RGB").copy() @@ -543,7 +543,7 @@ class TestImageDraw(PillowTestCase): for y in range(0, size[1]): if (x + y) % 2 == 0: img.putpixel((x, y), background2) - return (img, ImageDraw.Draw(img)) + return img, ImageDraw.Draw(img) def test_square(self): expected = Image.open(os.path.join(IMAGES_PATH, 'square.png')) diff --git a/Tests/test_imagefile.py b/Tests/test_imagefile.py index 8a8cdb64b..4f81df12e 100644 --- a/Tests/test_imagefile.py +++ b/Tests/test_imagefile.py @@ -144,7 +144,7 @@ class TestImageFile(PillowTestCase): class MockPyDecoder(ImageFile.PyDecoder): def decode(self, buffer): # eof - return (-1, 0) + return -1, 0 xoff, yoff, xsize, ysize = 10, 20, 100, 100 diff --git a/Tests/test_imagetk.py b/Tests/test_imagetk.py index 72ca91ca2..667d18e8f 100644 --- a/Tests/test_imagetk.py +++ b/Tests/test_imagetk.py @@ -26,7 +26,7 @@ class TestImageTk(PillowTestCase): # setup tk tk.Frame() # root = tk.Tk() - except (tk.TclError) as v: + except tk.TclError as v: self.skipTest("TCL Error: %s" % v) def test_kw(self): diff --git a/Tests/test_lib_pack.py b/Tests/test_lib_pack.py index 6f755c239..33590eeb4 100644 --- a/Tests/test_lib_pack.py +++ b/Tests/test_lib_pack.py @@ -17,7 +17,7 @@ class TestLibPack(PillowTestCase): for x, pixel in enumerate(pixels): im.putpixel((x, 0), pixel) - if isinstance(data, (int)): + if isinstance(data, int): data_len = data * len(pixels) data = bytes(bytearray(range(1, data_len + 1))) @@ -217,7 +217,7 @@ class TestLibUnpack(PillowTestCase): """ data - either raw bytes with data or just number of bytes in rawmode. """ - if isinstance(data, (int)): + if isinstance(data, int): data_len = data * len(pixels) data = bytes(bytearray(range(1, data_len + 1))) diff --git a/Tests/test_qt_image_toqimage.py b/Tests/test_qt_image_toqimage.py index b9d095cd9..6f4a044e2 100644 --- a/Tests/test_qt_image_toqimage.py +++ b/Tests/test_qt_image_toqimage.py @@ -70,8 +70,8 @@ class TestToQImage(PillowQtTestCase, PillowTestCase): def test_segfault(self): app = QApplication([]) ex = Example() - assert(app) # Silence warning - assert(ex) # Silence warning + assert app # Silence warning + assert ex # Silence warning if ImageQt.qt_is_installed: From 088d04470ef1c03954cf0dc0bdd85528dc22db17 Mon Sep 17 00:00:00 2001 From: Hugo Date: Tue, 2 Oct 2018 13:43:48 +0300 Subject: [PATCH 11/12] Unnecessary list comprehension - 'tuple' can take a generator --- Tests/test_file_tiff_metadata.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/test_file_tiff_metadata.py b/Tests/test_file_tiff_metadata.py index d1e2b577e..9c615354c 100644 --- a/Tests/test_file_tiff_metadata.py +++ b/Tests/test_file_tiff_metadata.py @@ -136,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'] From 5df41b43993dd807e3321fffbf5244c7d545fdc9 Mon Sep 17 00:00:00 2001 From: Hugo Date: Tue, 2 Oct 2018 13:45:48 +0300 Subject: [PATCH 12/12] Unnecessary generator - rewrite as a list comprehension --- Tests/helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/helper.py b/Tests/helper.py index 8905e4009..f6995e4b5 100644 --- a/Tests/helper.py +++ b/Tests/helper.py @@ -174,7 +174,7 @@ class PillowTestCase(unittest.TestCase): if warn_class is None: self.assertEqual(len(w), 0, "Expected no warnings, got %s" % - list(v.category for v in w)) + [v.category for v in w]) else: self.assertGreaterEqual(len(w), 1) found = False