2014-07-07 21:03:50 +04:00
|
|
|
from helper import unittest, PillowTestCase, lena
|
2014-05-26 21:09:12 +04:00
|
|
|
|
|
|
|
from PIL import Image
|
2014-05-26 22:00:20 +04:00
|
|
|
from PIL import SpiderImagePlugin
|
2014-05-26 21:09:12 +04:00
|
|
|
|
2014-07-15 13:23:02 +04:00
|
|
|
TEST_FILE = "Tests/images/lena.spider"
|
2014-05-26 21:09:12 +04:00
|
|
|
|
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
class TestImageSpider(PillowTestCase):
|
2014-05-26 21:09:12 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
def test_sanity(self):
|
2014-07-15 13:23:02 +04:00
|
|
|
im = Image.open(TEST_FILE)
|
2014-06-10 13:10:47 +04:00
|
|
|
im.load()
|
|
|
|
self.assertEqual(im.mode, "F")
|
|
|
|
self.assertEqual(im.size, (128, 128))
|
|
|
|
self.assertEqual(im.format, "SPIDER")
|
2014-05-26 22:00:20 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
def test_save(self):
|
|
|
|
# Arrange
|
|
|
|
temp = self.tempfile('temp.spider')
|
|
|
|
im = lena()
|
2014-05-26 22:00:20 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
# Act
|
|
|
|
im.save(temp, "SPIDER")
|
2014-05-26 22:00:20 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
# Assert
|
|
|
|
im2 = Image.open(temp)
|
|
|
|
self.assertEqual(im2.mode, "F")
|
|
|
|
self.assertEqual(im2.size, (128, 128))
|
|
|
|
self.assertEqual(im2.format, "SPIDER")
|
2014-05-26 22:00:20 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
def test_isSpiderImage(self):
|
2014-07-15 13:23:02 +04:00
|
|
|
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)
|
2014-05-26 22:00:20 +04:00
|
|
|
|
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|
2014-05-26 22:00:20 +04:00
|
|
|
|
2014-05-26 21:09:12 +04:00
|
|
|
# End of file
|