First version
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
"""Tests for :mod:`genshin_tcg.config`."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from pydantic import ValidationError
|
||||
|
||||
from genshin_tcg.config import CardSettings, Settings
|
||||
|
||||
|
||||
def test_design_pixels_for_poker_format() -> None:
|
||||
card = CardSettings(width_mm=63, height_mm=88, dpi=300)
|
||||
assert card.design_width_px == 744
|
||||
assert card.design_height_px == 1039
|
||||
assert card.scale_factor == 1.0
|
||||
assert card.output_width_px == 744
|
||||
|
||||
|
||||
def test_scale_factor_tracks_dpi() -> None:
|
||||
card = CardSettings(dpi=600)
|
||||
assert card.scale_factor == 2.0
|
||||
assert card.output_width_px == 1488
|
||||
assert card.output_height_px == 2078
|
||||
|
||||
|
||||
def test_dpi_below_baseline_is_rejected() -> None:
|
||||
with pytest.raises(ValidationError):
|
||||
CardSettings(dpi=150)
|
||||
|
||||
|
||||
def test_derived_paths(tmp_path: Path) -> None:
|
||||
settings = Settings(language="en", assets_dir=tmp_path / "a", build_dir=tmp_path / "b")
|
||||
assert settings.source_json == tmp_path / "a" / "source" / "en.json"
|
||||
assert settings.tags_json == tmp_path / "a" / "source" / "tags_en.json"
|
||||
assert settings.catalog_path == tmp_path / "b" / "catalog.json"
|
||||
assert settings.pdf_path == tmp_path / "b" / "cards-en.pdf"
|
||||
assert settings.factions_override == tmp_path / "a" / "overrides" / "factions.json"
|
||||
|
||||
|
||||
def test_ensure_directories(tmp_path: Path) -> None:
|
||||
settings = Settings(assets_dir=tmp_path / "a", build_dir=tmp_path / "b")
|
||||
settings.ensure_directories()
|
||||
assert settings.source_dir.is_dir()
|
||||
assert settings.tcg_dir.is_dir()
|
||||
assert settings.html_dir.is_dir()
|
||||
assert settings.png_dir.is_dir()
|
||||
|
||||
|
||||
def test_nested_env_override() -> None:
|
||||
import os
|
||||
|
||||
os.environ["GTCG_CARD__DPI"] = "600"
|
||||
os.environ["GTCG_PAGE__CUT_MARKS"] = "false"
|
||||
try:
|
||||
settings = Settings()
|
||||
assert settings.card.dpi == 600
|
||||
assert settings.page.cut_marks is False
|
||||
finally:
|
||||
os.environ.pop("GTCG_CARD__DPI", None)
|
||||
os.environ.pop("GTCG_PAGE__CUT_MARKS", None)
|
||||
Reference in New Issue
Block a user