Skip to content

Commit aa583d3

Browse files
committed
Test reading of table cells when non-cells are present
1 parent b3ce26c commit aa583d3

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

mammoth/docx/body_xml.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ def calculate_row_spans(rows):
410410
for cell in row.children
411411
)
412412
if unexpected_non_cells:
413+
remove_unmerged_table_cells(rows)
413414
return _elements_result_with_messages(rows, [results.warning(
414415
"unexpected non-cell element in table row, cell merging may be incorrect"
415416
)])

tests/docx/body_xml_tests.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1166,8 +1166,45 @@ def test_warning_if_non_row_in_table(self):
11661166

11671167

11681168
def test_warning_if_non_cell_in_table_row(self):
1169-
element = xml_element("w:tbl", {}, [w_tr(xml_element("w:p"))])
1169+
# Include normal cells to ensure they're still read correctly.
1170+
element = xml_element("w:tbl", {}, [
1171+
w_tr(
1172+
xml_element("w:tc", {}, [
1173+
xml_element("w:p", {}, [
1174+
_run_element_with_text("Cell 1"),
1175+
]),
1176+
]),
1177+
xml_element("w:p"),
1178+
xml_element("w:tc", {}, [
1179+
xml_element("w:p", {}, [
1180+
_run_element_with_text("Cell 2"),
1181+
]),
1182+
]),
1183+
),
1184+
])
1185+
11701186
result = _read_document_xml_element(element)
1187+
1188+
expected_value = documents.table([
1189+
documents.table_row([
1190+
documents.table_cell([
1191+
documents.paragraph([
1192+
documents.run([
1193+
documents.text("Cell 1"),
1194+
]),
1195+
]),
1196+
]),
1197+
documents.paragraph([]),
1198+
documents.table_cell([
1199+
documents.paragraph([
1200+
documents.run([
1201+
documents.text("Cell 2"),
1202+
]),
1203+
]),
1204+
]),
1205+
]),
1206+
])
1207+
assert_equal(expected_value, result.value)
11711208
expected_warning = results.warning("unexpected non-cell element in table row, cell merging may be incorrect")
11721209
assert_equal([expected_warning], result.messages)
11731210

0 commit comments

Comments
 (0)