diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-06-15 14:22:26 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-06-15 14:22:26 +0100 |
| commit | 3ea79e23d3211b937c2c75f1390b212b25cc2fcb (patch) | |
| tree | a7201a8d539b38e77276397035d04bcf4ec74f1b /tests/docx | |
| parent | abc07c40f2a80468292b13ddb6714972bb73b7af (diff) | |
Read mc:Fallback when reading mc:AlternateContent
Diffstat (limited to 'tests/docx')
| -rw-r--r-- | tests/docx/document_xml_tests.py | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/tests/docx/document_xml_tests.py b/tests/docx/document_xml_tests.py index eecedf6..22b4c31 100644 --- a/tests/docx/document_xml_tests.py +++ b/tests/docx/document_xml_tests.py @@ -409,13 +409,32 @@ class ReadXmlElementTests(object): documents.run([documents.Text("Hello!")]), read_document_xml_element(element).value ) + + @istest + def alternate_content_is_read_using_fallback(self): + element = xml_element("mc:AlternateContent", {}, [ + xml_element("mc:Choice", {"Requires": "wps"}, [ + _paragraph_with_style_id("first") + ]), + xml_element("mc:Fallback", {}, [ + _paragraph_with_style_id("second") + ]) + ]) + result = _read_and_get_document_xml_element(element) + assert_equal("second", result[0].style_id) + def _read_and_get_document_xml_element(*args, **kwargs): - result = read_document_xml_element(*args, **kwargs) + styles = kwargs.pop("styles", FakeStyles()) + result = read_document_xml_element(*args, styles=styles, **kwargs) assert_equal([], result.messages) return result.value +class FakeStyles(object): + def find_paragraph_style_by_id(self, style_id): + return Style(style_id, style_id) + def _document_element_with_text(text): return xml_element("w:document", {}, [ xml_element("w:body", {}, [_paragraph_element_with_text(text)]) @@ -425,6 +444,10 @@ def _document_element_with_text(text): def _paragraph_element_with_text(text): return xml_element("w:p", {}, [_run_element_with_text(text)]) +def _paragraph_with_style_id(style_id): + style_xml = xml_element("w:pStyle", {"w:val": style_id}) + properties_xml = xml_element("w:pPr", {}, [style_xml]) + return xml_element("w:p", {}, [properties_xml]) def _run_element_with_text(text): return xml_element("w:r", {}, [_text_element(text)]) |
