Fixed faction image fetching
CI / quality (3.11) (push) Has been cancelled
CI / quality (3.12) (push) Has been cancelled

This commit is contained in:
2026-10-15 18:12:27 +02:00
parent d651455499
commit 3b886acaba
11 changed files with 1301 additions and 6 deletions
+97
View File
@@ -2,8 +2,10 @@
from __future__ import annotations
from collections.abc import Sequence
from pathlib import Path
import pytest
from typer.testing import CliRunner
from genshin_tcg import __version__
@@ -40,3 +42,98 @@ def test_list_prints_catalogue(tmp_path: Path, sample_catalog: Catalog) -> None:
assert result.exit_code == 0
assert "test_pyro" in result.output
assert "Test Pyro" in result.output
class _FakeWiki:
"""A stand-in for :class:`genshin_tcg.data.fandom.FandomSource`."""
def __init__(self, *args: object, **kwargs: object) -> None:
pass
def __enter__(self) -> _FakeWiki:
return self
def __exit__(self, *exc: object) -> None:
return None
def character_regions(self) -> dict[str, str]:
return {"test_pyro": "Mondstadt"}
def enemy_families(self) -> dict[str, str]:
return {}
def region_emblems(self) -> dict[str, str]:
return {}
def file_urls(self, names: Sequence[str]) -> dict[str, str]:
return {}
def download(self, url: str, destination: Path, *, force: bool = False) -> bool:
return False
def test_factions_command_writes_overrides(
tmp_path: Path, sample_catalog: Catalog, monkeypatch: pytest.MonkeyPatch
) -> None:
build_dir = tmp_path / "build"
build_dir.mkdir(parents=True)
save_catalog(sample_catalog, build_dir / "catalog.json")
monkeypatch.setattr("genshin_tcg.pipeline.FandomSource", _FakeWiki)
result = runner.invoke(
app,
["--build-dir", str(build_dir), "--assets-dir", str(tmp_path / "assets"), "factions"],
)
assert result.exit_code == 0
assert "Factions" in result.output
overrides = tmp_path / "assets" / "overrides" / "factions.json"
assert overrides.is_file()
assert "mondstadt" in overrides.read_text(encoding="utf-8")
def test_factions_command_no_icons(
tmp_path: Path, sample_catalog: Catalog, monkeypatch: pytest.MonkeyPatch
) -> None:
build_dir = tmp_path / "build"
build_dir.mkdir(parents=True)
save_catalog(sample_catalog, build_dir / "catalog.json")
monkeypatch.setattr("genshin_tcg.pipeline.FandomSource", _FakeWiki)
result = runner.invoke(
app,
[
"--build-dir",
str(build_dir),
"--assets-dir",
str(tmp_path / "assets"),
"factions",
"--no-icons",
],
)
assert result.exit_code == 0
assert "Icons" not in result.output
def test_factions_command_dry_run(
tmp_path: Path, sample_catalog: Catalog, monkeypatch: pytest.MonkeyPatch
) -> None:
build_dir = tmp_path / "build"
build_dir.mkdir(parents=True)
save_catalog(sample_catalog, build_dir / "catalog.json")
monkeypatch.setattr("genshin_tcg.pipeline.FandomSource", _FakeWiki)
result = runner.invoke(
app,
[
"--build-dir",
str(build_dir),
"--assets-dir",
str(tmp_path / "assets"),
"factions",
"--dry-run",
],
)
assert result.exit_code == 0
assert "test_pyro: mondstadt" in result.output
assert not (tmp_path / "assets" / "overrides" / "factions.json").exists()