Files
031-flash-card/tests/unit/test_app.py
T
Tirsvad 8d66c43eea MIL-003: Step 2 - New flash cards
Review record RC-025 (Go, autonomous mode, not independent).

Task: MIL-003#1
Task: MIL-003#2
Task: MIL-003#3
Task: MIL-003#4
Task: MIL-003#5
2026-10-14 21:59:29 +08:00

44 lines
1.1 KiB
Python

"""Tests of the entry point.
@file test_app.py
@brief Checks main of flash_card.presentation.app without opening a window.
"""
from pathlib import Path
import pytest
from flash_card.presentation import app
class _FakeRoot:
def __init__(self) -> None:
self.mainloop_calls = 0
def mainloop(self) -> None:
self.mainloop_calls += 1
def test_main_runs_main_loop_and_returns_zero(
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
) -> None:
root = _FakeRoot()
seen: list[Path | None] = []
def fake_create(data_dir: Path | None = None) -> tuple[_FakeRoot, object]:
seen.append(data_dir)
return root, object()
monkeypatch.setattr(app, "create_application", fake_create)
assert app.main(["--data-dir", str(tmp_path)]) == 0
assert root.mainloop_calls == 1
assert seen == [tmp_path]
def test_main_returns_one_when_word_list_is_missing(
tmp_path: Path, caplog: pytest.LogCaptureFixture
) -> None:
assert app.main(["--data-dir", str(tmp_path / "nowhere")]) == 1
assert "word list not found" in caplog.text