Added tests

This commit is contained in:
Andrew Murray 2015-06-08 01:01:34 +10:00
parent 0c51b7967e
commit 46f439604c
11 changed files with 67 additions and 2 deletions

View File

@ -131,7 +131,6 @@ class FliImageFile(ImageFile.ImageFile):
self._seek(f)
def _seek(self, frame):
if frame == 0:
self.__frame = -1
self.__fp.seek(self.__rewind)
@ -157,7 +156,6 @@ class FliImageFile(ImageFile.ImageFile):
self.__offset += framesize
def tell(self):
return self.__frame
#

BIN
Tests/images/hopper.im Normal file

Binary file not shown.

Binary file not shown.

View File

@ -30,6 +30,10 @@ class TestFileDcx(PillowTestCase):
# Assert
self.assertEqual(frame, 0)
def test_n_frames(self):
im = Image.open(TEST_FILE)
self.assertEqual(im.n_frames, 1)
def test_seek_too_far(self):
# Arrange
im = Image.open(TEST_FILE)

View File

@ -18,6 +18,10 @@ class TestFileFli(PillowTestCase):
self.assertEqual(im.size, (128, 128))
self.assertEqual(im.format, "FLI")
def test_n_frames(self):
im = Image.open(test_file)
self.assertEqual(im.n_frames, 2)
if __name__ == '__main__':
unittest.main()

View File

@ -134,6 +134,10 @@ class TestFileGif(PillowTestCase):
except EOFError:
self.assertEqual(framecount, 5)
def test_n_frames(self):
im = Image.open("Tests/images/iss634.gif")
self.assertEqual(im.n_frames, 43)
def test_dispose_none(self):
img = Image.open("Tests/images/dispose_none.gif")
try:

33
Tests/test_file_im.py Normal file
View File

@ -0,0 +1,33 @@
from helper import unittest, PillowTestCase, hopper
from PIL import Image
# sample im
TEST_IM = "Tests/images/hopper.im"
class TestFileIm(PillowTestCase):
def test_sanity(self):
im = Image.open(TEST_IM)
im.load()
self.assertEqual(im.mode, "RGB")
self.assertEqual(im.size, (128, 128))
self.assertEqual(im.format, "IM")
def test_n_frames(self):
im = Image.open(TEST_IM)
self.assertEqual(im.n_frames, 1)
def test_roundtrip(self):
out = self.tempfile('temp.im')
im = hopper()
im.save(out)
reread = Image.open(out)
self.assert_image_equal(reread, im)
if __name__ == '__main__':
unittest.main()
# End of file

View File

@ -95,6 +95,10 @@ class TestFileMpo(PillowTestCase):
im.seek(0)
self.assertEqual(im.tell(), 0)
def test_n_frames(self):
im = Image.open("Tests/images/sugarshack.mpo")
self.assertEqual(im.n_frames, 2)
def test_image_grab(self):
for test_file in test_files:
im = Image.open(test_file)

View File

@ -16,6 +16,13 @@ class TestImagePsd(PillowTestCase):
self.assertEqual(im.size, (128, 128))
self.assertEqual(im.format, "PSD")
def test_n_frames(self):
im = Image.open("Tests/images/hopper_merged.psd")
self.assertEqual(im.n_frames, 1)
im = Image.open(test_file)
self.assertEqual(im.n_frames, 2)
if __name__ == '__main__':
unittest.main()

View File

@ -42,6 +42,10 @@ class TestImageSpider(PillowTestCase):
# Assert
self.assertEqual(index, 0)
def test_n_frames(self):
im = Image.open(TEST_FILE)
self.assertEqual(im.n_frames, 1)
def test_loadImageSeries(self):
# Arrange
not_spider_file = "Tests/images/hopper.ppm"

View File

@ -150,6 +150,13 @@ class TestFileTiff(PillowTestCase):
self.assertEqual(
im.getextrema(), (-3.140936851501465, 3.140684127807617))
def test_n_frames(self):
im = Image.open('Tests/images/multipage-lastframe.tif')
self.assertEqual(im.n_frames, 1)
im = Image.open('Tests/images/multipage.tiff')
self.assertEqual(im.n_frames, 3)
def test_multipage(self):
# issue #862
im = Image.open('Tests/images/multipage.tiff')