Skip to content

Commit c000472

Browse files
authored
Improve WalImageFile test coverage (#9189)
2 parents f570c67 + cfca02a commit c000472

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

Tests/test_file_wal.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
from io import BytesIO
4+
35
from PIL import WalImageFile
46

57
from .helper import assert_image_equal_tofile
@@ -13,12 +15,22 @@ def test_open() -> None:
1315
assert im.format_description == "Quake2 Texture"
1416
assert im.mode == "P"
1517
assert im.size == (128, 128)
18+
assert "next_name" not in im.info
1619

1720
assert isinstance(im, WalImageFile.WalImageFile)
1821

1922
assert_image_equal_tofile(im, "Tests/images/hopper_wal.png")
2023

2124

25+
def test_next_name() -> None:
26+
with open(TEST_FILE, "rb") as fp:
27+
data = bytearray(fp.read())
28+
data[56:60] = b"Test"
29+
f = BytesIO(data)
30+
with WalImageFile.open(f) as im:
31+
assert im.info["next_name"] == b"Test"
32+
33+
2234
def test_load() -> None:
2335
with WalImageFile.open(TEST_FILE) as im:
2436
px = im.load()

src/PIL/WalImageFile.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ def _open(self) -> None:
4949

5050
# strings are null-terminated
5151
self.info["name"] = header[:32].split(b"\0", 1)[0]
52-
next_name = header[56 : 56 + 32].split(b"\0", 1)[0]
53-
if next_name:
52+
if next_name := header[56 : 56 + 32].split(b"\0", 1)[0]:
5453
self.info["next_name"] = next_name
5554

5655
def load(self) -> Image.core.PixelAccess | None:

0 commit comments

Comments
 (0)