mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-29 11:26:17 +03:00
77 lines
2.3 KiB
Python
77 lines
2.3 KiB
Python
from helper import unittest, PillowTestCase, hopper
|
|
|
|
from PIL import Image, SgiImagePlugin
|
|
|
|
|
|
class TestFileSgi(PillowTestCase):
|
|
|
|
def test_rgb(self):
|
|
# Created with ImageMagick then renamed:
|
|
# convert hopper.ppm -compress None sgi:hopper.rgb
|
|
test_file = "Tests/images/hopper.rgb"
|
|
|
|
im = Image.open(test_file)
|
|
self.assert_image_equal(im, hopper())
|
|
|
|
def test_l(self):
|
|
# Created with ImageMagick
|
|
# convert hopper.ppm -monochrome -compress None sgi:hopper.bw
|
|
test_file = "Tests/images/hopper.bw"
|
|
|
|
im = Image.open(test_file)
|
|
self.assert_image_similar(im, hopper('L'), 2)
|
|
|
|
def test_rgba(self):
|
|
# Created with ImageMagick:
|
|
# convert transparent.png -compress None transparent.sgi
|
|
test_file = "Tests/images/transparent.sgi"
|
|
|
|
im = Image.open(test_file)
|
|
target = Image.open('Tests/images/transparent.png')
|
|
self.assert_image_equal(im, target)
|
|
|
|
def test_rle(self):
|
|
# convert hopper.ppm hopper.sgi
|
|
# We don't support RLE compression, this should throw a value error
|
|
test_file = "Tests/images/hopper.sgi"
|
|
|
|
with self.assertRaises(ValueError):
|
|
Image.open(test_file)
|
|
|
|
def test_invalid_file(self):
|
|
invalid_file = "Tests/images/flower.jpg"
|
|
|
|
self.assertRaises(ValueError,
|
|
lambda:
|
|
SgiImagePlugin.SgiImageFile(invalid_file))
|
|
|
|
def test_write(self):
|
|
def roundtrip(img):
|
|
out = self.tempfile('temp.sgi')
|
|
img.save(out, format='sgi')
|
|
reloaded = Image.open(out)
|
|
self.assert_image_equal(img, reloaded)
|
|
|
|
for mode in ('L', 'RGB', 'RGBA'):
|
|
roundtrip(hopper(mode))
|
|
|
|
# Test 1 dimension for an L mode image
|
|
roundtrip(Image.new('L', (10, 1)))
|
|
|
|
def test_unsupported_mode(self):
|
|
im = hopper('LA')
|
|
out = self.tempfile('temp.sgi')
|
|
|
|
self.assertRaises(ValueError, lambda: im.save(out, format='sgi'))
|
|
|
|
def test_incorrect_number_of_bands(self):
|
|
im = hopper('YCbCr')
|
|
im.mode = 'RGB'
|
|
out = self.tempfile('temp.sgi')
|
|
|
|
self.assertRaises(ValueError, lambda: im.save(out, format='sgi'))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|