diff --git a/Tests/test_file_dcx.py b/Tests/test_file_dcx.py index 5e73fd10f..28ebb91dc 100644 --- a/Tests/test_file_dcx.py +++ b/Tests/test_file_dcx.py @@ -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 diff --git a/Tests/test_file_fli.py b/Tests/test_file_fli.py index 09dd8d8a7..142af3cec 100644 --- a/Tests/test_file_fli.py +++ b/Tests/test_file_fli.py @@ -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() diff --git a/Tests/test_file_gif.py b/Tests/test_file_gif.py index f5d244edf..0b52d7b44 100644 --- a/Tests/test_file_gif.py +++ b/Tests/test_file_gif.py @@ -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") diff --git a/Tests/test_file_im.py b/Tests/test_file_im.py index e42197034..c99924767 100644 --- a/Tests/test_file_im.py +++ b/Tests/test_file_im.py @@ -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"]: diff --git a/Tests/test_file_mpo.py b/Tests/test_file_mpo.py index b4d0c696e..70bb9b105 100644 --- a/Tests/test_file_mpo.py +++ b/Tests/test_file_mpo.py @@ -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: diff --git a/Tests/test_file_tiff.py b/Tests/test_file_tiff.py index f8402b47c..3ad8b2bd1 100644 --- a/Tests/test_file_tiff.py +++ b/Tests/test_file_tiff.py @@ -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