summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2025-05-28 20:01:21 +0100
committerMichael Williamson <mike@zwobble.org>2025-05-28 20:01:21 +0100
commitdd8b47154b2f9109eb6041302902d85fad6ceb08 (patch)
treec9609ed582a19a1db3b0f50db19624b2fd3f4e60 /tests
parente7041cb3e4188c24ca6efbd383df183518d7840d (diff)
Handle AlternateContent without Fallback in office_xml
Diffstat (limited to 'tests')
-rw-r--r--tests/docx/office_xml_tests.py48
1 files changed, 32 insertions, 16 deletions
diff --git a/tests/docx/office_xml_tests.py b/tests/docx/office_xml_tests.py
index f87fa75..05897db 100644
--- a/tests/docx/office_xml_tests.py
+++ b/tests/docx/office_xml_tests.py
@@ -6,19 +6,35 @@ from mammoth.docx import xmlparser as xml, office_xml
from ..testing import assert_equal
-def test_alternate_content_is_replaced_by_contents_of_fallback():
- xml_string = (
- '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
- '<numbering xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">' +
- '<mc:AlternateContent>' +
- '<mc:Choice Requires="w14">' +
- '<choice/>' +
- '</mc:Choice>' +
- '<mc:Fallback>' +
- '<fallback/>' +
- '</mc:Fallback>' +
- '</mc:AlternateContent>' +
- '</numbering>')
-
- result = office_xml.read(io.StringIO(xml_string))
- assert_equal([xml.element("fallback")], result.children)
+class AlternateContentTests(object):
+ def test_when_fallback_is_present_then_fallback_is_read(self):
+ xml_string = (
+ '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
+ '<numbering xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">' +
+ '<mc:AlternateContent>' +
+ '<mc:Choice Requires="w14">' +
+ '<choice/>' +
+ '</mc:Choice>' +
+ '<mc:Fallback>' +
+ '<fallback/>' +
+ '</mc:Fallback>' +
+ '</mc:AlternateContent>' +
+ '</numbering>')
+
+ result = office_xml.read(io.StringIO(xml_string))
+ assert_equal([xml.element("fallback")], result.children)
+
+
+ def test_when_fallback_is_not_present_then_element_is_ignored(self):
+ xml_string = (
+ '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
+ '<numbering xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">' +
+ '<mc:AlternateContent>' +
+ '<mc:Choice Requires="w14">' +
+ '<choice/>' +
+ '</mc:Choice>' +
+ '</mc:AlternateContent>' +
+ '</numbering>')
+
+ result = office_xml.read(io.StringIO(xml_string))
+ assert_equal([], result.children)