amayer5125 is savage
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import struct
|
||||
import zlib
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
import imagepipeline.modules # noqa: F401
|
||||
|
||||
|
||||
def make_png(
|
||||
path: Path,
|
||||
width: int = 2,
|
||||
height: int = 2,
|
||||
rgb: tuple[int, int, int] = (200, 100, 50),
|
||||
) -> None:
|
||||
"""Write a minimal valid PNG without external dependencies."""
|
||||
r, g, b = rgb
|
||||
|
||||
def chunk(tag: bytes, data: bytes) -> bytes:
|
||||
crc = zlib.crc32(tag + data) & 0xFFFFFFFF
|
||||
return struct.pack(">I", len(data)) + tag + data + struct.pack(">I", crc)
|
||||
|
||||
raw = b"".join(
|
||||
b"\x00" + bytes([r, g, b] * width)
|
||||
for _ in range(height)
|
||||
)
|
||||
compressed = zlib.compress(raw, 9)
|
||||
ihdr = struct.pack(">IIBBBBB", width, height, 8, 2, 0, 0, 0)
|
||||
png = (
|
||||
b"\x89PNG\r\n\x1a\n"
|
||||
+ chunk(b"IHDR", ihdr)
|
||||
+ chunk(b"IDAT", compressed)
|
||||
+ chunk(b"IEND", b"")
|
||||
)
|
||||
path.write_bytes(png)
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _ensure_builtin_modules() -> None:
|
||||
import imagepipeline.modules # noqa: F401
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def input_dir(tmp_path: Path) -> Path:
|
||||
directory = tmp_path / "input"
|
||||
directory.mkdir()
|
||||
make_png(directory / "photo_a.png")
|
||||
make_png(directory / "photo_b.png", rgb=(10, 20, 30))
|
||||
return directory
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def output_base(tmp_path: Path) -> Path:
|
||||
base = tmp_path / "output"
|
||||
base.mkdir()
|
||||
return base
|
||||
Reference in New Issue
Block a user