Pillow/Tests/test_file_xpm.py

40 lines
977 B
Python
Raw Normal View History

2014-09-23 17:01:58 +04:00
from helper import unittest, PillowTestCase, hopper
2015-07-03 08:03:25 +03:00
from PIL import Image, XpmImagePlugin
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.
2014-09-23 17:01:58 +04: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"
self.assertRaises(SyntaxError,
lambda: 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)
2014-06-10 13:10:47 +04:00
if __name__ == '__main__':
unittest.main()