From 803cdf068f77e40f5244b39a4dd5b6355c206f2f Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 3 Jun 2017 13:34:52 +1000 Subject: [PATCH 1/4] Removed unnecessary parameter --- Tests/test_imagegrab.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/test_imagegrab.py b/Tests/test_imagegrab.py index 840df31c2..b2edffa57 100644 --- a/Tests/test_imagegrab.py +++ b/Tests/test_imagegrab.py @@ -38,7 +38,7 @@ class TestImageGrabImport(PillowTestCase): # Assert if sys.platform in ["win32", "darwin"]: - self.assertIsNone(exception, None) + self.assertIsNone(exception) else: self.assertIsInstance(exception, ImportError) self.assertEqual(str(exception), From cf575ff93ef2de287c30aba62833ad51637011f4 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 3 Jun 2017 14:02:23 +1000 Subject: [PATCH 2/4] Replaced false assert with fail --- Tests/test_bmp_reference.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Tests/test_bmp_reference.py b/Tests/test_bmp_reference.py index fa4571e60..8e84cc8f1 100644 --- a/Tests/test_bmp_reference.py +++ b/Tests/test_bmp_reference.py @@ -99,8 +99,7 @@ class TestBmpReference(PillowTestCase): os.path.join(base, 'g', 'pal8rle.bmp'), os.path.join(base, 'g', 'pal4rle.bmp')) if f not in unsupported: - self.assertTrue( - False, "Unsupported Image %s: %s" % (f, msg)) + self.fail("Unsupported Image %s: %s" % (f, msg)) if __name__ == '__main__': From e8cba27bb1bce7b4ff8a703e77e50da233773289 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 3 Jun 2017 14:04:54 +1000 Subject: [PATCH 3/4] Changed assert checks to more specific versions --- Tests/test_decompression_bomb.py | 2 +- Tests/test_features.py | 6 +++--- Tests/test_file_dcx.py | 2 +- Tests/test_file_fli.py | 2 +- Tests/test_file_gif.py | 2 +- Tests/test_file_im.py | 2 +- Tests/test_file_jpeg.py | 2 +- Tests/test_file_libtiff.py | 3 +-- Tests/test_file_mpo.py | 2 +- Tests/test_file_png.py | 8 ++++---- Tests/test_file_psd.py | 2 +- Tests/test_file_spider.py | 2 +- Tests/test_file_tiff.py | 10 +++++----- Tests/test_file_webp_metadata.py | 2 +- Tests/test_image.py | 2 +- Tests/test_image_getbbox.py | 4 ++-- Tests/test_image_getcolors.py | 14 +++++++------- Tests/test_image_getpalette.py | 16 ++++++++-------- Tests/test_imagecms.py | 24 ++++++++++++------------ Tests/test_imagetk.py | 2 +- Tests/test_tiff_ifdrational.py | 8 ++++---- 21 files changed, 58 insertions(+), 59 deletions(-) diff --git a/Tests/test_decompression_bomb.py b/Tests/test_decompression_bomb.py index e952f6586..675005d3f 100644 --- a/Tests/test_decompression_bomb.py +++ b/Tests/test_decompression_bomb.py @@ -21,7 +21,7 @@ class TestDecompressionBomb(PillowTestCase): # Arrange # Turn limit off Image.MAX_IMAGE_PIXELS = None - self.assertEqual(Image.MAX_IMAGE_PIXELS, None) + self.assertIsNone(Image.MAX_IMAGE_PIXELS) # Act / Assert # Implicit assert: no warning. diff --git a/Tests/test_features.py b/Tests/test_features.py index b9afe9b1d..eacf807db 100644 --- a/Tests/test_features.py +++ b/Tests/test_features.py @@ -7,10 +7,10 @@ class TestFeatures(PillowTestCase): def test_check_features(self): for feature in features.modules: - self.assertTrue( - features.check_module(feature) in [True, False, None]) + self.assertIn( + features.check_module(feature), [True, False, None]) for feature in features.codecs: - self.assertTrue(features.check_codec(feature) in [True, False]) + self.assertIn(features.check_codec(feature), [True, False]) def test_supported_features(self): self.assertIsInstance(features.get_supported_modules(), list) diff --git a/Tests/test_file_dcx.py b/Tests/test_file_dcx.py index 09da3c439..3da146d01 100644 --- a/Tests/test_file_dcx.py +++ b/Tests/test_file_dcx.py @@ -50,7 +50,7 @@ class TestFileDcx(PillowTestCase): im.seek(n_frames) break except EOFError: - self.assertTrue(im.tell() < n_frames) + self.assertLess(im.tell(), n_frames) def test_seek_too_far(self): # Arrange diff --git a/Tests/test_file_fli.py b/Tests/test_file_fli.py index a49301de1..ad4e8bc3f 100644 --- a/Tests/test_file_fli.py +++ b/Tests/test_file_fli.py @@ -38,7 +38,7 @@ class TestFileFli(PillowTestCase): im.seek(n_frames) break except EOFError: - self.assertTrue(im.tell() < n_frames) + self.assertLess(im.tell(), n_frames) if __name__ == '__main__': diff --git a/Tests/test_file_gif.py b/Tests/test_file_gif.py index 1a67b7db5..bb2aa8a0d 100644 --- a/Tests/test_file_gif.py +++ b/Tests/test_file_gif.py @@ -226,7 +226,7 @@ class TestFileGif(PillowTestCase): im.seek(n_frames) break except EOFError: - self.assertTrue(im.tell() < n_frames) + self.assertLess(im.tell(), n_frames) def test_dispose_none(self): img = Image.open("Tests/images/dispose_none.gif") diff --git a/Tests/test_file_im.py b/Tests/test_file_im.py index 94d8bcce6..fcf4f52f4 100644 --- a/Tests/test_file_im.py +++ b/Tests/test_file_im.py @@ -30,7 +30,7 @@ class TestFileIm(PillowTestCase): im.seek(n_frames) break except EOFError: - self.assertTrue(im.tell() < n_frames) + self.assertLess(im.tell(), n_frames) def test_roundtrip(self): out = self.tempfile('temp.im') diff --git a/Tests/test_file_jpeg.py b/Tests/test_file_jpeg.py index f4cfe8d60..b33644bd7 100644 --- a/Tests/test_file_jpeg.py +++ b/Tests/test_file_jpeg.py @@ -93,7 +93,7 @@ class TestFileJpeg(PillowTestCase): self.assertEqual(test(72), (72, 72)) self.assertEqual(test(300), (300, 300)) self.assertEqual(test(100, 200), (100, 200)) - self.assertEqual(test(0), None) # square pixels + self.assertIsNone(test(0)) # square pixels def test_icc(self): # Test ICC support diff --git a/Tests/test_file_libtiff.py b/Tests/test_file_libtiff.py index 9c60aedf9..4b67ba676 100644 --- a/Tests/test_file_libtiff.py +++ b/Tests/test_file_libtiff.py @@ -173,8 +173,7 @@ class TestFileLibTiff(LibTiffTestCase): 'RowsPerStrip', 'StripOffsets'] for field in requested_fields: - self.assertTrue(field in reloaded, - "%s not in metadata" % field) + self.assertIn(field, reloaded, "%s not in metadata" % field) def test_additional_metadata(self): # these should not crash. Seriously dummy data, most of it doesn't make diff --git a/Tests/test_file_mpo.py b/Tests/test_file_mpo.py index 4c9f31abd..b4d0c696e 100644 --- a/Tests/test_file_mpo.py +++ b/Tests/test_file_mpo.py @@ -110,7 +110,7 @@ class TestFileMpo(PillowTestCase): im.seek(n_frames) break except EOFError: - self.assertTrue(im.tell() < n_frames) + self.assertLess(im.tell(), n_frames) def test_image_grab(self): for test_file in test_files: diff --git a/Tests/test_file_png.py b/Tests/test_file_png.py index 32d6a3acd..f9b9a1eb4 100644 --- a/Tests/test_file_png.py +++ b/Tests/test_file_png.py @@ -316,7 +316,7 @@ class TestFilePng(PillowTestCase): test_file = f.read()[:offset] im = Image.open(BytesIO(test_file)) - self.assertTrue(im.fp is not None) + self.assertIsNotNone(im.fp) self.assertRaises((IOError, SyntaxError), im.verify) def test_verify_ignores_crc_error(self): @@ -331,7 +331,7 @@ class TestFilePng(PillowTestCase): ImageFile.LOAD_TRUNCATED_IMAGES = True try: im = load(image_data) - self.assertTrue(im is not None) + self.assertIsNotNone(im) finally: ImageFile.LOAD_TRUNCATED_IMAGES = False @@ -462,7 +462,7 @@ class TestFilePng(PillowTestCase): def test_save_icc_profile(self): im = Image.open("Tests/images/icc_profile_none.png") - self.assertEqual(im.info['icc_profile'], None) + self.assertIsNone(im.info['icc_profile']) with_icc = Image.open("Tests/images/icc_profile.png") expected_icc = with_icc.info['icc_profile'] @@ -485,7 +485,7 @@ class TestFilePng(PillowTestCase): def test_roundtrip_no_icc_profile(self): im = Image.open("Tests/images/icc_profile_none.png") - self.assertEqual(im.info['icc_profile'], None) + self.assertIsNone(im.info['icc_profile']) im = roundtrip(im) self.assertNotIn('icc_profile', im.info) diff --git a/Tests/test_file_psd.py b/Tests/test_file_psd.py index 04a171cbb..ddd2507bc 100644 --- a/Tests/test_file_psd.py +++ b/Tests/test_file_psd.py @@ -44,7 +44,7 @@ class TestImagePsd(PillowTestCase): im.seek(n_frames+1) break except EOFError: - self.assertTrue(im.tell() < n_frames) + self.assertLess(im.tell(), n_frames) def test_seek_tell(self): im = Image.open(test_file) diff --git a/Tests/test_file_spider.py b/Tests/test_file_spider.py index 96f82054e..32f1f55e5 100644 --- a/Tests/test_file_spider.py +++ b/Tests/test_file_spider.py @@ -69,7 +69,7 @@ class TestImageSpider(PillowTestCase): img_list = SpiderImagePlugin.loadImageSeries(file_list) # Assert - self.assertEqual(img_list, None) + self.assertIsNone(img_list) def test_isInt_not_a_number(self): # Arrange diff --git a/Tests/test_file_tiff.py b/Tests/test_file_tiff.py index 1e182fb1a..ebcc6dd35 100644 --- a/Tests/test_file_tiff.py +++ b/Tests/test_file_tiff.py @@ -237,7 +237,7 @@ class TestFileTiff(PillowTestCase): im.seek(n_frames) break except EOFError: - self.assertTrue(im.tell() < n_frames) + self.assertLess(im.tell(), n_frames) def test_multipage(self): # issue #862 @@ -484,7 +484,7 @@ class TestFileTiff(PillowTestCase): def test_close_on_load_nonexclusive(self): tmpfile = self.tempfile("temp.tif") - + with Image.open("Tests/images/uint16_1_4660.tif") as im: im.save(tmpfile) @@ -495,7 +495,7 @@ class TestFileTiff(PillowTestCase): im.load() self.assertFalse(fp.closed) - + @unittest.skipUnless(sys.platform.startswith('win32'), "Windows only") class TestFileTiffW32(PillowTestCase): @@ -503,7 +503,7 @@ class TestFileTiffW32(PillowTestCase): tmpfile = self.tempfile("temp.tif") import os - # this is an mmaped file. + # this is an mmaped file. with Image.open("Tests/images/uint16_1_4660.tif") as im: im.save(tmpfile) @@ -516,7 +516,7 @@ class TestFileTiffW32(PillowTestCase): # this closes the mmap im.close() - + # this should not fail, as load should have closed the file pointer, # and close should have closed the mmap os.remove(tmpfile) diff --git a/Tests/test_file_webp_metadata.py b/Tests/test_file_webp_metadata.py index 947f8464a..88e2b3b88 100644 --- a/Tests/test_file_webp_metadata.py +++ b/Tests/test_file_webp_metadata.py @@ -96,7 +96,7 @@ class TestFileWebpMetadata(PillowTestCase): file_path = "Tests/images/flower.jpg" image = Image.open(file_path) - self.assertTrue('exif' in image.info) + self.assertIn('exif', image.info) test_buffer = BytesIO() diff --git a/Tests/test_image.py b/Tests/test_image.py index 156396451..ea813cd84 100644 --- a/Tests/test_image.py +++ b/Tests/test_image.py @@ -170,7 +170,7 @@ class TestImage(PillowTestCase): im2 = Image.new('RGB', (25, 25), 'white') # Act / Assert - self.assertTrue(im1 != im2) + self.assertNotEqual(im1, im2) def test_alpha_composite(self): # https://stackoverflow.com/questions/3374878 diff --git a/Tests/test_image_getbbox.py b/Tests/test_image_getbbox.py index 116f26497..f29032143 100644 --- a/Tests/test_image_getbbox.py +++ b/Tests/test_image_getbbox.py @@ -14,7 +14,7 @@ class TestImageGetBbox(PillowTestCase): # 8-bit mode im = Image.new("L", (100, 100), 0) - self.assertEqual(im.getbbox(), None) + self.assertIsNone(im.getbbox()) im.paste(255, (10, 25, 90, 75)) self.assertEqual(im.getbbox(), (10, 25, 90, 75)) @@ -27,7 +27,7 @@ class TestImageGetBbox(PillowTestCase): # 32-bit mode im = Image.new("RGB", (100, 100), 0) - self.assertEqual(im.getbbox(), None) + self.assertIsNone(im.getbbox()) im.paste(255, (10, 25, 90, 75)) self.assertEqual(im.getbbox(), (10, 25, 90, 75)) diff --git a/Tests/test_image_getcolors.py b/Tests/test_image_getcolors.py index a6a20b288..ca7a9d93d 100644 --- a/Tests/test_image_getcolors.py +++ b/Tests/test_image_getcolors.py @@ -20,15 +20,15 @@ class TestImageGetColors(PillowTestCase): self.assertEqual(getcolors("I"), 255) self.assertEqual(getcolors("F"), 255) self.assertEqual(getcolors("P"), 90) # fixed palette - self.assertEqual(getcolors("RGB"), None) - self.assertEqual(getcolors("RGBA"), None) - self.assertEqual(getcolors("CMYK"), None) - self.assertEqual(getcolors("YCbCr"), None) + self.assertIsNone(getcolors("RGB")) + self.assertIsNone(getcolors("RGBA")) + self.assertIsNone(getcolors("CMYK")) + self.assertIsNone(getcolors("YCbCr")) - self.assertEqual(getcolors("L", 128), None) + self.assertIsNone(getcolors("L", 128)) self.assertEqual(getcolors("L", 1024), 255) - self.assertEqual(getcolors("RGB", 8192), None) + self.assertIsNone(getcolors("RGB", 8192)) self.assertEqual(getcolors("RGB", 16384), 10100) self.assertEqual(getcolors("RGB", 100000), 10100) @@ -48,7 +48,7 @@ class TestImageGetColors(PillowTestCase): (7960, (31, 20, 33))] A = im.getcolors(maxcolors=2) - self.assertEqual(A, None) + self.assertIsNone(A) A = im.getcolors(maxcolors=3) A.sort() diff --git a/Tests/test_image_getpalette.py b/Tests/test_image_getpalette.py index 14ecddbbf..01a6ac7ad 100644 --- a/Tests/test_image_getpalette.py +++ b/Tests/test_image_getpalette.py @@ -9,15 +9,15 @@ class TestImageGetPalette(PillowTestCase): if p: return p[:10] return None - self.assertEqual(palette("1"), None) - self.assertEqual(palette("L"), None) - self.assertEqual(palette("I"), None) - self.assertEqual(palette("F"), None) + self.assertIsNone(palette("1")) + self.assertIsNone(palette("L")) + self.assertIsNone(palette("I")) + self.assertIsNone(palette("F")) self.assertEqual(palette("P"), [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) - self.assertEqual(palette("RGB"), None) - self.assertEqual(palette("RGBA"), None) - self.assertEqual(palette("CMYK"), None) - self.assertEqual(palette("YCbCr"), None) + self.assertIsNone(palette("RGB")) + self.assertIsNone(palette("RGBA")) + self.assertIsNone(palette("CMYK")) + self.assertIsNone(palette("YCbCr")) if __name__ == '__main__': diff --git a/Tests/test_imagecms.py b/Tests/test_imagecms.py index 21493e8d5..ef30f3e00 100644 --- a/Tests/test_imagecms.py +++ b/Tests/test_imagecms.py @@ -222,7 +222,7 @@ class TestImageCms(PillowTestCase): self.assertTrue(img_srgb.info['icc_profile']) profile = ImageCmsProfile(BytesIO(img_srgb.info['icc_profile'])) - self.assertTrue('sRGB' in ImageCms.getProfileDescription(profile)) + self.assertIn('sRGB', ImageCms.getProfileDescription(profile)) def test_lab_roundtrip(self): # check to see if we're at least internally consistent. @@ -275,12 +275,12 @@ class TestImageCms(PillowTestCase): assert_truncated_tuple_equal(p.blue_colorant, ((0.14306640625, 0.06060791015625, 0.7140960693359375), (0.1558847490315394, 0.06603820639433387, 0.06060791015625))) assert_truncated_tuple_equal(p.blue_primary, ((0.14306641366715667, 0.06060790921083026, 0.7140960805782015), (0.15588475410450106, 0.06603820408959558, 0.06060790921083026))) assert_truncated_tuple_equal(p.chromatic_adaptation, (((1.04791259765625, 0.0229339599609375, -0.050201416015625), (0.02960205078125, 0.9904632568359375, -0.0170745849609375), (-0.009246826171875, 0.0150604248046875, 0.7517852783203125)), ((1.0267159024652783, 0.022470062342089134, 0.0229339599609375), (0.02951378324103937, 0.9875098886387147, 0.9904632568359375), (-0.012205438066465256, 0.01987915407854985, 0.0150604248046875)))) - self.assertEqual(p.chromaticity, None) + self.assertIsNone(p.chromaticity) self.assertEqual(p.clut, {0: (False, False, True), 1: (False, False, True), 2: (False, False, True), 3: (False, False, True)}) self.assertEqual(p.color_space, 'RGB') - self.assertEqual(p.colorant_table, None) - self.assertEqual(p.colorant_table_out, None) - self.assertEqual(p.colorimetric_intent, None) + self.assertIsNone(p.colorant_table) + self.assertIsNone(p.colorant_table_out) + self.assertIsNone(p.colorimetric_intent) self.assertEqual(p.connection_space, 'XYZ ') self.assertEqual(p.copyright, 'Copyright International Color Consortium, 2009') self.assertEqual(p.creation_date, datetime.datetime(2009, 2, 27, 21, 36, 31)) @@ -292,17 +292,17 @@ class TestImageCms(PillowTestCase): self.assertEqual(p.header_model, '\x00\x00\x00\x00') self.assertEqual(p.icc_measurement_condition, {'backing': (0.0, 0.0, 0.0), 'flare': 0.0, 'geo': 'unknown', 'observer': 1, 'illuminant_type': 'D65'}) self.assertEqual(p.icc_version, 33554432) - self.assertEqual(p.icc_viewing_condition, None) + self.assertIsNone(p.icc_viewing_condition) self.assertEqual(p.intent_supported, {0: (True, True, True), 1: (True, True, True), 2: (True, True, True), 3: (True, True, True)}) - self.assertEqual(p.is_matrix_shaper, True) + self.assertTrue(p.is_matrix_shaper) self.assertEqual(p.luminance, ((0.0, 80.0, 0.0), (0.0, 1.0, 80.0))) - self.assertEqual(p.manufacturer, None) + self.assertIsNone(p.manufacturer) assert_truncated_tuple_equal(p.media_black_point, ((0.012054443359375, 0.0124969482421875, 0.01031494140625), (0.34573304157549234, 0.35842450765864337, 0.0124969482421875))) assert_truncated_tuple_equal(p.media_white_point, ((0.964202880859375, 1.0, 0.8249053955078125), (0.3457029219802284, 0.3585375327567059, 1.0))) assert_truncated_tuple_equal((p.media_white_point_temperature,), (5000.722328847392,)) self.assertEqual(p.model, 'IEC 61966-2-1 Default RGB Colour Space - sRGB') self.assertEqual(p.pcs, 'XYZ') - self.assertEqual(p.perceptual_rendering_intent_gamut, None) + self.assertIsNone(p.perceptual_rendering_intent_gamut) self.assertEqual(p.product_copyright, 'Copyright International Color Consortium, 2009') self.assertEqual(p.product_desc, 'sRGB IEC61966-2-1 black scaled') self.assertEqual(p.product_description, 'sRGB IEC61966-2-1 black scaled') @@ -313,9 +313,9 @@ class TestImageCms(PillowTestCase): assert_truncated_tuple_equal(p.red_colorant, ((0.436065673828125, 0.2224884033203125, 0.013916015625), (0.6484536316398539, 0.3308524880306778, 0.2224884033203125))) assert_truncated_tuple_equal(p.red_primary, ((0.43606566581047446, 0.22248840582960838, 0.013916015621759925), (0.6484536250319214, 0.3308524944738204, 0.22248840582960838))) self.assertEqual(p.rendering_intent, 0) - self.assertEqual(p.saturation_rendering_intent_gamut, None) - self.assertEqual(p.screening_description, None) - self.assertEqual(p.target, None) + self.assertIsNone(p.saturation_rendering_intent_gamut) + self.assertIsNone(p.screening_description) + self.assertIsNone(p.target) self.assertEqual(p.technology, 'CRT ') self.assertEqual(p.version, 2.0) self.assertEqual(p.viewing_condition, 'Reference Viewing Condition in IEC 61966-2-1') diff --git a/Tests/test_imagetk.py b/Tests/test_imagetk.py index 8c8723927..fbf48a1b6 100644 --- a/Tests/test_imagetk.py +++ b/Tests/test_imagetk.py @@ -45,7 +45,7 @@ class TestImageTk(PillowTestCase): # Test no relevant entry im = ImageTk._get_image_from_kw(kw) - self.assertEqual(im, None) + self.assertIsNone(im) def test_photoimage(self): for mode in TK_MODES: diff --git a/Tests/test_tiff_ifdrational.py b/Tests/test_tiff_ifdrational.py index 54f330ec3..0bf4503c4 100644 --- a/Tests/test_tiff_ifdrational.py +++ b/Tests/test_tiff_ifdrational.py @@ -34,10 +34,10 @@ class Test_IFDRational(PillowTestCase): xres = IFDRational(72) yres = IFDRational(72) - self.assertTrue(xres._val is not None) - self.assertTrue(xres.numerator is not None) - self.assertTrue(xres.denominator is not None) - self.assertTrue(yres._val is not None) + self.assertIsNotNone(xres._val) + self.assertIsNotNone(xres.numerator) + self.assertIsNotNone(xres.denominator) + self.assertIsNotNone(yres._val) self.assertTrue(xres and 1) self.assertTrue(xres and yres) From b8e0daaf70849d380bd2900b2a43bab69fe22281 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 3 Jun 2017 14:05:24 +1000 Subject: [PATCH 4/4] Replaced true assert with comment --- Tests/test_image_resample.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/test_image_resample.py b/Tests/test_image_resample.py index 98fe3b0f7..96ad93578 100644 --- a/Tests/test_image_resample.py +++ b/Tests/test_image_resample.py @@ -16,8 +16,8 @@ class TestImagingResampleVulnerability(PillowTestCase): def test_invalid_size(self): im = hopper() + # Should not crash im.resize((100, 100)) - self.assertTrue(True, "Should not Crash") with self.assertRaises(ValueError): im.resize((-100, 100))