Avoid catching unexpected exceptions in tests

Instead, allow exceptions to bubble up to the unittest exception
handler.

Prevents replacing the exception trace with a less informative
message. As the exceptions are always unexpected, should not need to
catch them explicitly in tests.
This commit is contained in:
Jon Dufresne 2016-11-06 08:58:45 -08:00
parent 9dd09fa4bf
commit 875e8c4bda
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') im = Image.open('Tests/images/icc_profile_big.jpg')
f = self.tempfile("temp.jpg") f = self.tempfile("temp.jpg")
icc_profile = im.info["icc_profile"] icc_profile = im.info["icc_profile"]
try: # Should not raise IOError for image with icc larger than image size.
im.save(f, format='JPEG', progressive=True, quality=95, im.save(f, format='JPEG', progressive=True, quality=95,
icc_profile=icc_profile, optimize=True) icc_profile=icc_profile, optimize=True)
except IOError:
self.fail("Failed saving image with icc larger than image size")
def test_optimize(self): def test_optimize(self):
im1 = self.roundtrip(hopper()) im1 = self.roundtrip(hopper())

View File

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

View File

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

View File

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