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
# 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.

View File

@ -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)

View File

@ -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

View File

@ -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__':

View File

@ -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")

View File

@ -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')

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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()

View File

@ -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

View File

@ -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))

View File

@ -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()

View File

@ -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__':

View File

@ -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')

View File

@ -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:

View File

@ -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)