aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2013-12-14 16:53:02 +0000
committerMichael Williamson <mike@zwobble.org>2013-12-14 16:53:02 +0000
commita5574fbb4540ca31ab0d4c639f6cd2a633e749fc (patch)
tree1a2a2af2368e8685ee19a88e7621890fd55409f7 /tests
parenta96ab058644e43bb5fdf32c0b3b238e1a9e1360f (diff)
Allow custom image conversion
Diffstat (limited to 'tests')
-rw-r--r--tests/conversion_tests.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/conversion_tests.py b/tests/conversion_tests.py
index 5088288..4732991 100644
--- a/tests/conversion_tests.py
+++ b/tests/conversion_tests.py
@@ -131,5 +131,16 @@ def images_have_alt_tags_if_available():
assert_equal('<img src="data:image/png;base64,YWJj" alt="It\'s a hat" />', result.value)
+@istest
+def can_define_custom_conversion_for_images():
+ def convert_image(image, html_generator):
+ with image.open() as image_file:
+ html_generator.self_closing("img", {"alt": image_file.read()})
+
+ image = documents.image(alt_text=None, content_type="image/png", open=lambda: io.BytesIO("abc"))
+ result = convert_document_element_to_html(image, convert_image=convert_image)
+ assert_equal('<img alt="abc" />', result.value)
+
+
def _run_with_text(text):
return documents.run(children=[documents.text(text)])