diff options
| author | Danilo M. <danix@danix.xyz> | 2026-05-03 09:55:27 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-05-03 09:55:27 +0200 |
| commit | cf1c58081d68fe7f8833bc32589b4feb7210165f (patch) | |
| tree | 0dbeb997296640395cfe6e484812b98bfd674e76 /tests/test_taxonomy.py | |
| parent | b4d3b526e232804e06b84d93628244cecd035df5 (diff) | |
| download | publisher-cf1c58081d68fe7f8833bc32589b4feb7210165f.tar.gz publisher-cf1c58081d68fe7f8833bc32589b4feb7210165f.zip | |
feat: taxonomy load/save with IT/EN pair alignment
Diffstat (limited to 'tests/test_taxonomy.py')
| -rw-r--r-- | tests/test_taxonomy.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/test_taxonomy.py b/tests/test_taxonomy.py new file mode 100644 index 0000000..a10531b --- /dev/null +++ b/tests/test_taxonomy.py @@ -0,0 +1,43 @@ +# tests/test_taxonomy.py +import pytest +from pathlib import Path +from core.taxonomy import TaxonomyModel, load_taxonomy, save_taxonomy + +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) |
