Pillow/Tests/test_file_xpm.py

34 lines
884 B
Python
Raw Normal View History

2015-07-03 08:03:25 +03:00
from PIL import Image, XpmImagePlugin
from .helper import PillowTestCase, hopper
2014-09-23 17:01:58 +04:00
TEST_FILE = "Tests/images/hopper.xpm"
2014-06-10 13:10:47 +04:00
class TestFileXpm(PillowTestCase):
def test_sanity(self):
im = Image.open(TEST_FILE)
2014-06-10 13:10:47 +04:00
im.load()
self.assertEqual(im.mode, "P")
self.assertEqual(im.size, (128, 128))
self.assertEqual(im.format, "XPM")
2015-04-24 02:26:52 +03:00
# large error due to quantization->44 colors.
2019-06-13 18:54:11 +03:00
self.assert_image_similar(im.convert("RGB"), hopper("RGB"), 60)
2015-07-03 08:03:25 +03:00
def test_invalid_file(self):
2015-07-03 09:22:56 +03:00
invalid_file = "Tests/images/flower.jpg"
2019-06-13 18:54:11 +03:00
self.assertRaises(SyntaxError, XpmImagePlugin.XpmImageFile, invalid_file)
2015-07-03 08:03:25 +03:00
2014-07-17 03:38:57 +04:00
def test_load_read(self):
# Arrange
im = Image.open(TEST_FILE)
2014-07-17 03:38:57 +04:00
dummy_bytes = 1
# Act
data = im.load_read(dummy_bytes)
# Assert
self.assertEqual(len(data), 16384)