diff options
| author | Michael Williamson <mike@zwobble.org> | 2025-09-09 09:42:05 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2025-09-09 09:42:05 +0100 |
| commit | b3ce26c39f64e580e1e42c28e829421084455043 (patch) | |
| tree | f0e8fe8b48ff0bc40edbf2973c8a3354f976d4aa /tests/docx | |
| parent | 0c872345021d25a0895ccdaf32a3ad076406f3c4 (diff) | |
Test reading of table rows when non-rows are present
Diffstat (limited to 'tests/docx')
| -rw-r--r-- | tests/docx/body_xml_tests.py | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/tests/docx/body_xml_tests.py b/tests/docx/body_xml_tests.py index fc677be..0c86c6e 100644 --- a/tests/docx/body_xml_tests.py +++ b/tests/docx/body_xml_tests.py @@ -1118,8 +1118,49 @@ class TableTests(object): def test_warning_if_non_row_in_table(self): - element = xml_element("w:tbl", {}, [xml_element("w:p")]) + # Include normal rows to ensure they're still read correctly. + element = xml_element("w:tbl", {}, [ + xml_element("w:tr", {}, [ + xml_element("w:tc", {}, [ + xml_element("w:p", {}, [ + _run_element_with_text("Row 1"), + ]), + ]), + ]), + xml_element("w:p"), + xml_element("w:tr", {}, [ + xml_element("w:tc", {}, [ + xml_element("w:p", {}, [ + _run_element_with_text("Row 2"), + ]), + ]), + ]), + ]) + result = _read_document_xml_element(element) + + expected_value = documents.table([ + documents.table_row([ + documents.table_cell([ + documents.paragraph([ + documents.run([ + documents.text("Row 1"), + ]), + ]), + ]), + ]), + documents.paragraph([]), + documents.table_row([ + documents.table_cell([ + documents.paragraph([ + documents.run([ + documents.text("Row 2"), + ]), + ]), + ]), + ]), + ]) + assert_equal(expected_value, result.value) expected_warning = results.warning("unexpected non-row element in table, cell merging may be incorrect") assert_equal([expected_warning], result.messages) |
