Pillow/Tests/test_file_ico.py

51 lines
1.4 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
2012-10-26 02:00:19 +04:00
from PIL import Image
# 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")
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)
2014-11-13 09:45:35 +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")
2014-11-13 09:45:35 +03:00
self.assert_image_equal(reloaded, hopper().resize((64,64), Image.ANTIALIAS))
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)
reloaded.size = (32,32)
self.assertEqual(im.mode, reloaded.mode)
self.assertEqual((32, 32), reloaded.size)
self.assertEqual(reloaded.format, "ICO")
self.assert_image_equal(reloaded, hopper().resize((32,32), Image.ANTIALIAS))
2014-06-10 13:10:47 +04:00
if __name__ == '__main__':
unittest.main()
# End of file