From 659c4ffe6ade2d8132873ae3f3f3a22df38fdb37 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 5 Dec 2026 11:06:47 +0000 Subject: Handle XML documents that are missing a root element --- tests/docx/office_xml_tests.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests/docx/office_xml_tests.py') diff --git a/tests/docx/office_xml_tests.py b/tests/docx/office_xml_tests.py index 05897db..34566ff 100644 --- a/tests/docx/office_xml_tests.py +++ b/tests/docx/office_xml_tests.py @@ -2,10 +2,18 @@ from __future__ import unicode_literals import io +import pytest + from mammoth.docx import xmlparser as xml, office_xml from ..testing import assert_equal +def test_when_document_is_missing_root_element_then_none_is_returned(): + xml_string = '' + + pytest.raises(xml.NoRootElementError, lambda: office_xml.read(io.StringIO(xml_string))) + + class AlternateContentTests(object): def test_when_fallback_is_present_then_fallback_is_read(self): xml_string = ( -- cgit v1.2.3