Pillow/Tests/test_file_mic.py

62 lines
1.6 KiB
Python
Raw Normal View History

2017-03-13 09:18:13 +03:00
from helper import unittest, PillowTestCase, hopper
2015-07-03 08:03:25 +03:00
from PIL import Image, ImagePalette, MicImagePlugin
2017-03-13 09:18:13 +03:00
TEST_FILE = "Tests/images/hopper.mic"
2015-07-03 08:03:25 +03:00
class TestFileMic(PillowTestCase):
2017-03-13 09:18:13 +03:00
def test_sanity(self):
im = Image.open(TEST_FILE)
im.load()
self.assertEqual(im.mode, "RGBA")
self.assertEqual(im.size, (128, 128))
self.assertEqual(im.format, "MIC")
# Adjust for the gamma of 2.2 encoded into the file
lut = ImagePalette.make_gamma_lut(1/2.2)
im = Image.merge('RGBA', [chan.point(lut) for chan in im.split()])
2017-03-13 09:18:13 +03:00
im2 = hopper("RGBA")
self.assert_image_similar(im, im2, 10)
2017-03-13 09:18:13 +03:00
def test_n_frames(self):
im = Image.open(TEST_FILE)
self.assertEqual(im.n_frames, 1)
def test_is_animated(self):
im = Image.open(TEST_FILE)
self.assertFalse(im.is_animated)
def test_tell(self):
im = Image.open(TEST_FILE)
self.assertEqual(im.tell(), 0)
def test_seek(self):
im = Image.open(TEST_FILE)
im.seek(0)
self.assertEqual(im.tell(), 0)
2017-09-01 14:05:40 +03:00
self.assertRaises(EOFError, im.seek, 99)
2017-03-13 09:18:13 +03:00
self.assertEqual(im.tell(), 0)
2015-07-03 08:03:25 +03:00
def test_invalid_file(self):
2016-01-23 05:46:36 +03:00
# Test an invalid OLE file
2015-07-03 09:22:56 +03:00
invalid_file = "Tests/images/flower.jpg"
self.assertRaises(SyntaxError,
2017-09-01 14:05:40 +03:00
MicImagePlugin.MicImageFile, invalid_file)
2015-07-03 08:03:25 +03:00
2016-01-23 05:46:36 +03:00
# Test a valid OLE file, but not a MIC file
ole_file = "Tests/images/test-ole-file.doc"
self.assertRaises(SyntaxError,
2017-09-01 14:05:40 +03:00
MicImagePlugin.MicImageFile, ole_file)
2016-01-23 05:46:36 +03:00
2015-07-03 08:03:25 +03:00
if __name__ == '__main__':
unittest.main()