Added correctness tests for opening SGI images

This commit is contained in:
wiredfool 2016-12-30 22:20:46 +00:00
parent df5f62e719
commit 95888466c8
5 changed files with 20 additions and 14 deletions

Binary file not shown.

Binary file not shown.

BIN
Tests/images/hopper.sgi Normal file

Binary file not shown.

Binary file not shown.

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase from helper import unittest, PillowTestCase, hopper
from PIL import Image, SgiImagePlugin from PIL import Image, SgiImagePlugin
@ -6,31 +6,37 @@ from PIL import Image, SgiImagePlugin
class TestFileSgi(PillowTestCase): class TestFileSgi(PillowTestCase):
def test_rgb(self): def test_rgb(self):
# Arrange
# Created with ImageMagick then renamed: # Created with ImageMagick then renamed:
# convert hopper.ppm hopper.sgi # convert hopper.ppm -compress None sgi:hopper.rgb
test_file = "Tests/images/hopper.rgb" test_file = "Tests/images/hopper.rgb"
# Act / Assert im = Image.open(test_file)
self.assertRaises(ValueError, lambda: Image.open(test_file)) self.assert_image_equal(im, hopper())
def test_l(self): def test_l(self):
# Arrange # Created with ImageMagick
# Created with ImageMagick then renamed: # convert hopper.ppm -monochrome -compress None sgi:hopper.bw
# convert hopper.ppm -monochrome hopper.sgi
test_file = "Tests/images/hopper.bw" test_file = "Tests/images/hopper.bw"
# Act / Assert im = Image.open(test_file)
self.assertRaises(ValueError, lambda: Image.open(test_file)) self.assert_image_similar(im, hopper('L'), 2)
def test_rgba(self): def test_rgba(self):
# Arrange
# Created with ImageMagick: # Created with ImageMagick:
# convert transparent.png transparent.sgi # convert transparent.png -compress None transparent.sgi
test_file = "Tests/images/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)
# Act / Assert def test_rle(self):
self.assertRaises(ValueError, lambda: Image.open(test_file)) # 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): def test_invalid_file(self):
invalid_file = "Tests/images/flower.jpg" invalid_file = "Tests/images/flower.jpg"