"""Integration test — full md → docx conversion on pluxee-todo.md fixture.""" import subprocess import sys import zipfile import xml.etree.ElementTree as ET from pathlib import Path REPO = Path(__file__).parent.parent FIXTURE = REPO / "pluxee-todo.md" W_NS = "http://schemas.openxmlformats.org/wordprocessingml/2006/main" def test_convert_pluxee_todo_creates_valid_docx(tmp_path): out = tmp_path / "pluxee.docx" r = subprocess.run( [sys.executable, "md2doc.py", str(FIXTURE), "-o", str(out)], cwd=REPO, capture_output=True, text=True ) assert r.returncode == 0, f"Conversion failed: {r.stderr}" assert out.exists() assert out.stat().st_size > 0 def test_converted_docx_has_headings_and_paragraphs(tmp_path): out = tmp_path / "pluxee.docx" subprocess.run( [sys.executable, "md2doc.py", str(FIXTURE), "-o", str(out), "-q"], cwd=REPO, capture_output=True, text=True ) with zipfile.ZipFile(out) as z: root = ET.fromstring(z.read("word/document.xml")) headings = list(root.iter(f"{{{W_NS}}}pStyle")) heading_vals = [h.get(f"{{{W_NS}}}val") for h in headings] assert any(v and v.startswith("Heading") for v in heading_vals), \ f"expected at least one Heading style, got {heading_vals}" def test_image_in_markdown_warns_to_stderr(tmp_path): md_with_image = tmp_path / "img.md" md_with_image.write_text("# Test\n\n![alt text](https://example.com/x.png)\n") out = tmp_path / "img.docx" r = subprocess.run( [sys.executable, "md2doc.py", str(md_with_image), "-o", str(out)], cwd=REPO, capture_output=True, text=True ) assert r.returncode == 0 # warning, not error assert "image" in r.stderr.lower() or "skip" in r.stderr.lower() def test_directory_mode_converts_all_md(tmp_path): (tmp_path / "a.md").write_text("# A\n") (tmp_path / "b.md").write_text("# B\n") out_dir = tmp_path / "out" r = subprocess.run( [sys.executable, "md2doc.py", str(tmp_path), "-o", str(out_dir)], cwd=REPO, capture_output=True, text=True ) assert r.returncode == 0 assert (out_dir / "a.docx").exists() assert (out_dir / "b.docx").exists()