Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Tests/test_file_wal.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from io import BytesIO

from PIL import WalImageFile

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

assert isinstance(im, WalImageFile.WalImageFile)

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


def test_next_name() -> None:
with open(TEST_FILE, "rb") as fp:
data = bytearray(fp.read())
data[56:60] = b"Test"
f = BytesIO(data)
with WalImageFile.open(f) as im:
assert im.info["next_name"] == b"Test"


def test_load() -> None:
with WalImageFile.open(TEST_FILE) as im:
px = im.load()
Expand Down
3 changes: 1 addition & 2 deletions src/PIL/WalImageFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ def _open(self) -> None:

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

def load(self) -> Image.core.PixelAccess | None:
Expand Down
Loading