2019-07-06 23:40:53 +03:00
|
|
|
import os
|
2019-11-21 05:42:52 +03:00
|
|
|
import unittest
|
2014-07-16 15:24:23 +04:00
|
|
|
|
2015-07-03 08:03:25 +03:00
|
|
|
from PIL import Image, SunImagePlugin
|
2014-07-16 15:24:23 +04:00
|
|
|
|
2020-01-30 17:56:07 +03:00
|
|
|
from .helper import PillowTestCase, assert_image_equal, assert_image_similar, hopper
|
2016-11-22 17:47:33 +03:00
|
|
|
|
2019-06-13 18:54:11 +03:00
|
|
|
EXTRA_DIR = "Tests/images/sunraster"
|
2014-07-16 15:24:23 +04:00
|
|
|
|
2017-04-20 14:14:23 +03:00
|
|
|
|
2014-07-16 15:24:23 +04:00
|
|
|
class TestFileSun(PillowTestCase):
|
|
|
|
def test_sanity(self):
|
|
|
|
# Arrange
|
2014-09-04 13:59:03 +04:00
|
|
|
# Created with ImageMagick: convert hopper.jpg hopper.ras
|
|
|
|
test_file = "Tests/images/hopper.ras"
|
2014-07-16 15:24:23 +04:00
|
|
|
|
|
|
|
# Act
|
2019-11-25 23:03:23 +03:00
|
|
|
with Image.open(test_file) as im:
|
2014-07-16 15:24:23 +04:00
|
|
|
|
2019-11-25 23:03:23 +03:00
|
|
|
# Assert
|
|
|
|
self.assertEqual(im.size, (128, 128))
|
2014-07-16 15:24:23 +04:00
|
|
|
|
2020-01-30 17:56:07 +03:00
|
|
|
assert_image_similar(im, hopper(), 5) # visually verified
|
2017-04-20 14:14:23 +03:00
|
|
|
|
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, SunImagePlugin.SunImageFile, invalid_file)
|
2015-07-03 08:03:25 +03:00
|
|
|
|
2016-11-20 06:12:30 +03:00
|
|
|
def test_im1(self):
|
2019-11-25 23:03:23 +03:00
|
|
|
with Image.open("Tests/images/sunraster.im1") as im:
|
|
|
|
with Image.open("Tests/images/sunraster.im1.png") as target:
|
2020-01-30 17:56:07 +03:00
|
|
|
assert_image_equal(im, target)
|
2016-11-22 17:47:33 +03:00
|
|
|
|
2019-12-25 06:13:16 +03:00
|
|
|
@unittest.skipUnless(os.path.exists(EXTRA_DIR), "Extra image files not installed")
|
2016-11-22 17:47:33 +03:00
|
|
|
def test_others(self):
|
2019-06-13 18:54:11 +03:00
|
|
|
files = (
|
|
|
|
os.path.join(EXTRA_DIR, f)
|
|
|
|
for f in os.listdir(EXTRA_DIR)
|
|
|
|
if os.path.splitext(f)[1] in (".sun", ".SUN", ".ras")
|
|
|
|
)
|
2016-11-22 17:47:33 +03:00
|
|
|
for path in files:
|
|
|
|
with Image.open(path) as im:
|
2017-04-20 14:14:23 +03:00
|
|
|
im.load()
|
2016-11-22 17:47:33 +03:00
|
|
|
self.assertIsInstance(im, SunImagePlugin.SunImageFile)
|
|
|
|
target_path = "%s.png" % os.path.splitext(path)[0]
|
2017-04-20 14:14:23 +03:00
|
|
|
# im.save(target_file)
|
2016-11-22 17:47:33 +03:00
|
|
|
with Image.open(target_path) as target:
|
2020-01-30 17:56:07 +03:00
|
|
|
assert_image_equal(im, target)
|