64 lines
1.6 KiB
Python
64 lines
1.6 KiB
Python
"""Shared pytest fixtures."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
from collections.abc import Iterator
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from genshin_tcg.config import Settings
|
|
from genshin_tcg.data.catalog import Catalog
|
|
from genshin_tcg.models import parse_catalog
|
|
|
|
FIXTURES_DIR = Path(__file__).parent / "fixtures"
|
|
|
|
|
|
class FakeConverter:
|
|
"""A stub :class:`~genshin_tcg.rendering.converters.HtmlConverter`."""
|
|
|
|
def __init__(self) -> None:
|
|
self.calls: list[tuple[Path, Path]] = []
|
|
|
|
def convert(self, html_path: Path, image_path: Path) -> None:
|
|
self.calls.append((html_path, image_path))
|
|
image_path.parent.mkdir(parents=True, exist_ok=True)
|
|
image_path.write_bytes(b"fake-png")
|
|
|
|
def close(self) -> None: # pragma: no cover - trivial
|
|
pass
|
|
|
|
def __enter__(self) -> FakeConverter:
|
|
return self
|
|
|
|
def __exit__(self, *exc: object) -> None: # pragma: no cover - trivial
|
|
return None
|
|
|
|
|
|
@pytest.fixture
|
|
def fake_converter() -> FakeConverter:
|
|
return FakeConverter()
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_payload() -> list[dict[str, object]]:
|
|
raw = (FIXTURES_DIR / "sample_fr.json").read_text(encoding="utf-8")
|
|
payload = json.loads(raw)
|
|
assert isinstance(payload, list)
|
|
return payload
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_catalog(sample_payload: list[dict[str, object]]) -> Catalog:
|
|
return Catalog(cards=tuple(parse_catalog(sample_payload)))
|
|
|
|
|
|
@pytest.fixture
|
|
def settings(tmp_path: Path) -> Iterator[Settings]:
|
|
yield Settings(
|
|
language="fr",
|
|
assets_dir=tmp_path / "assets",
|
|
build_dir=tmp_path / "build",
|
|
)
|