From 06b5117f11e1a4265528b15d43e2c6a6ffb7eeee Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 27 Jan 2018 17:17:16 +0000 Subject: Add tests for _find_part_paths --- tests/docx/docx_tests.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/docx/docx_tests.py b/tests/docx/docx_tests.py index d450424..a474b17 100644 --- a/tests/docx/docx_tests.py +++ b/tests/docx/docx_tests.py @@ -4,7 +4,7 @@ import zipfile from nose.tools import istest, assert_equal -from mammoth import docx, documents +from mammoth import docx, documents, zips from ..testing import assert_raises, test_path @@ -78,6 +78,32 @@ def error_is_raised_when_main_document_part_does_not_exist(): str(error), ) +class TestPartPaths(object): + @istest + def main_document_part_is_found_using_package_relationships(self): + fileobj = _create_zip({ + "word/document2.xml": " ", + "_rels/.rels": textwrap.dedent("""\ + + + + + """), + }) + part_paths = self._find_part_paths(fileobj) + assert_equal("word/document2.xml", part_paths.main_document) + + @istest + def when_relationship_for_main_document_cannot_be_found_then_fallback_is_used(self): + fileobj = _create_zip({ + "word/document.xml": " ", + }) + part_paths = self._find_part_paths(fileobj) + assert_equal("word/document.xml", part_paths.main_document) + + def _find_part_paths(self, fileobj): + return docx._find_part_paths(zips.open_zip(fileobj, "r")) + def _create_zip(files): fileobj = io.BytesIO() -- cgit v1.2.3