Merge pull request #2203 from jdufresne/test-exceptions

Avoid catching unexpected exceptions in tests
This commit is contained in:
Hugo 2018-09-26 15:43:41 +03:00 committed by GitHub
commit b9b4c03957
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 26 deletions

View File

@ -141,11 +141,9 @@ class TestFileJpeg(PillowTestCase):
im = Image.open('Tests/images/icc_profile_big.jpg')
f = self.tempfile("temp.jpg")
icc_profile = im.info["icc_profile"]
try:
im.save(f, format='JPEG', progressive=True, quality=95,
icc_profile=icc_profile, optimize=True)
except IOError:
self.fail("Failed saving image with icc larger than image size")
# Should not raise IOError for image with icc larger than image size.
im.save(f, format='JPEG', progressive=True, quality=95,
icc_profile=icc_profile, optimize=True)
def test_optimize(self):
im1 = self.roundtrip(hopper())

View File

@ -539,10 +539,8 @@ class TestFileLibTiff(LibTiffTestCase):
im = Image.open(tmpfile)
im.n_frames
im.close()
try:
os.remove(tmpfile) # Windows PermissionError here!
except:
self.fail("Should not get permission error here")
# Should not raise PermissionError.
os.remove(tmpfile)
def test_read_icc(self):
with Image.open("Tests/images/hopper.iccprofile.tif") as img:

View File

@ -133,11 +133,8 @@ class TestFileTiff(PillowTestCase):
def test_bad_exif(self):
i = Image.open('Tests/images/hopper_bad_exif.jpg')
try:
self.assert_warning(UserWarning, i._getexif)
except struct.error:
self.fail(
"Bad EXIF data passed incorrect values to _binary unpack")
# Should not raise struct.error.
self.assert_warning(UserWarning, i._getexif)
def test_save_rgba(self):
im = hopper("RGBA")

View File

@ -169,10 +169,8 @@ class TestFileTiffMetadata(PillowTestCase):
f = io.BytesIO(b'II*\x00\x08\x00\x00\x00')
head = f.read(8)
info = TiffImagePlugin.ImageFileDirectory(head)
try:
self.assert_warning(UserWarning, info.load, f)
except struct.error:
self.fail("Should not be struct errors there.")
# Should not raise struct.error.
self.assert_warning(UserWarning, info.load, f)
def test_iccprofile(self):
# https://github.com/python-pillow/Pillow/issues/1462
@ -223,10 +221,8 @@ class TestFileTiffMetadata(PillowTestCase):
head = data.read(8)
info = TiffImagePlugin.ImageFileDirectory_v2(head)
info.load(data)
try:
info = dict(info)
except ValueError:
self.fail("Should not be struct value error there.")
# Should not raise ValueError.
info = dict(info)
self.assertIn(33432, info)
def test_PhotoshopInfo(self):
@ -245,10 +241,8 @@ class TestFileTiffMetadata(PillowTestCase):
ifd._tagdata[277] = struct.pack('hh', 4, 4)
ifd.tagtype[277] = TiffTags.SHORT
try:
self.assert_warning(UserWarning, lambda: ifd[277])
except ValueError:
self.fail("Invalid Metadata count should not cause a Value Error.")
# Should not raise ValueError.
self.assert_warning(UserWarning, lambda: ifd[277])
if __name__ == '__main__':