Changed assert checks to more specific versions

This commit is contained in:
Andrew Murray 2017-06-03 14:04:54 +10:00
parent cf575ff93e
commit e8cba27bb1
21 changed files with 58 additions and 59 deletions

View File

@ -21,7 +21,7 @@ class TestDecompressionBomb(PillowTestCase):
# Arrange # Arrange
# Turn limit off # Turn limit off
Image.MAX_IMAGE_PIXELS = None Image.MAX_IMAGE_PIXELS = None
self.assertEqual(Image.MAX_IMAGE_PIXELS, None) self.assertIsNone(Image.MAX_IMAGE_PIXELS)
# Act / Assert # Act / Assert
# Implicit assert: no warning. # Implicit assert: no warning.

View File

@ -7,10 +7,10 @@ class TestFeatures(PillowTestCase):
def test_check_features(self): def test_check_features(self):
for feature in features.modules: for feature in features.modules:
self.assertTrue( self.assertIn(
features.check_module(feature) in [True, False, None]) features.check_module(feature), [True, False, None])
for feature in features.codecs: 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): def test_supported_features(self):
self.assertIsInstance(features.get_supported_modules(), list) self.assertIsInstance(features.get_supported_modules(), list)

View File

@ -50,7 +50,7 @@ class TestFileDcx(PillowTestCase):
im.seek(n_frames) im.seek(n_frames)
break break
except EOFError: except EOFError:
self.assertTrue(im.tell() < n_frames) self.assertLess(im.tell(), n_frames)
def test_seek_too_far(self): def test_seek_too_far(self):
# Arrange # Arrange

View File

@ -38,7 +38,7 @@ class TestFileFli(PillowTestCase):
im.seek(n_frames) im.seek(n_frames)
break break
except EOFError: except EOFError:
self.assertTrue(im.tell() < n_frames) self.assertLess(im.tell(), n_frames)
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -226,7 +226,7 @@ class TestFileGif(PillowTestCase):
im.seek(n_frames) im.seek(n_frames)
break break
except EOFError: except EOFError:
self.assertTrue(im.tell() < n_frames) self.assertLess(im.tell(), n_frames)
def test_dispose_none(self): def test_dispose_none(self):
img = Image.open("Tests/images/dispose_none.gif") img = Image.open("Tests/images/dispose_none.gif")

View File

@ -30,7 +30,7 @@ class TestFileIm(PillowTestCase):
im.seek(n_frames) im.seek(n_frames)
break break
except EOFError: except EOFError:
self.assertTrue(im.tell() < n_frames) self.assertLess(im.tell(), n_frames)
def test_roundtrip(self): def test_roundtrip(self):
out = self.tempfile('temp.im') out = self.tempfile('temp.im')

View File

@ -93,7 +93,7 @@ class TestFileJpeg(PillowTestCase):
self.assertEqual(test(72), (72, 72)) self.assertEqual(test(72), (72, 72))
self.assertEqual(test(300), (300, 300)) self.assertEqual(test(300), (300, 300))
self.assertEqual(test(100, 200), (100, 200)) self.assertEqual(test(100, 200), (100, 200))
self.assertEqual(test(0), None) # square pixels self.assertIsNone(test(0)) # square pixels
def test_icc(self): def test_icc(self):
# Test ICC support # Test ICC support

View File

@ -173,8 +173,7 @@ class TestFileLibTiff(LibTiffTestCase):
'RowsPerStrip', 'RowsPerStrip',
'StripOffsets'] 'StripOffsets']
for field in requested_fields: for field in requested_fields:
self.assertTrue(field in reloaded, self.assertIn(field, reloaded, "%s not in metadata" % field)
"%s not in metadata" % field)
def test_additional_metadata(self): def test_additional_metadata(self):
# these should not crash. Seriously dummy data, most of it doesn't make # these should not crash. Seriously dummy data, most of it doesn't make

View File

@ -110,7 +110,7 @@ class TestFileMpo(PillowTestCase):
im.seek(n_frames) im.seek(n_frames)
break break
except EOFError: except EOFError:
self.assertTrue(im.tell() < n_frames) self.assertLess(im.tell(), n_frames)
def test_image_grab(self): def test_image_grab(self):
for test_file in test_files: for test_file in test_files:

View File

