summaryrefslogtreecommitdiff
path: root/tests/docx
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2025-09-09 09:43:54 +0100
committerMichael Williamson <mike@zwobble.org>2025-09-09 09:43:54 +0100
commitaa583d3eda56cb157b2eaff7d607d3d41b24c3f5 (patch)
tree099c287cce1232188f9e7dc09be0061249f5f220 /tests/docx
parentb3ce26c39f64e580e1e42c28e829421084455043 (diff)
Test reading of table cells when non-cells are present
Diffstat (limited to 'tests/docx')
-rw-r--r--tests/docx/body_xml_tests.py39
1 files changed, 38 insertions, 1 deletions
diff --git a/tests/docx/body_xml_tests.py b/tests/docx/body_xml_tests.py
index 0c86c6e..e9decc4 100644
--- a/tests/docx/body_xml_tests.py
+++ b/tests/docx/body_xml_tests.py
@@ -1166,8 +1166,45 @@ class TableTests(object):
def test_warning_if_non_cell_in_table_row(self):
- element = xml_element("w:tbl", {}, [w_tr(xml_element("w:p"))])
+ # Include normal cells to ensure they're still read correctly.
+ element = xml_element("w:tbl", {}, [
+ w_tr(
+ xml_element("w:tc", {}, [
+ xml_element("w:p", {}, [
+ _run_element_with_text("Cell 1"),
+ ]),
+ ]),
+ xml_element("w:p"),
+ xml_element("w:tc", {}, [
+ xml_element("w:p", {}, [
+ _run_element_with_text("Cell 2"),
+ ]),
+ ]),
+ ),
+ ])
+
result = _read_document_xml_element(element)
+
+ expected_value = documents.table([
+ documents.table_row([
+ documents.table_cell([
+ documents.paragraph([
+ documents.run([
+ documents.text("Cell 1"),
+ ]),
+ ]),
+ ]),
+ documents.paragraph([]),
+ documents.table_cell([
+ documents.paragraph([
+ documents.run([
+ documents.text("Cell 2"),
+ ]),
+ ]),
+ ]),
+ ]),
+ ])
+ assert_equal(expected_value, result.value)
expected_warning = results.warning("unexpected non-cell element in table row, cell merging may be incorrect")
assert_equal([expected_warning], result.messages)