Pillow/Tests/test_file_xvthumb.py

36 lines
997 B
Python
Raw Normal View History

from PIL import Image, XVThumbImagePlugin
from .helper import PillowTestCase, hopper
TEST_FILE = "Tests/images/hopper.p7"
2017-03-01 12:20:18 +03:00
class TestFileXVThumb(PillowTestCase):
def test_open(self):
# Act
2019-11-25 23:03:23 +03:00
with Image.open(TEST_FILE) as im:
2019-11-25 23:03:23 +03:00
# Assert
self.assertEqual(im.format, "XVThumb")
2019-11-25 23:03:23 +03:00
# Create a Hopper image with a similar XV palette
im_hopper = hopper().quantize(palette=im)
self.assert_image_similar(im, im_hopper, 9)
2017-03-05 00:33:43 +03:00
def test_unexpected_eof(self):
# Test unexpected EOF reading XV thumbnail file
# Arrange
bad_file = "Tests/images/hopper_bad.p7"
# Act / Assert
2019-06-13 18:54:11 +03:00
self.assertRaises(SyntaxError, XVThumbImagePlugin.XVThumbImageFile, bad_file)
2017-03-05 00:33:43 +03:00
2017-03-01 12:20:18 +03:00
def test_invalid_file(self):
2017-03-05 00:33:43 +03:00
# Arrange
2017-03-01 12:20:18 +03:00
invalid_file = "Tests/images/flower.jpg"
2017-03-05 00:33:43 +03:00
# Act / Assert
2019-06-13 18:54:11 +03:00
self.assertRaises(
SyntaxError, XVThumbImagePlugin.XVThumbImageFile, invalid_file
)