Pillow/Tests/test_file_sun.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

50 lines
1.3 KiB
Python
Raw Normal View History

from __future__ import annotations
2024-01-20 14:23:03 +03:00
import os
2014-07-16 15:24:23 +04:00
2020-02-12 19:29:19 +03:00
import pytest
2020-09-01 20:16:46 +03:00
2015-07-03 08:03:25 +03:00
from PIL import Image, SunImagePlugin
2014-07-16 15:24:23 +04:00
from .helper import assert_image_equal_tofile, assert_image_similar, hopper
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
def test_sanity() -> None:
2020-02-12 19:29:19 +03:00
# Arrange
# Created with ImageMagick: convert hopper.jpg hopper.ras
test_file = "Tests/images/hopper.ras"
2014-07-16 15:24:23 +04:00
2020-02-12 19:29:19 +03:00
# Act
with Image.open(test_file) as im:
# Assert
assert im.size == (128, 128)
2014-07-16 15:24:23 +04:00
2020-02-12 19:29:19 +03:00
assert_image_similar(im, hopper(), 5) # visually verified
2017-04-20 14:14:23 +03:00
2020-02-12 19:29:19 +03:00
invalid_file = "Tests/images/flower.jpg"
with pytest.raises(SyntaxError):
SunImagePlugin.SunImageFile(invalid_file)
2015-07-03 08:03:25 +03:00
def test_im1() -> None:
2020-02-12 19:29:19 +03:00
with Image.open("Tests/images/sunraster.im1") as im:
assert_image_equal_tofile(im, "Tests/images/sunraster.im1.png")
2020-02-12 19:29:19 +03:00
@pytest.mark.skipif(
not os.path.exists(EXTRA_DIR), reason="Extra image files not installed"
)
def test_others() -> None:
2020-02-12 19:29:19 +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")
)
for path in files:
with Image.open(path) as im:
im.load()
assert isinstance(im, SunImagePlugin.SunImageFile)
assert_image_equal_tofile(im, f"{os.path.splitext(path)[0]}.png")