MIL-011: Menu bar

Review record RC-066 (Go, autonomous mode, not independent).

Task: MIL-011#1
Task: MIL-011#2
Task: MIL-011#3
Task: MIL-011#4
Task: MIL-011#5
Task: MIL-011#6
Task: MIL-011#7
Task: MIL-011#8
This commit is contained in:
2026-10-15 09:06:47 +08:00
parent 5d626dc890
commit ce4aacb4bc
28 changed files with 1450 additions and 35 deletions
@@ -110,3 +110,18 @@ def test_progress_save_then_load_returns_same_cards(tmp_path: Path) -> None:
assert deck is not None
assert deck.cards == CARDS
assert deck.language_pair == PAIR
def test_reset_deletes_the_progress_file(tmp_path: Path) -> None:
path = tmp_path / "words_to_learn.csv"
path.write_text("ms;da\naku;mig\n", encoding="utf-8")
repository = CsvProgressRepository(path)
repository.reset()
assert not path.exists()
assert repository.load() is None
def test_reset_does_nothing_when_the_file_is_absent(tmp_path: Path) -> None:
CsvProgressRepository(tmp_path / "words_to_learn.csv").reset()
@@ -93,3 +93,18 @@ def test_repository_load_raises_format_error_when_no_card(tmp_path: Path) -> Non
path = _write(tmp_path / "w.csv", "ms;da\n")
with pytest.raises(VocabularyFormatError):
CsvVocabularyRepository(path).load()
@pytest.mark.parametrize(
"content",
[b"ms;da\n\xff\xfe;x\n", "ms;da\nkøkken;x\n".encode("latin-1")],
ids=["invalid-utf8", "latin-1"],
)
def test_read_word_list_raises_format_error_when_not_utf8(
tmp_path: Path, content: bytes
) -> None:
path = tmp_path / "w.csv"
path.write_bytes(content)
with pytest.raises(VocabularyFormatError, match=r"w\.csv.*not UTF-8") as info:
read_word_list(path)
assert isinstance(info.value.__cause__, UnicodeDecodeError)
@@ -0,0 +1,36 @@
"""Tests of the name of the words to learn file of a word list."""
from pathlib import Path
import pytest
from flash_card.infrastructure.persistence.progress_file_name import (
progress_file_name,
)
def test_progress_file_name_is_default_for_the_delivered_list() -> None:
assert progress_file_name(Path("data") / "ms-da.csv") == "words_to_learn.csv"
def test_progress_file_name_uses_the_stem_for_another_list() -> None:
assert progress_file_name(Path("x") / "animals.csv") == "words_to_learn_animals.csv"
def test_progress_file_name_keeps_hyphen_and_underscore() -> None:
name = progress_file_name(Path("my_list-2.csv"))
assert name == "words_to_learn_my_list-2.csv"
@pytest.mark.parametrize(
("file_name", "expected"),
[
("my list.csv", "words_to_learn_my_list.csv"),
("a.b;c.csv", "words_to_learn_a_b_c.csv"),
("ord (1).csv", "words_to_learn_ord__1_.csv"),
],
)
def test_progress_file_name_replaces_other_characters(
file_name: str, expected: str
) -> None:
assert progress_file_name(Path(file_name)) == expected