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 = ( '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '') 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 = ( '' + '' + '' + '' + '' + '' + '' + '') result = office_xml.read(io.StringIO(xml_string)) assert_equal([], result.children)