tests/images.py
Rama main · réplica de lectura del repositorio original.
"""Real, decodable images built with the standard library, for tests."""
from __future__ import annotations
import struct
import zlib
def png(width: int = 2, height: int = 2) -> bytes:
"""A valid grey PNG of ``width`` x ``height``."""
def chunk(kind: bytes, body: bytes) -> bytes:
return (struct.pack(">I", len(body)) + kind + body
+ struct.pack(">I", zlib.crc32(kind + body) & 0xFFFFFFFF))
rows = b"".join(b"\x00" + b"\x80" * width for _ in range(height))
return (b"\x89PNG\r\n\x1a\n"
+ chunk(b"IHDR", struct.pack(">IIBBBBB", width, height, 8, 0, 0, 0, 0))
+ chunk(b"IDAT", zlib.compress(rows)) + chunk(b"IEND", b""))