-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Expand file tree
/
Copy pathtest_file_jxl.py
More file actions
64 lines (50 loc) · 1.88 KB
/
Copy pathtest_file_jxl.py
File metadata and controls
64 lines (50 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from __future__ import annotations
import os
import re
import pytest
from PIL import Image, JpegXlImagePlugin, UnidentifiedImageError, features
from .helper import assert_image_similar_tofile, skip_unless_feature
try:
from PIL import _jpegxl
except ImportError:
pass
class TestUnsupportedJpegXl:
def test_unsupported(self, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(JpegXlImagePlugin, "SUPPORTED", False)
with pytest.raises(OSError):
with pytest.warns(UserWarning, match="JXL support not installed"):
Image.open("Tests/images/jxl/hopper.jxl")
@skip_unless_feature("jpegxl")
class TestFileJpegXl:
def test_version(self) -> None:
version = features.version_module("jpegxl")
assert version is not None
assert re.search(r"\d+\.\d+\.\d+$", version)
@pytest.mark.parametrize(
"mode, test_file",
(
("1", "hopper_bw_500.png"),
("L", "hopper_gray.jpg"),
("I;16", "jxl/16bit_subcutaneous.cropped.png"),
("RGB", "hopper.jpg"),
("RGBA", "transparent.png"),
),
)
def test_read(self, mode: str, test_file: str) -> None:
with Image.open(
"Tests/images/jxl/"
+ os.path.splitext(os.path.basename(test_file))[0]
+ ".jxl"
) as im:
assert im.format == "JPEG XL"
assert im.mode == mode
assert_image_similar_tofile(im, "Tests/images/" + test_file, 1.9)
def test_unknown_mode(self) -> None:
with pytest.raises(UnidentifiedImageError):
Image.open("Tests/images/jxl/unknown_mode.jxl")
def test_JpegXlDecode_with_invalid_args(self) -> None:
"""
Calling decoder functions with no arguments should result in an error.
"""
with pytest.raises(TypeError):
_jpegxl.JpegXlDecoder()