diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-05-20 20:07:16 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-05-20 20:07:16 +0100 |
| commit | 3c28baca5a85d95744d7c325a07e2837dea51ef2 (patch) | |
| tree | aaa97b0a0f33a21265259d3205408dc53ca9fb9a /tests | |
| parent | 764885cdd67087cbb93cf73641a2357ecc562606 (diff) | |
Support merged paragraphs when revisions are tracked
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/docx/body_xml_tests.py | 55 |
1 files changed, 54 insertions, 1 deletions
diff --git a/tests/docx/body_xml_tests.py b/tests/docx/body_xml_tests.py index 1b02b97..32f6642 100644 --- a/tests/docx/body_xml_tests.py +++ b/tests/docx/body_xml_tests.py @@ -4,7 +4,7 @@ import io import sys import funk -from precisely import assert_that, is_sequence +from precisely import all_of, assert_that, has_attrs, instance_of, is_sequence import pytest from mammoth import documents, results @@ -144,6 +144,59 @@ class ParagraphTests(object): assert_equal(None, paragraph.numbering) + def test_content_of_deleted_paragraph_is_prepended_to_next_paragraph(self): + styles = Styles.create( + paragraph_styles={ + "Heading1": Style(style_id="Heading1", name="Heading 1"), + "Heading2": Style(style_id="Heading2", name="Heading 2"), + }, + ) + body_xml = [ + xml_element("w:p", {}, [ + xml_element("w:pPr", {}, [ + xml_element("w:pStyle", {"w:val": "Heading1"}, []), + xml_element("w:rPr", {}, [ + xml_element("w:del"), + ]), + ]), + _run_element_with_text("One"), + ]), + xml_element("w:p", {}, [ + xml_element("w:pPr", {}, [ + xml_element("w:pStyle", {"w:val": "Heading2"}, []), + ]), + _run_element_with_text("Two"), + ]), + # Include a second paragraph that isn't deleted to ensure we only add + # the deleted paragraph contents once. + xml_element("w:p", {}, [ + _run_element_with_text("Three"), + ]) + ] + + result = _read_and_get_document_xml_elements(body_xml, styles=styles); + + assert_that(result, is_sequence( + all_of( + instance_of(documents.Paragraph), + has_attrs( + style_id="Heading2", + children=is_sequence( + documents.run([documents.text("One")]), + documents.run([documents.text("Two")]) + ), + ), + ), + all_of( + instance_of(documents.Paragraph), + has_attrs( + children=is_sequence( + documents.run([documents.text("Three")]), + ) + ), + ), + )) + def _paragraph_with_numbering_properties(self, children): numbering_properties_xml = xml_element("w:numPr", {}, children) properties_xml = xml_element("w:pPr", {}, [numbering_properties_xml]) |
