From df5644cde6ba9b70870ddb01caaee423e00e49ad Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Fri, 19 Jan 2018 20:12:18 +0000 Subject: Read document XML path from _rels/.rels --- tests/docx/docx_tests.py | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'tests/docx') diff --git a/tests/docx/docx_tests.py b/tests/docx/docx_tests.py index ea69dc2..fd53d4f 100644 --- a/tests/docx/docx_tests.py +++ b/tests/docx/docx_tests.py @@ -1,3 +1,7 @@ +import io +import textwrap +import zipfile + from nose.tools import istest, assert_equal from mammoth import docx, documents @@ -18,3 +22,52 @@ class ReadTests(object): ]) ]) assert_equal(expected_document, result.value) + + +_relationship_namespaces = { + "r": "http://schemas.openxmlformats.org/package/2006/relationships", +} + + +@istest +def when_document_xml_is_not_present_then_document_is_found_using_file_relationships(): + fileobj = _create_zip({ + "word/document2.xml": textwrap.dedent("""\ + + + + + + Hello. + + + + + """), + "_rels/.rels": textwrap.dedent("""\ + + + + + """), + }) + result = docx.read(fileobj=fileobj) + expected_document = documents.document([ + documents.paragraph([ + documents.run([ + documents.text("Hello.") + ]) + ]) + ]) + assert_equal(expected_document, result.value) + + +def _create_zip(files): + fileobj = io.BytesIO() + + with zipfile.ZipFile(fileobj, "w") as zip_file: + for name, contents in files.items(): + zip_file.writestr(name, contents) + + fileobj.seek(0) + return fileobj -- cgit v1.2.3