2017-03-04 20:54:06 +03:00
|
|
|
from helper import hopper, unittest, PillowTestCase
|
2017-03-01 12:20:18 +03:00
|
|
|
|
2017-03-04 20:54:06 +03:00
|
|
|
from PIL import Image, XVThumbImagePlugin
|
|
|
|
|
|
|
|
TEST_FILE = "Tests/images/hopper.p7"
|
2017-03-01 12:20:18 +03:00
|
|
|
|
|
|
|
|
|
|
|
class TestFileXVThumb(PillowTestCase):
|
|
|
|
|
2017-03-04 20:54:06 +03:00
|
|
|
def test_open(self):
|
|
|
|
# Act
|
|
|
|
im = Image.open(TEST_FILE)
|
|
|
|
|
|
|
|
# Assert
|
|
|
|
self.assertEqual(im.format, "XVThumb")
|
2017-03-06 18:33:47 +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-04 20:54:06 +03:00
|
|
|
|
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
|
|
|
|
self.assertRaises(SyntaxError,
|
2017-09-01 14:05:40 +03:00
|
|
|
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
|
2017-03-01 12:20:18 +03:00
|
|
|
self.assertRaises(SyntaxError,
|
2017-09-01 14:05:40 +03:00
|
|
|
XVThumbImagePlugin.XVThumbImageFile, invalid_file)
|
2017-03-01 12:20:18 +03:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|