2023-12-21 14:13:31 +03:00
|
|
|
from __future__ import annotations
|
2024-01-20 14:23:03 +03:00
|
|
|
|
2023-03-09 05:34:44 +03:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
from PIL import Image, QoiImagePlugin
|
|
|
|
|
2023-08-31 02:27:33 +03:00
|
|
|
from .helper import assert_image_equal_tofile
|
2023-03-09 05:34:44 +03:00
|
|
|
|
|
|
|
|
2024-01-27 07:19:43 +03:00
|
|
|
def test_sanity() -> None:
|
2023-03-12 15:28:29 +03:00
|
|
|
with Image.open("Tests/images/hopper.qoi") as im:
|
|
|
|
assert im.mode == "RGB"
|
|
|
|
assert im.size == (128, 128)
|
|
|
|
assert im.format == "QOI"
|
2023-03-09 05:34:44 +03:00
|
|
|
|
2023-03-12 15:28:29 +03:00
|
|
|
assert_image_equal_tofile(im, "Tests/images/hopper.png")
|
2023-03-09 05:34:44 +03:00
|
|
|
|
2023-03-12 15:28:29 +03:00
|
|
|
with Image.open("Tests/images/pil123rgba.qoi") as im:
|
|
|
|
assert im.mode == "RGBA"
|
|
|
|
assert im.size == (162, 150)
|
|
|
|
assert im.format == "QOI"
|
2023-03-09 05:34:44 +03:00
|
|
|
|
2023-08-31 02:27:33 +03:00
|
|
|
assert_image_equal_tofile(im, "Tests/images/pil123rgba.png")
|
2023-03-09 05:34:44 +03:00
|
|
|
|
|
|
|
|
2024-01-27 07:19:43 +03:00
|
|
|
def test_invalid_file() -> None:
|
2023-03-12 15:28:29 +03:00
|
|
|
invalid_file = "Tests/images/flower.jpg"
|
|
|
|
|
|
|
|
with pytest.raises(SyntaxError):
|
|
|
|
QoiImagePlugin.QoiImageFile(invalid_file)
|