77 lines
2.4 KiB
Python
77 lines
2.4 KiB
Python
"""PNG identity includes timing, even when visible atlas pixels are identical."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import gzip
|
|
from typing import TYPE_CHECKING
|
|
|
|
import pytest
|
|
from PIL import Image
|
|
|
|
from models import Catalog, ImportFailureError
|
|
from tests.conftest import api_server, encoded, routes_for
|
|
from tests.test_import import run_cli
|
|
|
|
if TYPE_CHECKING:
|
|
from pathlib import Path
|
|
|
|
|
|
def test_transparent_animations_with_different_timing_keep_distinct_ids(
|
|
tmp_path: Path,
|
|
) -> None:
|
|
"""Distinguish frame counts even when transparent atlas pixels match."""
|
|
assets = {
|
|
f"empty{count}.tgs": gzip.compress(
|
|
encoded(
|
|
{
|
|
"v": "5.5.2",
|
|
"w": 512,
|
|
"h": 512,
|
|
"fr": 20,
|
|
"ip": 0,
|
|
"op": count,
|
|
"layers": [],
|
|
}
|
|
)
|
|
)
|
|
for count in (9, 10)
|
|
}
|
|
with api_server(routes_for(assets)) as origin:
|
|
result = run_cli(tmp_path, origin)
|
|
assert result.returncode == 0, result.stderr
|
|
catalog = Catalog.model_validate_json(
|
|
(tmp_path / "cache" / "catalog.json").read_bytes()
|
|
)
|
|
stickers = catalog.packs[0].stickers
|
|
assert [s.frames for s in stickers] == [9, 10]
|
|
assert stickers[0].id != stickers[1].id
|
|
pixels: list[bytes] = []
|
|
for sticker in stickers:
|
|
with Image.open(tmp_path / "cache" / "assets" / (sticker.id + ".png")) as image:
|
|
assert image.size == (1024, 256)
|
|
assert image.info["wowmine_frames"] == str(sticker.frames)
|
|
pixels.append(image.tobytes())
|
|
assert pixels[0] == pixels[1]
|
|
|
|
|
|
def test_catalog_rejects_conflicting_frames_for_shared_asset_id() -> None:
|
|
"""Reject an asset ID associated with incompatible animation timing."""
|
|
with pytest.raises(ImportFailureError, match="conflicting frame counts"):
|
|
_ = Catalog.model_validate_json(
|
|
encoded(
|
|
{
|
|
"version": 1,
|
|
"packs": [
|
|
{
|
|
"id": f"Pack{count}",
|
|
"title": "Title",
|
|
"stickers": [
|
|
{"id": "a" * 64, "emoji": "", "frames": count},
|
|
],
|
|
}
|
|
for count in (9, 10)
|
|
],
|
|
}
|
|
)
|
|
)
|