import pytest from pathlib import Path from docx import Document from src.core.converter import process_document @pytest.fixture def create_gost_example(): # Создаём inputs/gost_example/ doc_dir = Path("tests/fixtures/inputs/gost_example") doc_dir.mkdir(parents=True, exist_ok=True) # Создаём document.md md_content = """ # ВВЕДЕНИЕ Текст введения. ## 1.1 Актуальность темы Текст актуальности. | Показатель | 2022 | |------------|------| | Выручка | 1000 | ![Рис. 1 — Диаграмма](images/chart.png) """ (doc_dir / "document.md").write_text(md_content, encoding="utf-8") # Создаём images/ (doc_dir / "images").mkdir(exist_ok=True) # Создаём изображение from PIL import Image img_path = doc_dir / "images/chart.png" img = Image.new("RGB", (100, 100), color="blue") img.save(img_path) yield doc_dir.parent # возвращаем Path("tests/fixtures/inputs") # Удаляем после теста import shutil shutil.rmtree(doc_dir.parent, ignore_errors=True) def test_gost_example_document_not_empty(create_gost_example): input_dir = create_gost_example process_document( input_dir=input_dir, output_dir=Path("tests/output"), style_config_path=Path("resources/themes/gost.yaml"), ) output_path = Path("tests/output/gost_example.docx") assert output_path.exists(), "Файл .docx не создан" # Открываем и проверяем, что в документе есть хотя бы 1 параграф doc = Document(output_path) assert len(doc.paragraphs) > 0, "Документ пустой (нет параграфов)" assert len(doc.tables) >= 0, "Документ не содержит таблиц (это нормально)" assert any(p.text.strip() != "" for p in doc.paragraphs), "Все параграфы пустые" # Удаляем после теста output_path.unlink(missing_ok=True)