53 lines
2.3 KiB
Python
53 lines
2.3 KiB
Python
|
|
import subprocess
|
|||
|
|
import sys
|
|||
|
|
from pathlib import Path
|
|||
|
|
|
|||
|
|
def test_real_cli_call_creates_non_empty_doc():
|
|||
|
|
import tempfile
|
|||
|
|
|
|||
|
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
|||
|
|
tmp_path = Path(tmp_dir)
|
|||
|
|
input_dir = tmp_path / "inputs"
|
|||
|
|
output_dir = tmp_path / "outputs"
|
|||
|
|
input_dir.mkdir()
|
|||
|
|
output_dir.mkdir()
|
|||
|
|
|
|||
|
|
# Создаём папку example_doc
|
|||
|
|
doc_dir = input_dir / "example_doc"
|
|||
|
|
doc_dir.mkdir()
|
|||
|
|
(doc_dir / "document.md").write_text("# ВВЕДЕНИЕ\n\nТекст введения.", encoding="utf-8")
|
|||
|
|
(doc_dir / "images").mkdir()
|
|||
|
|
|
|||
|
|
# Запускаем CLI через subprocess
|
|||
|
|
result = subprocess.run([
|
|||
|
|
sys.executable, "-m", "src",
|
|||
|
|
"--input", str(input_dir),
|
|||
|
|
"--output", str(output_dir),
|
|||
|
|
"--style", "resources/style_config.yaml"
|
|||
|
|
], capture_output=True, text=True, cwd=Path(__file__).parent.parent) # запускаем из корня проекта
|
|||
|
|
|
|||
|
|
print("STDOUT:", result.stdout)
|
|||
|
|
print("STDERR:", result.stderr)
|
|||
|
|
print("Return code:", result.returncode)
|
|||
|
|
|
|||
|
|
assert result.returncode == 0, f"CLI завершился с ошибкой: {result.stderr}"
|
|||
|
|
|
|||
|
|
# Проверяем, что файл создан
|
|||
|
|
output_path = output_dir / "example_doc.docx"
|
|||
|
|
assert output_path.exists(), "Файл .docx не создан через CLI"
|
|||
|
|
|
|||
|
|
# Открываем и проверяем
|
|||
|
|
from docx import Document
|
|||
|
|
doc = Document(output_path)
|
|||
|
|
|
|||
|
|
print(f"Real CLI: Количество параграфов: {len(doc.paragraphs)}")
|
|||
|
|
for i, p in enumerate(doc.paragraphs):
|
|||
|
|
print(f"Real CLI: Параграф {i}: '{p.text}' (len={len(p.text)})")
|
|||
|
|
|
|||
|
|
# Проверяем, что есть хотя бы 1 непустой параграф
|
|||
|
|
non_empty_paragraphs = [p for p in doc.paragraphs if p.text.strip() != ""]
|
|||
|
|
assert len(non_empty_paragraphs) > 0, f"Real CLI: Все параграфы пустые: {[p.text for p in doc.paragraphs]}"
|
|||
|
|
|
|||
|
|
# Проверяем, что есть заголовок
|
|||
|
|
found_intro = any("ВВЕДЕНИЕ" in p.text for p in doc.paragraphs)
|
|||
|
|
assert found_intro, f"Real CLI: Заголовок 'ВВЕДЕНИЕ' не найден"
|