71 lines
2.5 KiB
Python
71 lines
2.5 KiB
Python
"""Tests for asset discovery and URL resolution."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
from genshin_tcg.constants import AssetPaths, CardType, CostType, Element, WeaponType
|
|
from genshin_tcg.data.assets import (
|
|
illustration_key,
|
|
iter_required_keys,
|
|
skill_keys,
|
|
static_icon_keys,
|
|
)
|
|
from genshin_tcg.data.catalog import Catalog
|
|
from genshin_tcg.models import CharacterCard
|
|
from genshin_tcg.rendering.context import AssetUrlResolver
|
|
|
|
|
|
def test_static_icons_cover_domain_vocabulary() -> None:
|
|
keys = set(static_icon_keys())
|
|
assert AssetPaths.HP_ICON in keys
|
|
assert AssetPaths.ENERGY_CARD_ICON in keys
|
|
assert AssetPaths.cost_die(CostType.VOID) in keys
|
|
assert AssetPaths.element(Element.PYRO) in keys
|
|
assert AssetPaths.weapon(WeaponType.BOW) in keys
|
|
|
|
|
|
def test_static_icons_exclude_character_type_icon() -> None:
|
|
# No ``types/character.png`` exists upstream.
|
|
assert AssetPaths.card_type(CardType.CHARACTER) not in static_icon_keys()
|
|
|
|
|
|
def test_required_keys_include_illustration_and_skills(sample_catalog: Catalog) -> None:
|
|
keys = set(iter_required_keys(sample_catalog.cards))
|
|
assert "tcg/test_pyro.png" in keys
|
|
assert "tcg/skills/test_pyro/skill_1.png" in keys
|
|
assert "tcg/skills/test_pyro/skill_3.png" in keys
|
|
assert "tcg/skills/test_pyro/skill_4.png" not in keys
|
|
assert "tcg/test_food.png" in keys
|
|
|
|
|
|
def test_skill_keys_follow_skill_order(sample_catalog: Catalog) -> None:
|
|
character = next(iter(sample_catalog.characters))
|
|
assert isinstance(character, CharacterCard)
|
|
assert skill_keys(character) == [
|
|
"tcg/skills/test_pyro/skill_1.png",
|
|
"tcg/skills/test_pyro/skill_2.png",
|
|
"tcg/skills/test_pyro/skill_3.png",
|
|
]
|
|
|
|
|
|
def test_illustration_key_uses_card_id(sample_catalog: Catalog) -> None:
|
|
assert illustration_key(sample_catalog.get("test_food")) == "tcg/test_food.png"
|
|
|
|
|
|
def test_asset_url_resolver_builds_relative_urls(tmp_path: Path) -> None:
|
|
assets = tmp_path / "assets"
|
|
html_dir = tmp_path / "build" / "html"
|
|
resolver = AssetUrlResolver(assets, html_dir)
|
|
url = resolver.url("tcg/test_pyro.png")
|
|
assert url == "../../assets/tcg/test_pyro.png"
|
|
|
|
|
|
def test_asset_url_resolver_exists(tmp_path: Path) -> None:
|
|
assets = tmp_path / "assets"
|
|
(assets / "tcg").mkdir(parents=True)
|
|
(assets / "tcg" / "x.png").write_bytes(b"x")
|
|
resolver = AssetUrlResolver(assets, tmp_path / "build" / "html")
|
|
assert resolver.exists("tcg/x.png")
|
|
assert not resolver.exists("tcg/missing.png")
|