release: Евномия, новая версия, линейка юристов
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
||||
|
||||
import pilot_pdf # noqa: E402
|
||||
import pytest # noqa: E402
|
||||
from pypdf import PdfReader # noqa: E402
|
||||
|
||||
|
||||
def _text(pdf: Path) -> str:
|
||||
return "\n".join(p.extract_text() for p in PdfReader(str(pdf)).pages)
|
||||
|
||||
|
||||
def test_render_keeps_cyrillic(tmp_path):
|
||||
md = tmp_path / "a.md"
|
||||
md.write_text("Первая строка кириллицей\nВторая строка кириллицей\n", encoding="utf-8")
|
||||
pdf = tmp_path / "a.pdf"
|
||||
pilot_pdf.render(md, pdf)
|
||||
text = _text(pdf)
|
||||
assert "Первая строка кириллицей" in text
|
||||
assert "Вторая строка кириллицей" in text
|
||||
|
||||
|
||||
def test_main_copies_case_and_renders_intake(tmp_path):
|
||||
src = tmp_path / "src"
|
||||
(src / "00_intake").mkdir(parents=True)
|
||||
(src / "_case.md").write_text("# Дело\n", encoding="utf-8")
|
||||
(src / "00_intake" / "01-doc.md").write_text("Текст документа\n", encoding="utf-8")
|
||||
dst = tmp_path / "новое дело" / "pilot"
|
||||
assert pilot_pdf.main([str(src), str(dst)]) == 0
|
||||
assert (dst / "_case.md").read_text(encoding="utf-8") == "# Дело\n"
|
||||
assert sorted(p.name for p in (dst / "00_intake").iterdir()) == ["01-doc.pdf"]
|
||||
assert "Текст документа" in _text(dst / "00_intake" / "01-doc.pdf")
|
||||
assert pilot_pdf.main([str(src), str(dst)]) == 1 # новое дело уже есть
|
||||
|
||||
|
||||
def test_no_font_exits_2(tmp_path, monkeypatch):
|
||||
monkeypatch.setattr(pilot_pdf, "FONTS", [tmp_path / "нет.ttf"])
|
||||
with pytest.raises(SystemExit) as e:
|
||||
pilot_pdf.render(tmp_path / "a.md", tmp_path / "a.pdf")
|
||||
assert e.value.code == 2
|
||||
|
||||
|
||||
def test_render_paginates_and_wraps(tmp_path):
|
||||
md = tmp_path / "long.md"
|
||||
lines = [f"Строка {n}" for n in range(1, 121)]
|
||||
md.write_text("\n".join(lines) + "\n\n" + "слово " * 200 + "конец\n", encoding="utf-8")
|
||||
pdf = tmp_path / "long.pdf"
|
||||
pilot_pdf.render(md, pdf)
|
||||
assert len(PdfReader(str(pdf)).pages) > 2
|
||||
text = _text(pdf)
|
||||
assert "Строка 1\n" in text and "Строка 120" in text and text.rstrip().endswith("конец")
|
||||
Reference in New Issue
Block a user