aboutsummaryrefslogtreecommitdiff
path: root/tests/docx
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2018-01-23 21:43:30 +0000
committerMichael Williamson <mike@zwobble.org>2018-01-23 21:43:30 +0000
commit93e07b02624f668aa9300c048cde05bb416dda35 (patch)
treeea83907583ae87fde53955f9e61065b5d9fd3231 /tests/docx
parent804dc4c1666c7f0c24528acf3cf3083a46492e4d (diff)
Raise error when main document part does not exist
Diffstat (limited to 'tests/docx')
-rw-r--r--tests/docx/docx_tests.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/tests/docx/docx_tests.py b/tests/docx/docx_tests.py
index 8bd5b36..d450424 100644
--- a/tests/docx/docx_tests.py
+++ b/tests/docx/docx_tests.py
@@ -5,7 +5,7 @@ import zipfile
from nose.tools import istest, assert_equal
from mammoth import docx, documents
-from ..testing import test_path
+from ..testing import assert_raises, test_path
@istest
@@ -62,6 +62,23 @@ def main_document_is_found_using_package_relationships():
assert_equal(expected_document, result.value)
+@istest
+def error_is_raised_when_main_document_part_does_not_exist():
+ fileobj = _create_zip({
+ "_rels/.rels": textwrap.dedent("""\
+ <?xml version="1.0" encoding="utf-8"?>
+ <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
+ <Relationship Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="/word/document2.xml" Id="rId1"/>
+ </Relationships>
+ """),
+ })
+ error = assert_raises(IOError, lambda: docx.read(fileobj=fileobj))
+ assert_equal(
+ "Could not find main document part. Are you sure this is a valid .docx file?",
+ str(error),
+ )
+
+
def _create_zip(files):
fileobj = io.BytesIO()