diff options
| author | Michael Williamson <mike@zwobble.org> | 2022-08-31 21:30:26 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2022-08-31 21:30:26 +0100 |
| commit | 8b354c6b086259fe023a6ec333ae99f59f01684d (patch) | |
| tree | 0c234c17b1cd5844074d145fca9975245a1faa14 | |
| parent | 2dee4de65d6f94da7c46a484716ab504d356a0be (diff) | |
Add tests for mammoth.images.img_element()
| -rw-r--r-- | tests/images_tests.py | 41 |
1 files changed, 41 insertions, 0 deletions
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": "<src>"} + + result = convert_image(image) + + assert_that(result, is_sequence( + has_attrs(attributes={"src": "<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="<alt>", + content_type="image/jpeg", + open=lambda: io.BytesIO(image_bytes), + ) + + @mammoth.images.img_element + def convert_image(image): + return {"src": "<src>"} + + result = convert_image(image) + + assert_that(result, is_sequence( + has_attrs(attributes={"alt": "<alt>", "src": "<src>"}), + )) |
