aboutsummaryrefslogtreecommitdiff
path: root/tests/images_tests.py
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2022-08-31 21:33:29 +0100
committerMichael Williamson <mike@zwobble.org>2022-08-31 21:33:29 +0100
commit2736ab6dbfa95c4a6d99837b715ecccb23c84215 (patch)
treed32a35f1a940fac2a81a4457373ab936359b0208 /tests/images_tests.py
parent8b354c6b086259fe023a6ec333ae99f59f01684d (diff)
Only use the alt text of image elements as a fallback
Diffstat (limited to 'tests/images_tests.py')
-rw-r--r--tests/images_tests.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/images_tests.py b/tests/images_tests.py
index 49784d3..0ab29e1 100644
--- a/tests/images_tests.py
+++ b/tests/images_tests.py
@@ -66,3 +66,22 @@ class ImgElementTests:
assert_that(result, is_sequence(
has_attrs(attributes={"alt": "<alt>", "src": "<src>"}),
))
+
+ @istest
+ def test_image_alt_text_can_be_overridden_by_alt_attribute_returned_from_function(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 {"alt": "<alt override>", "src": "<src>"}
+
+ result = convert_image(image)
+
+ assert_that(result, is_sequence(
+ has_attrs(attributes={"alt": "<alt override>", "src": "<src>"}),
+ ))