1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# tests/test_taxonomy.py
import pytest
from pathlib import Path
from core.taxonomy import TaxonomyModel, load_taxonomy, save_taxonomy
from ui.taxonomy_view import TaxonomyView
def _write_pair(tmp_path, it_lines, en_lines):
it_file = tmp_path / "tags-it.txt"
en_file = tmp_path / "tags-en.txt"
it_file.write_text("\n".join(it_lines) + "\n")
en_file.write_text("\n".join(en_lines) + "\n")
return it_file, en_file
def test_load_taxonomy_basic(tmp_path):
it_f, en_f = _write_pair(tmp_path, ["linux", "vita"], ["linux", "life"])
model = load_taxonomy(it_f, en_f)
assert model.it_to_en["linux"] == "linux"
assert model.it_to_en["vita"] == "life"
def test_load_taxonomy_orphan_it(tmp_path):
it_f, en_f = _write_pair(tmp_path, ["linux", "vita", "extra"], ["linux", "life"])
model = load_taxonomy(it_f, en_f)
assert "extra" in model.orphans_it
def test_load_taxonomy_orphan_en(tmp_path):
it_f, en_f = _write_pair(tmp_path, ["linux"], ["linux", "extra-en"])
model = load_taxonomy(it_f, en_f)
assert "extra-en" in model.orphans_en
def test_save_taxonomy_round_trips(tmp_path):
it_f, en_f = _write_pair(tmp_path, ["linux"], ["linux"])
model = load_taxonomy(it_f, en_f)
model.it_to_en["vita"] = "life"
save_taxonomy(model, it_f, en_f)
model2 = load_taxonomy(it_f, en_f)
assert model2.it_to_en["vita"] == "life"
def test_save_taxonomy_sorted(tmp_path):
it_f, en_f = _write_pair(tmp_path, [], [])
from core.taxonomy import TaxonomyModel
model = TaxonomyModel(it_to_en={"zzz": "zzz", "aaa": "aaa"}, orphans_it=[], orphans_en=[])
save_taxonomy(model, it_f, en_f)
lines = it_f.read_text().splitlines()
assert lines == sorted(lines)
def test_detect_renames_en_change(qtbot):
old = {"linux": "linux", "vita": "life"}
new = {"linux": "linux", "vita": "living"}
it_r, en_r = TaxonomyView._detect_renames(old, new)
assert it_r == {}
assert en_r == {"life": "living"}
def test_detect_renames_it_change(qtbot):
old = {"linux": "linux", "vita": "life"}
new = {"linux": "linux", "living": "life"}
it_r, en_r = TaxonomyView._detect_renames(old, new)
assert it_r == {"vita": "living"}
assert en_r == {}
def test_detect_renames_no_change(qtbot):
old = {"linux": "linux"}
new = {"linux": "linux"}
it_r, en_r = TaxonomyView._detect_renames(old, new)
assert it_r == {}
assert en_r == {}
def test_detect_renames_addition_not_rename(qtbot):
old = {"linux": "linux"}
new = {"linux": "linux", "vita": "life"}
it_r, en_r = TaxonomyView._detect_renames(old, new)
assert it_r == {}
assert en_r == {}
|