работа с шаблонами
This commit is contained in:
48
tests/test_converter.py
Normal file
48
tests/test_converter.py
Normal file
@@ -0,0 +1,48 @@
|
||||
import pytest
|
||||
from pathlib import Path
|
||||
from docx import Document
|
||||
from src.core.converter import process_document
|
||||
|
||||
@pytest.fixture
|
||||
def create_example_doc():
|
||||
# Создаём inputs/example_doc/
|
||||
doc_dir = Path("tests/fixtures/inputs/example_doc")
|
||||
doc_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# Создаём document.md
|
||||
md_content = "# Заголовок\n\nПараграф."
|
||||
(doc_dir / "document.md").write_text(md_content, encoding="utf-8")
|
||||
|
||||
# Создаём images/
|
||||
(doc_dir / "images").mkdir(exist_ok=True)
|
||||
|
||||
yield doc_dir.parent # возвращаем Path("tests/fixtures/inputs")
|
||||
|
||||
# Удаляем после теста
|
||||
import shutil
|
||||
shutil.rmtree(doc_dir.parent, ignore_errors=True)
|
||||
|
||||
def test_process_document_with_template(create_example_doc):
|
||||
# create_example_doc = Path("tests/fixtures/inputs")
|
||||
input_dir = create_example_doc
|
||||
|
||||
# Создать пустой .dotx файл для теста
|
||||
tpl_path = Path("tests/fixtures/template.dotx")
|
||||
tpl_path.parent.mkdir(exist_ok=True)
|
||||
doc = Document()
|
||||
doc.save(tpl_path)
|
||||
|
||||
# Запустить конвертацию с шаблоном
|
||||
process_document(
|
||||
input_dir=input_dir,
|
||||
output_dir=Path("tests/output"),
|
||||
style_config_path=Path("resources/style_config.yaml"),
|
||||
template_path=tpl_path
|
||||
)
|
||||
|
||||
output_path = Path("tests/output/example_doc.docx")
|
||||
assert output_path.exists()
|
||||
|
||||
# Удаляем файл после теста
|
||||
output_path.unlink(missing_ok=True)
|
||||
tpl_path.unlink(missing_ok=True)
|
||||
Reference in New Issue
Block a user