More tests for SpiderImagePlugin.py

This commit is contained in:
hugovk 2014-07-15 12:23:02 +03:00
parent ffa22229bc
commit 6c9940e9d1

View File

@ -3,13 +3,13 @@ from helper import unittest, PillowTestCase, lena
from PIL import Image from PIL import Image
from PIL import SpiderImagePlugin from PIL import SpiderImagePlugin
test_file = "Tests/images/lena.spider" TEST_FILE = "Tests/images/lena.spider"
class TestImageSpider(PillowTestCase): class TestImageSpider(PillowTestCase):
def test_sanity(self): def test_sanity(self):
im = Image.open(test_file) im = Image.open(TEST_FILE)
im.load() im.load()
self.assertEqual(im.mode, "F") self.assertEqual(im.mode, "F")
self.assertEqual(im.size, (128, 128)) self.assertEqual(im.size, (128, 128))
@ -30,7 +30,50 @@ class TestImageSpider(PillowTestCase):
self.assertEqual(im2.format, "SPIDER") self.assertEqual(im2.format, "SPIDER")
def test_isSpiderImage(self): def test_isSpiderImage(self):
self.assertTrue(SpiderImagePlugin.isSpiderImage(test_file)) self.assertTrue(SpiderImagePlugin.isSpiderImage(TEST_FILE))
def test_tell(self):
# Arrange
im = Image.open(TEST_FILE)
# Act
index = im.tell()
# Assert
self.assertEqual(index, 0)
def test_loadImageSeries(self):
# Arrange
not_spider_file = "Tests/images/lena.ppm"
file_list = [TEST_FILE, not_spider_file, "path/not_found.ext"]
# Act
img_list = SpiderImagePlugin.loadImageSeries(file_list)
# Assert
self.assertEqual(len(img_list), 1)
self.assertIsInstance(img_list[0], Image.Image)
self.assertEqual(img_list[0].size, (128, 128))
def test_loadImageSeries_no_input(self):
# Arrange
file_list = None
# Act
img_list = SpiderImagePlugin.loadImageSeries(file_list)
# Assert
self.assertEqual(img_list, None)
def test_isInt_not_a_number(self):
# Arrange
not_a_number = "a"
# Act
ret = SpiderImagePlugin.isInt(not_a_number)
# Assert
self.assertEqual(ret, 0)
if __name__ == '__main__': if __name__ == '__main__':