@ -316,7 +316,7 @@ class TestFilePng(PillowTestCase):
test_file = f.read()[:offset] test_file = f.read()[:offset]
im = Image.open(BytesIO(test_file)) im = Image.open(BytesIO(test_file))
self.assertTrue(im.fp is not None) self.assertIsNotNone(im.fp)
self.assertRaises((IOError, SyntaxError), im.verify) self.assertRaises((IOError, SyntaxError), im.verify)
def test_verify_ignores_crc_error(self): def test_verify_ignores_crc_error(self):
@ -331,7 +331,7 @@ class TestFilePng(PillowTestCase):
ImageFile.LOAD_TRUNCATED_IMAGES = True ImageFile.LOAD_TRUNCATED_IMAGES = True
try: try:
im = load(image_data) im = load(image_data)
self.assertTrue(im is not None) self.assertIsNotNone(im)
finally: finally:
ImageFile.LOAD_TRUNCATED_IMAGES = False ImageFile.LOAD_TRUNCATED_IMAGES = False
@ -462,7 +462,7 @@ class TestFilePng(PillowTestCase):
def test_save_icc_profile(self): def test_save_icc_profile(self):
im = Image.open("Tests/images/icc_profile_none.png") 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") with_icc = Image.open("Tests/images/icc_profile.png")
expected_icc = with_icc.info['icc_profile'] expected_icc = with_icc.info['icc_profile']
@ -485,7 +485,7 @@ class TestFilePng(PillowTestCase):
def test_roundtrip_no_icc_profile(self): def test_roundtrip_no_icc_profile(self):
im = Image.open("Tests/images/icc_profile_none.png") 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) im = roundtrip(im)
self.assertNotIn('icc_profile', im.info) self.assertNotIn('icc_profile', im.info)

View File

@ -44,7 +44,7 @@ class TestImagePsd(PillowTestCase):
im.seek(n_frames+1) im.seek(n_frames+1)
break break
except EOFError: except EOFError:
self.assertTrue(im.tell() < n_frames) self.assertLess(im.tell(), n_frames)
def test_seek_tell(self): def test_seek_tell(self):
im = Image.open(test_file) im = Image.open(test_file)

View File

@ -69,7 +69,7 @@ class TestImageSpider(PillowTestCase):
img_list = SpiderImagePlugin.loadImageSeries(file_list) img_list = SpiderImagePlugin.loadImageSeries(file_list)
# Assert # Assert
self.assertEqual(img_list, None) self.assertIsNone(img_list)
def test_isInt_not_a_number(self): def test_isInt_not_a_number(self):
# Arrange # Arrange

View File

@ -237,7 +237,7 @@ class TestFileTiff(PillowTestCase):
im.seek(n_frames) im.seek(n_frames)
break break
except EOFError: except EOFError:
self.assertTrue(im.tell() < n_frames) self.assertLess(im.tell(), n_frames)
def test_multipage(self): def test_multipage(self):
# issue #862 # issue #862

View File

@ -96,7 +96,7 @@ class TestFileWebpMetadata(PillowTestCase):
file_path = "Tests/images/flower.jpg" file_path = "Tests/images/flower.jpg"
image = Image.open(file_path) image = Image.open(file_path)
self.assertTrue('exif' in image.info) self.assertIn('exif', image.info)
test_buffer = BytesIO() test_buffer = BytesIO()

View File

@ -170,7 +170,7 @@ class TestImage(PillowTestCase):
im2 = Image.new('RGB', (25, 25), 'white') im2 = Image.new('RGB', (25, 25), 'white')
# Act / Assert # Act / Assert
self.assertTrue(im1 != im2) self.assertNotEqual(im1, im2)
def test_alpha_composite(self): def test_alpha_composite(self):
# https://stackoverflow.com/questions/3374878 # https://stackoverflow.com/questions/3374878

View File

@ -14,7 +14,7 @@ class TestImageGetBbox(PillowTestCase):
# 8-bit mode # 8-bit mode
im = Image.new("L", (100, 100), 0) im = Image.new("L", (100, 100), 0)
self.assertEqual(im.getbbox(), None) self.assertIsNone(im.getbbox())
im.paste(255, (10, 25, 90, 75)) im.paste(255, (10, 25, 90, 75))
self.assertEqual(im.getbbox(), (10, 25, 90, 75)) self.assertEqual(im.getbbox(), (10, 25, 90, 75))
@ -27,7 +27,7 @@ class TestImageGetBbox(PillowTestCase):
# 32-bit mode # 32-bit mode
im = Image.new("RGB", (100, 100), 0) im = Image.new("RGB", (100, 100), 0)
self.assertEqual(im.getbbox(), None) self.assertIsNone(im.getbbox())
im.paste(255, (10, 25, 90, 75)) im.paste(255, (10, 25, 90, 75))
self.assertEqual(im.getbbox(), (10, 25, 90, 75)) self.assertEqual(im.getbbox(), (10, 25, 90, 75))

View File

@ -20,15 +20,15 @@ class TestImageGetColors(PillowTestCase):
self.assertEqual(getcolors("I"), 255) self.assertEqual(getcolors("I"), 255)
self.assertEqual(getcolors("F"), 255) self.assertEqual(getcolors("F"), 255)
self.assertEqual(getcolors("P"), 90) # fixed palette self.assertEqual(getcolors("P"), 90) # fixed palette
self.assertEqual(getcolors("RGB"), None) self.assertIsNone(getcolors("RGB"))
self.assertEqual(getcolors("RGBA"), None) self.assertIsNone(getcolors("RGBA"))
self.assertEqual(getcolors("CMYK"), None) self.assertIsNone(getcolors("CMYK"))
self.assertEqual(getcolors("YCbCr"), None) self.assertIsNone(getcolors("YCbCr"))
self.assertEqual(getcolors("L", 128), None) self.assertIsNone(getcolors("L", 128))
self.assertEqual(getcolors("L", 1024), 255) 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", 16384), 10100)
self.assertEqual(getcolors("RGB", 100000), 10100) self.assertEqual(getcolors("RGB", 100000), 10100)
@ -48,7 +48,7 @@ class TestImageGetColors(PillowTestCase):
(7960, (31, 20, 33))] (7960, (31, 20, 33))]
A = im.getcolors(maxcolors=2) A = im.getcolors(maxcolors=2)
self.assertEqual(A, None) self.assertIsNone(A)
A = im.getcolors(maxcolors=3) A = im.getcolors(maxcolors=3)
A.sort() A.sort()

