2019-01-13 20:00:12 +03:00
|
|
|
from .helper import unittest, PillowTestCase, hopper
|
2015-07-03 08:03:25 +03:00
|
|
|
|
2017-12-20 15:22:28 +03:00
|
|
|
from PIL import Image, ImagePalette, features
|
2017-10-04 16:34:56 +03:00
|
|
|
|
|
|
|
try:
|
|
|
|
from PIL import MicImagePlugin
|
|
|
|
except ImportError:
|
|
|
|
olefile_installed = False
|
|
|
|
else:
|
|
|
|
olefile_installed = True
|
2017-03-13 09:18:13 +03:00
|
|
|
|
|
|
|
TEST_FILE = "Tests/images/hopper.mic"
|
2015-07-03 08:03:25 +03:00
|
|
|
|
|
|
|
|
2017-10-04 16:34:56 +03:00
|
|
|
@unittest.skipUnless(olefile_installed, "olefile package not installed")
|
2017-12-20 15:22:28 +03:00
|
|
|
@unittest.skipUnless(features.check('libtiff'), "libtiff not installed")
|
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")
|
|
|
|
|
2017-06-13 23:07:46 +03:00
|
|
|
# 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")
|
2017-06-13 23:07:46 +03:00
|
|
|
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)
|