aboutsummaryrefslogtreecommitdiff
path: root/tests/mammoth_tests.py
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2017-03-27 18:41:19 +0100
committerMichael Williamson <mike@zwobble.org>2017-03-27 18:41:19 +0100
commit3bb202f320d0fc548bbe569f3d6abdfc0698773e (patch)
treeb906ccdbb67b7d80fe9fca794a7ff8b76c0359dd /tests/mammoth_tests.py
parent09ccf2bdc28da0ef5727848059872f995f9b30f4 (diff)
Add top-level test for convert_image arg
Diffstat (limited to 'tests/mammoth_tests.py')
-rw-r--r--tests/mammoth_tests.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/mammoth_tests.py b/tests/mammoth_tests.py
index 8789855..bcdf5a8 100644
--- a/tests/mammoth_tests.py
+++ b/tests/mammoth_tests.py
@@ -2,6 +2,7 @@
from __future__ import unicode_literals
+import base64
import io
import shutil
import os
@@ -157,6 +158,23 @@ def warn_if_images_stored_outside_of_document_are_not_found():
assert_equal("warning", result.messages[0].type)
assert result.messages[0].message.startswith(expected_warning), "message was: " + result.messages[0].message
assert_equal(1, len(result.messages))
+
+
+@istest
+def image_conversion_can_be_customised():
+ @mammoth.images.img_element
+ def convert_image(image):
+ with image.open() as image_bytes:
+ encoded_src = base64.b64encode(image_bytes.read()).decode("ascii")
+
+ return {
+ "src": encoded_src[:2] + "," + image.content_type
+ }
+
+ with open(test_path("tiny-picture.docx"), "rb") as fileobj:
+ result = mammoth.convert_to_html(fileobj=fileobj, convert_image=convert_image)
+ assert_equal("""<p><img src="iV,image/png" /></p>""", result.value)
+ assert_equal([], result.messages)
@istest