aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/docx/document_xml_tests.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/docx/document_xml_tests.py b/tests/docx/document_xml_tests.py
index a044154..f869749 100644
--- a/tests/docx/document_xml_tests.py
+++ b/tests/docx/document_xml_tests.py
@@ -1,3 +1,5 @@
+import pytest
+
from mammoth import documents
from mammoth.docx.xmlparser import element as xml_element, text as xml_text
from mammoth.docx.document_xml import read_document_xml_element
@@ -5,6 +7,29 @@ from mammoth.docx import body_xml
from ..testing import assert_equal
+def test_when_body_element_is_present_then_body_is_read():
+ paragraph_xml = xml_element("w:p", {}, [])
+ body_xml = xml_element("w:body", {}, [paragraph_xml])
+ document_xml = xml_element("w:document", {}, [body_xml])
+
+ document = _read_and_get_document_xml_element(document_xml)
+
+ assert_equal(
+ documents.document([documents.paragraph([])]),
+ document
+ )
+
+
+def test_when_body_element_is_not_present_then_error_is_raised():
+ paragraph_xml = xml_element("w:p", {}, [])
+ body_xml = xml_element("w:body2", {}, [paragraph_xml])
+ document_xml = xml_element("w:document", {}, [body_xml])
+
+ error = pytest.raises(ValueError, lambda: _read_and_get_document_xml_element(document_xml))
+
+ assert_equal(str(error.value), "Could not find the body element: are you sure this is a docx file?")
+
+
def test_can_read_text_within_document():
element = _document_element_with_text("Hello!")
assert_equal(