aboutsummaryrefslogtreecommitdiff
path: root/tests/docx
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-02-04 08:42:19 +0000
committerMichael Williamson <mike@zwobble.org>2016-02-04 13:34:29 +0000
commit6e449db1f143ac198e820610a40765071163d87a (patch)
tree29195292abb67fc33ae389dda630865f34aacb4c /tests/docx
parent2fcc877a3513b79b9217a7575136e7711a2a3875 (diff)
Handle missing run styles in the source document
Diffstat (limited to 'tests/docx')
-rw-r--r--tests/docx/body_xml_tests.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/tests/docx/body_xml_tests.py b/tests/docx/body_xml_tests.py
index a3a7802..2d6644c 100644
--- a/tests/docx/body_xml_tests.py
+++ b/tests/docx/body_xml_tests.py
@@ -116,22 +116,29 @@ class ReadXmlElementTests(object):
assert_equal(None, _read_and_get_document_xml_element(element).style_id)
@istest
- def run_has_style_id_read_from_run_properties_if_present(self):
+ def run_has_style_id_and_name_read_from_run_properties_if_present(self):
style_xml = xml_element("w:rStyle", {"w:val": "Heading1Char"})
styles = Styles({}, {"Heading1Char": Style(style_id="Heading1Char", name="Heading 1 Char")})
run = self._read_run_with_properties([style_xml], styles=styles)
assert_equal("Heading1Char", run.style_id)
+ assert_equal("Heading 1 Char", run.style_name)
@istest
- def run_has_style_name_read_from_run_properties_and_styles(self):
+ def warning_is_emitted_when_run_style_cannot_be_found(self):
style_xml = xml_element("w:rStyle", {"w:val": "Heading1Char"})
+ properties_xml = xml_element("w:rPr", {}, [style_xml])
+ run_xml = xml_element("w:r", {}, [properties_xml])
- styles = Styles({}, {"Heading1Char": Style(style_id="Heading1Char", name="Heading 1 Char")})
+ styles = Styles({}, {})
+
+ result = _read_document_xml_element(run_xml, styles=styles)
+ run = result.value
+ assert_equal("Heading1Char", run.style_id)
+ assert_equal(None, run.style_name)
+ assert_equal([results.warning("Run style with ID Heading1Char was referenced but not defined in the document")], result.messages)
- run = self._read_run_with_properties([style_xml], styles=styles)
- assert_equal("Heading 1 Char", run.style_name)
@istest
def run_is_not_bold_if_bold_element_is_not_present(self):