View File

@ -9,15 +9,15 @@ class TestImageGetPalette(PillowTestCase):
if p: if p:
return p[:10] return p[:10]
return None return None
self.assertEqual(palette("1"), None) self.assertIsNone(palette("1"))
self.assertEqual(palette("L"), None) self.assertIsNone(palette("L"))
self.assertEqual(palette("I"), None) self.assertIsNone(palette("I"))
self.assertEqual(palette("F"), None) self.assertIsNone(palette("F"))
self.assertEqual(palette("P"), [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) self.assertEqual(palette("P"), [0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
self.assertEqual(palette("RGB"), None) self.assertIsNone(palette("RGB"))
self.assertEqual(palette("RGBA"), None) self.assertIsNone(palette("RGBA"))
self.assertEqual(palette("CMYK"), None) self.assertIsNone(palette("CMYK"))
self.assertEqual(palette("YCbCr"), None) self.assertIsNone(palette("YCbCr"))
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -222,7 +222,7 @@ class TestImageCms(PillowTestCase):
self.assertTrue(img_srgb.info['icc_profile']) self.assertTrue(img_srgb.info['icc_profile'])
profile = ImageCmsProfile(BytesIO(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): def test_lab_roundtrip(self):
# check to see if we're at least internally consistent. # 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_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.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)))) 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.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.color_space, 'RGB')
self.assertEqual(p.colorant_table, None) self.assertIsNone(p.colorant_table)
self.assertEqual(p.colorant_table_out, None) self.assertIsNone(p.colorant_table_out)
self.assertEqual(p.colorimetric_intent, None) self.assertIsNone(p.colorimetric_intent)
self.assertEqual(p.connection_space, 'XYZ ') self.assertEqual(p.connection_space, 'XYZ ')
self.assertEqual(p.copyright, 'Copyright International Color Consortium, 2009') self.assertEqual(p.copyright, 'Copyright International Color Consortium, 2009')
self.assertEqual(p.creation_date, datetime.datetime(2009, 2, 27, 21, 36, 31)) 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.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_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_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.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.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_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, ((0.964202880859375, 1.0, 0.8249053955078125), (0.3457029219802284, 0.3585375327567059, 1.0)))
assert_truncated_tuple_equal((p.media_white_point_temperature,), (5000.722328847392,)) 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.model, 'IEC 61966-2-1 Default RGB Colour Space - sRGB')
self.assertEqual(p.pcs, 'XYZ') 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_copyright, 'Copyright International Color Consortium, 2009')
self.assertEqual(p.product_desc, 'sRGB IEC61966-2-1 black scaled') self.assertEqual(p.product_desc, 'sRGB IEC61966-2-1 black scaled')
self.assertEqual(p.product_description, '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_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))) 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.rendering_intent, 0)
self.assertEqual(p.saturation_rendering_intent_gamut, None) self.assertIsNone(p.saturation_rendering_intent_gamut)
self.assertEqual(p.screening_description, None) self.assertIsNone(p.screening_description)
self.assertEqual(p.target, None) self.assertIsNone(p.target)
self.assertEqual(p.technology, 'CRT ') self.assertEqual(p.technology, 'CRT ')
self.assertEqual(p.version, 2.0) self.assertEqual(p.version, 2.0)
self.assertEqual(p.viewing_condition, 'Reference Viewing Condition in IEC 61966-2-1') self.assertEqual(p.viewing_condition, 'Reference Viewing Condition in IEC 61966-2-1')

View File

@ -45,7 +45,7 @@ class TestImageTk(PillowTestCase):
# Test no relevant entry # Test no relevant entry
im = ImageTk._get_image_from_kw(kw) im = ImageTk._get_image_from_kw(kw)
self.assertEqual(im, None) self.assertIsNone(im)
def test_photoimage(self): def test_photoimage(self):
for mode in TK_MODES: for mode in TK_MODES:

View File

@ -34,10 +34,10 @@ class Test_IFDRational(PillowTestCase):
xres = IFDRational(72) xres = IFDRational(72)
yres = IFDRational(72) yres = IFDRational(72)
self.assertTrue(xres._val is not None) self.assertIsNotNone(xres._val)
self.assertTrue(xres.numerator is not None) self.assertIsNotNone(xres.numerator)
self.assertTrue(xres.denominator is not None) self.assertIsNotNone(xres.denominator)
self.assertTrue(yres._val is not None) self.assertIsNotNone(yres._val)
self.assertTrue(xres and 1) self.assertTrue(xres and 1)
self.assertTrue(xres and yres) self.assertTrue(xres and yres)