Pillow/Tests/test_file_pcx.py

54 lines
1.6 KiB
Python
Raw Normal View History

2014-09-05 13:36:24 +04:00
from helper import unittest, PillowTestCase, hopper
2015-07-03 08:03:25 +03:00
from PIL import Image, PcxImagePlugin
2014-06-10 13:10:47 +04:00
class TestFilePcx(PillowTestCase):
def _roundtrip(self, im):
f = self.tempfile("temp.pcx")
im.save(f)
im2 = Image.open(f)
self.assertEqual(im2.mode, im.mode)
self.assertEqual(im2.size, im.size)
self.assertEqual(im2.format, "PCX")
self.assert_image_equal(im2, im)
def test_sanity(self):
for mode in ('1', 'L', 'P', 'RGB'):
2014-09-05 13:36:24 +04:00
self._roundtrip(hopper(mode))
2014-06-10 13:10:47 +04:00
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: PcxImagePlugin.PcxImageFile(invalid_file))
2015-07-03 08:03:25 +03:00
2014-06-10 13:10:47 +04:00
def test_odd(self):
# see issue #523, odd sized images should have a stride that's even.
# not that imagemagick or gimp write pcx that way.
# we were not handling properly.
for mode in ('1', 'L', 'P', 'RGB'):
# larger, odd sized images are better here to ensure that
# we handle interrupted scan lines properly.
2014-09-05 13:36:24 +04:00
self._roundtrip(hopper(mode).resize((511, 511)))
2014-06-10 13:10:47 +04:00
def test_pil184(self):
# Check reading of files where xmin/xmax is not zero.
2015-04-24 11:24:52 +03:00
test_file = "Tests/images/pil184.pcx"
im = Image.open(test_file)
2014-06-10 13:10:47 +04:00
self.assertEqual(im.size, (447, 144))
self.assertEqual(im.tile[0][1], (0, 0, 447, 144))
# Make sure all pixels are either 0 or 255.
self.assertEqual(im.histogram()[0] + im.histogram()[255], 447*144)
if __name__ == '__main__':
unittest.main()
# End of file