From 1c14ed25d75caf3228a92d8f7292bf0bf040653b Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Thu, 20 Aug 2015 20:34:34 +0100 Subject: Fix: cannot read file objects with name attribute --- tests/docx/body_xml_tests.py | 1 + tests/mammoth_tests.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+) (limited to 'tests') diff --git a/tests/docx/body_xml_tests.py b/tests/docx/body_xml_tests.py index 6122706..da662d8 100644 --- a/tests/docx/body_xml_tests.py +++ b/tests/docx/body_xml_tests.py @@ -406,6 +406,7 @@ class ReadXmlElementTests(object): }) files = context.mock() + funk.allows(files).verify("file:///media/hat.png") funk.allows(files).open("file:///media/hat.png").returns(io.BytesIO(image_bytes)) content_types = context.mock() diff --git a/tests/mammoth_tests.py b/tests/mammoth_tests.py index ddcb9a6..89336b3 100644 --- a/tests/mammoth_tests.py +++ b/tests/mammoth_tests.py @@ -2,6 +2,9 @@ from __future__ import unicode_literals +import io +import shutil + from nose.tools import istest, assert_equal from .testing import test_path @@ -67,6 +70,17 @@ def images_stored_outside_of_document_are_included_in_output(): result = mammoth.convert_to_html(fileobj=fileobj) assert_equal("""

""", result.value) assert_equal([], result.messages) + + +@istest +def warn_if_images_stored_outside_of_document_are_specified_when_passing_fileobj_without_name(): + fileobj = io.BytesIO() + with open(test_path("external-picture.docx"), "rb") as source_fileobj: + shutil.copyfileobj(source_fileobj, fileobj) + + result = mammoth.convert_to_html(fileobj=fileobj) + assert_equal("", result.value) + assert_equal([results.warning("could not find external image 'tiny-picture.png', fileobj has no name")], result.messages) @istest -- cgit v1.2.3