From 8b354c6b086259fe023a6ec333ae99f59f01684d Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Wed, 31 Aug 2022 21:30:26 +0100 Subject: Add tests for mammoth.images.img_element() --- tests/images_tests.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/images_tests.py b/tests/images_tests.py index 508d141..49784d3 100644 --- a/tests/images_tests.py +++ b/tests/images_tests.py @@ -25,3 +25,44 @@ def data_uri_encodes_images_in_base64(): assert_that(result, is_sequence( has_attrs(attributes={"src": "data:image/jpeg;base64,YWJj"}), )) + + +@istest +class ImgElementTests: + @istest + def test_when_element_does_not_have_alt_text_then_alt_attribute_is_not_set(self): + image_bytes = b"abc" + image = mammoth.documents.Image( + alt_text=None, + content_type="image/jpeg", + open=lambda: io.BytesIO(image_bytes), + ) + + @mammoth.images.img_element + def convert_image(image): + return {"src": ""} + + result = convert_image(image) + + assert_that(result, is_sequence( + has_attrs(attributes={"src": ""}), + )) + + @istest + def test_when_element_se_alt_text_then_alt_attribute_is_set(self): + image_bytes = b"abc" + image = mammoth.documents.Image( + alt_text="", + content_type="image/jpeg", + open=lambda: io.BytesIO(image_bytes), + ) + + @mammoth.images.img_element + def convert_image(image): + return {"src": ""} + + result = convert_image(image) + + assert_that(result, is_sequence( + has_attrs(attributes={"alt": "", "src": ""}), + )) -- cgit v1.2.3