1
from __future__ import annotations
3
from pathlib import Path
11
assert_image_equal_tofile,
17
def test_load_blp1() -> None:
18
with Image.open("Tests/images/blp/blp1_jpeg.blp") as im:
19
assert_image_equal_tofile(im, "Tests/images/blp/blp1_jpeg.png")
21
with Image.open("Tests/images/blp/blp1_jpeg2.blp") as im:
25
def test_load_blp2_raw() -> None:
26
with Image.open("Tests/images/blp/blp2_raw.blp") as im:
27
assert_image_equal_tofile(im, "Tests/images/blp/blp2_raw.png")
30
def test_load_blp2_dxt1() -> None:
31
with Image.open("Tests/images/blp/blp2_dxt1.blp") as im:
32
assert_image_equal_tofile(im, "Tests/images/blp/blp2_dxt1.png")
35
def test_load_blp2_dxt1a() -> None:
36
with Image.open("Tests/images/blp/blp2_dxt1a.blp") as im:
37
assert_image_equal_tofile(im, "Tests/images/blp/blp2_dxt1a.png")
40
def test_save(tmp_path: Path) -> None:
41
f = str(tmp_path / "temp.blp")
43
for version in ("BLP1", "BLP2"):
45
im.save(f, blp_version=version)
47
with Image.open(f) as reloaded:
48
assert_image_equal(im.convert("RGB"), reloaded)
50
with Image.open("Tests/images/transparent.png") as im:
51
f = str(tmp_path / "temp.blp")
52
im.convert("P").save(f, blp_version=version)
54
with Image.open(f) as reloaded:
55
assert_image_similar(im, reloaded, 8)
58
with pytest.raises(ValueError):
62
@pytest.mark.parametrize(
65
"Tests/images/timeout-060745d3f534ad6e4128c51d336ea5489182c69d.blp",
66
"Tests/images/timeout-31c8f86233ea728339c6e586be7af661a09b5b98.blp",
67
"Tests/images/timeout-60d8b7c8469d59fc9ffff6b3a3dc0faeae6ea8ee.blp",
68
"Tests/images/timeout-8073b430977660cdd48d96f6406ddfd4114e69c7.blp",
69
"Tests/images/timeout-bba4f2e026b5786529370e5dfe9a11b1bf991f07.blp",
70
"Tests/images/timeout-d6ec061c4afdef39d3edf6da8927240bb07fe9b7.blp",
71
"Tests/images/timeout-ef9112a065e7183fa7faa2e18929b03e44ee16bf.blp",
74
def test_crashes(test_file: str) -> None:
75
with open(test_file, "rb") as f:
76
with Image.open(f) as im:
77
with pytest.raises(OSError):