glossary.py: двуязычный глоссарий из параллельных изданий цикла

This commit is contained in:
chesirecatt
2026-08-21 18:41:45 +03:00
parent 14c7fad763
commit 43d6cfc456
4 changed files with 271 additions and 4 deletions
+19 -1
View File
@@ -57,6 +57,23 @@ def test_pack(tmp: Path):
assert "Текст второй главы" not in ch1, "главы не должны склеиваться"
def test_cover_used_in_text_is_not_duplicated(tmp: Path):
"""Обложка, встречающаяся и в тексте, не должна попадать в архив дважды."""
src = tmp / "book.html"
src.write_text("<h1>Глава</h1>\n"
'<p class="figure"><img src="images/cover.jpg"/></p>\n'
"<p>Текст главы.</p>", encoding="utf-8")
(tmp / "images").mkdir()
(tmp / "images" / "cover.jpg").write_bytes(b"\xff\xd8\xff")
out = tmp / "book.epub"
pack_epub.build(src, out, {"title": "t", "author": "a", "lang": "ru",
"cover": "cover.jpg", "id": "i"})
names = zipfile.ZipFile(out).namelist()
assert names.count("OEBPS/images/cover.jpg") == 1, names
opf = zipfile.ZipFile(out).read("OEBPS/content.opf").decode()
assert opf.count('href="images/cover.jpg"') == 1, opf
def test_no_content(tmp: Path):
src = tmp / "empty.html"
src.write_text("<html><body>\n</body></html>", encoding="utf-8")
@@ -69,7 +86,8 @@ def test_no_content(tmp: Path):
if __name__ == "__main__":
for case in (test_pack, test_no_content):
for case in (test_pack, test_cover_used_in_text_is_not_duplicated,
test_no_content):
with tempfile.TemporaryDirectory() as d:
case(Path(d))
print("OK")