Pillow/Tests/test_file_ico.py

54 lines
1.6 KiB
Python
Raw Normal View History

2014-11-08 09:49:50 +03:00
from helper import unittest, PillowTestCase, hopper
2012-10-26 02:00:19 +04:00
2014-11-08 09:49:50 +03:00
import io
2015-07-03 08:03:25 +03:00
from PIL import Image, IcoImagePlugin
2012-10-26 02:00:19 +04:00
# sample ppm stream
TEST_ICO_FILE = "Tests/images/hopper.ico"
TEST_DATA = open(TEST_ICO_FILE, "rb").read()
2012-10-26 02:00:19 +04:00
2014-06-10 13:10:47 +04:00
class TestFileIco(PillowTestCase):
def test_sanity(self):
im = Image.open(TEST_ICO_FILE)
2014-06-10 13:10:47 +04:00
im.load()
self.assertEqual(im.mode, "RGBA")
self.assertEqual(im.size, (16, 16))
self.assertEqual(im.format, "ICO")
2015-07-03 08:03:25 +03:00
def test_invalid_file(self):
with open("Tests/images/flower.jpg", "rb") as fp:
self.assertRaises(SyntaxError, lambda: IcoImagePlugin.IcoImageFile(fp))
2014-11-08 09:49:50 +03:00
def test_save_to_bytes(self):
output = io.BytesIO()
im = hopper()
im.save(output, "ico", sizes=[(32, 32), (64, 64)])
2014-11-13 09:45:35 +03:00
# the default image
2014-11-08 09:49:50 +03:00
output.seek(0)
reloaded = Image.open(output)
2015-04-24 02:26:52 +03:00
self.assertEqual(reloaded.info['sizes'], set([(32, 32), (64, 64)]))
2014-11-08 09:49:50 +03:00
self.assertEqual(im.mode, reloaded.mode)
self.assertEqual((64, 64), reloaded.size)
self.assertEqual(reloaded.format, "ICO")
2015-04-24 02:26:52 +03:00
self.assert_image_equal(reloaded, hopper().resize((64, 64), Image.LANCZOS))
2014-11-08 09:49:50 +03:00
2014-11-13 09:45:35 +03:00
# the other one
output.seek(0)
reloaded = Image.open(output)
2015-04-24 02:26:52 +03:00
reloaded.size = (32, 32)
2014-11-13 09:45:35 +03:00
self.assertEqual(im.mode, reloaded.mode)
self.assertEqual((32, 32), reloaded.size)
self.assertEqual(reloaded.format, "ICO")
2015-04-24 02:26:52 +03:00
self.assert_image_equal(reloaded, hopper().resize((32, 32), Image.LANCZOS))
2014-06-10 13:10:47 +04:00
if __name__ == '__main__':
unittest.main()
# End of file