Перевод не возобновляем: --all переводит все главы заново, механизм progress не работает

This commit is contained in:
chesirecatt
2026-08-21 17:36:10 +03:00
parent a21a4d713b
commit 7ed6e500ca
3 changed files with 54 additions and 7 deletions
+28
View File
@@ -105,6 +105,33 @@ def test_code_listings_are_left_alone(tmp: Path):
assert t.verify_output(src, "ru"), "код не должен заваливать приёмку"
def test_junk_translation_falls_back_to_original(tmp: Path):
"""Модель иногда возвращает на длинный абзац огрызок «, v», а число абзацев
при этом сходится — прежние ворота такое пропускали."""
src = tmp / "book.html"
long_en = ("A vector is simply a sequence of elements that you can access by "
"an index, and it is the workhorse of the standard library. ") * 2
src.write_text("\n".join([
"<h1>Chapter</h1>",
"<p>%s</p>" % long_en,
"<p>Second paragraph of the very same chapter, also reasonably long.</p>",
]), encoding="utf-8")
chapters = t.split_chapters(t.parse_blocks(src))
trans = tmp / "translations"
trans.mkdir()
(trans / "chapter_000_translated.json").write_text(json.dumps(
{"number": 0, "paragraphs": ["Глава", ", v",
"Второй абзац той же самой главы, тоже достаточно длинный."]},
ensure_ascii=False), encoding="utf-8")
out = tmp / "out.html"
t.rebuild(src, chapters, tmp, out)
result = out.read_text(encoding="utf-8")
assert ", v" not in result, "огрызок не должен попадать в книгу"
assert "A vector is simply a sequence" in result, "вместо огрызка нужен оригинал"
assert "Второй абзац" in result, "нормальный перевод должен остаться"
def test_workdir_belongs_to_one_book(tmp: Path):
"""Имена chapter_NNN.json у всех книг одинаковы: чужой workdir склеит
перевод одной книги с текстом другой."""
@@ -155,6 +182,7 @@ if __name__ == "__main__":
test_broken_marks_drop_tags()
test_language_detection()
for case in (test_split_and_rebuild, test_code_listings_are_left_alone,
test_junk_translation_falls_back_to_original,
test_workdir_belongs_to_one_book, test_stale_chapters_removed,
test_verify_output_catches_untranslated):
with tempfile.TemporaryDirectory() as d: