summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2017-11-03 16:30:11 +0000
committerMichael Williamson <mike@zwobble.org>2017-11-03 16:30:11 +0000
commit1498397f4ede71d81ec79f380d43ec041438a047 (patch)
tree8b9751ed744ca75cf6aa140fe227c94431129e1e /tests
parentcd95535a1bb0f486d4a102cfc622ae5228c3071d (diff)
Read table style applied to tables
Diffstat (limited to 'tests')
-rw-r--r--tests/docx/body_xml_tests.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/docx/body_xml_tests.py b/tests/docx/body_xml_tests.py
index ad509c4..d1dd071 100644
--- a/tests/docx/body_xml_tests.py
+++ b/tests/docx/body_xml_tests.py
@@ -493,6 +493,39 @@ class TableTests(object):
])
])
assert_equal(expected_result, table)
+
+ @istest
+ def table_has_no_style_if_it_has_no_properties(self):
+ element = xml_element("w:tbl")
+ assert_equal(None, _read_and_get_document_xml_element(element).style_id)
+
+ @istest
+ def table_has_style_id_and_name_read_from_paragraph_properties_if_present(self):
+ style_xml = xml_element("w:tblStyle", {"w:val": "TableNormal"})
+ properties_xml = xml_element("w:tblPr", {}, [style_xml])
+ table_xml = xml_element("w:tbl", {}, [properties_xml])
+
+ styles = Styles(
+ paragraph_styles={},
+ character_styles={},
+ table_styles={"TableNormal": Style(style_id="TableNormal", name="Normal Table")},
+ )
+
+ paragraph = _read_and_get_document_xml_element(table_xml, styles=styles)
+ assert_equal("TableNormal", paragraph.style_id)
+ assert_equal("Normal Table", paragraph.style_name)
+
+ @istest
+ def warning_is_emitted_when_table_style_cannot_be_found(self):
+ style_xml = xml_element("w:tblStyle", {"w:val": "TableNormal"})
+ properties_xml = xml_element("w:tblPr", {}, [style_xml])
+ table_xml = xml_element("w:tbl", {}, [properties_xml])
+
+ result = _read_document_xml_element(table_xml, styles=Styles.EMPTY)
+ table = result.value
+ assert_equal("TableNormal", table.style_id)
+ assert_equal(None, table.style_name)
+ assert_equal([results.warning("Table style with ID TableNormal was referenced but not defined in the document")], result.messages)
@istest
def tbl_header_marks_table_row_as_header(self):
@@ -1102,6 +1135,9 @@ class FakeStyles(object):
def find_character_style_by_id(self, style_id):
return None
+
+ def find_table_style_by_id(self, style_id):
+ return None
def _document_element_with_text(text):
return xml_element("w:document", {}, [