Changed EOFError tests

This commit is contained in:
Andrew Murray 2017-09-06 13:19:33 +10:00
parent 78c62727d3
commit f61b70aa8f
6 changed files with 44 additions and 55 deletions

View File

@ -42,15 +42,14 @@ class TestFileDcx(PillowTestCase):
def test_eoferror(self):
im = Image.open(TEST_FILE)
n_frames = im.n_frames
while True:
n_frames -= 1
try:
im.seek(n_frames)
break
except EOFError:
self.assertLess(im.tell(), n_frames)
# Test seeking past the last frame
self.assertRaises(EOFError, im.seek, n_frames)
self.assertLess(im.tell(), n_frames)
# Test that seeking to the last frame does not raise an error
im.seek(n_frames-1)
def test_seek_too_far(self):
# Arrange

View File

@ -54,24 +54,14 @@ class TestFileFli(PillowTestCase):
def test_eoferror(self):
im = Image.open(animated_test_file)
n_frames = im.n_frames
while True:
n_frames -= 1
try:
im.seek(n_frames)
break
except EOFError:
self.assertLess(im.tell(), n_frames)
def test_seek_outside(self):
# Test negative seek
im = Image.open(static_test_file)
im.seek(-1)
self.assertEqual(im.tell(), 0)
# Test seeking past the last frame
self.assertRaises(EOFError, im.seek, n_frames)
self.assertLess(im.tell(), n_frames)
# Test seek past end of file
self.assertRaises(EOFError, im.seek, 2)
# Test that seeking to the last frame does not raise an error
im.seek(n_frames-1)
def test_seek_tell(self):
im = Image.open(animated_test_file)
@ -91,6 +81,10 @@ class TestFileFli(PillowTestCase):
layer_number = im.tell()
self.assertEqual(layer_number, 2)
im.seek(1)
layer_number = im.tell()
self.assertEqual(layer_number, 1)
if __name__ == '__main__':
unittest.main()

View File

@ -223,15 +223,14 @@ class TestFileGif(PillowTestCase):
def test_eoferror(self):
im = Image.open(TEST_GIF)
n_frames = im.n_frames
while True:
n_frames -= 1
try:
im.seek(n_frames)
break
except EOFError:
self.assertLess(im.tell(), n_frames)
# Test seeking past the last frame
self.assertRaises(EOFError, im.seek, n_frames)
self.assertLess(im.tell(), n_frames)
# Test that seeking to the last frame does not raise an error
im.seek(n_frames-1)
def test_dispose_none(self):
img = Image.open("Tests/images/dispose_none.gif")

View File

@ -32,15 +32,14 @@ class TestFileIm(PillowTestCase):
def test_eoferror(self):
im = Image.open(TEST_IM)
n_frames = im.n_frames
while True:
n_frames -= 1
try:
im.seek(n_frames)
break
except EOFError:
self.assertLess(im.tell(), n_frames)
# Test seeking past the last frame
self.assertRaises(EOFError, im.seek, n_frames)
self.assertLess(im.tell(), n_frames)
# Test that seeking to the last frame does not raise an error
im.seek(n_frames-1)
def test_roundtrip(self):
for mode in ["RGB", "P"]:

View File

@ -102,15 +102,14 @@ class TestFileMpo(PillowTestCase):
def test_eoferror(self):
im = Image.open("Tests/images/sugarshack.mpo")
n_frames = im.n_frames
while True:
n_frames -= 1
try:
im.seek(n_frames)
break
except EOFError:
self.assertLess(im.tell(), n_frames)
# Test seeking past the last frame
self.assertRaises(EOFError, im.seek, n_frames)
self.assertLess(im.tell(), n_frames)
# Test that seeking to the last frame does not raise an error
im.seek(n_frames-1)
def test_image_grab(self):
for test_file in test_files:

View File

@ -250,15 +250,14 @@ class TestFileTiff(PillowTestCase):
def test_eoferror(self):
im = Image.open('Tests/images/multipage-lastframe.tif')
n_frames = im.n_frames
while True:
n_frames -= 1
try:
im.seek(n_frames)
break
except EOFError:
self.assertLess(im.tell(), n_frames)
# Test seeking past the last frame
self.assertRaises(EOFError, im.seek, n_frames)
self.assertLess(im.tell(), n_frames)
# Test that seeking to the last frame does not raise an error
im.seek(n_frames-1)
def test_multipage(self):
# issue #862