56 lines
1.6 KiB
Python
56 lines
1.6 KiB
Python
|
|
"""Generate the word_first/source.docx fixture for T06 regression tests.
|
|||
|
|
|
|||
|
|
Run this script once to (re)generate the fixture:
|
|||
|
|
python tests/regression/fixtures/word_first/generate.py
|
|||
|
|
|
|||
|
|
The generated source.docx is committed as a stable binary fixture.
|
|||
|
|
"""
|
|||
|
|
|
|||
|
|
from __future__ import annotations
|
|||
|
|
|
|||
|
|
from pathlib import Path
|
|||
|
|
|
|||
|
|
from docx import Document
|
|||
|
|
|
|||
|
|
|
|||
|
|
def generate_source_docx(out_path: Path) -> None:
|
|||
|
|
"""Create a representative Word document with headings, body, table, image placeholder, footer."""
|
|||
|
|
doc = Document()
|
|||
|
|
|
|||
|
|
# Heading 1
|
|||
|
|
doc.add_heading("Introduction", level=1)
|
|||
|
|
|
|||
|
|
# Body paragraphs
|
|||
|
|
doc.add_paragraph("This is the first paragraph of the introduction.")
|
|||
|
|
doc.add_paragraph("A second paragraph with some **notable** content.")
|
|||
|
|
|
|||
|
|
# Heading 2
|
|||
|
|
doc.add_heading("Background", level=2)
|
|||
|
|
doc.add_paragraph("Some background text explaining the context.")
|
|||
|
|
|
|||
|
|
# A simple 2×2 table
|
|||
|
|
table = doc.add_table(rows=2, cols=2)
|
|||
|
|
table.cell(0, 0).text = "Header A"
|
|||
|
|
table.cell(0, 1).text = "Header B"
|
|||
|
|
table.cell(1, 0).text = "Value 1"
|
|||
|
|
table.cell(1, 1).text = "Value 2"
|
|||
|
|
|
|||
|
|
# Heading 2 — Conclusion
|
|||
|
|
doc.add_heading("Conclusion", level=2)
|
|||
|
|
doc.add_paragraph("This concludes the document.")
|
|||
|
|
|
|||
|
|
# Footer
|
|||
|
|
section = doc.sections[0]
|
|||
|
|
footer = section.footer
|
|||
|
|
footer_para = footer.paragraphs[0]
|
|||
|
|
footer_para.text = "Page footer — fixture document"
|
|||
|
|
|
|||
|
|
out_path.parent.mkdir(parents=True, exist_ok=True)
|
|||
|
|
doc.save(str(out_path))
|
|||
|
|
print(f"Generated: {out_path}")
|
|||
|
|
|
|||
|
|
|
|||
|
|
if __name__ == "__main__":
|
|||
|
|
here = Path(__file__).parent
|
|||
|
|
generate_source_docx(here / "source.docx")
|