aboutsummaryrefslogtreecommitdiff
path: root/tests/images_tests.py
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-08-09 14:45:32 +0100
committerMichael Williamson <mike@zwobble.org>2026-08-09 14:45:32 +0100
commit32f3d9fae7ad0a4ad7cc9c74d81a6fd670912fbe (patch)
tree42e0fd73b717c05c4ef69e6a64013fdde2fbfe88 /tests/images_tests.py
parent1cac2458ea3c0a68754f1cc86df3aee50b02782b (diff)
Check image content type for backslashes
Diffstat (limited to 'tests/images_tests.py')
-rw-r--r--tests/images_tests.py35
1 files changed, 34 insertions, 1 deletions
diff --git a/tests/images_tests.py b/tests/images_tests.py
index 6e2487d..024aeb0 100644
--- a/tests/images_tests.py
+++ b/tests/images_tests.py
@@ -1,6 +1,6 @@
import io
-from precisely import assert_that, has_attrs, is_sequence
+from precisely import assert_that, equal_to, has_attrs, is_sequence
import mammoth
@@ -78,3 +78,36 @@ class ImgElementTests:
assert_that(result, is_sequence(
has_attrs(attributes={"alt": "<alt override>", "src": "<src>"}),
))
+
+
+class ImageFilenameExtensionTests:
+ def test_extension_is_derived_from_subtype_of_content_type(self):
+ image = self._image_with_content_type("image/gif")
+
+ result = mammoth.images.image_filename_extension(image)
+
+ assert_that(result, equal_to("gif"))
+
+ def test_data_after_second_slash_is_ignored(self):
+ image = self._image_with_content_type("image/gif/jpeg")
+
+ result = mammoth.images.image_filename_extension(image)
+
+ assert_that(result, equal_to("gif"))
+
+ def test_backslashes_are_treated_as_forward_slashes(self):
+ image = self._image_with_content_type("image\\gif\\..\\")
+
+ result = mammoth.images.image_filename_extension(image)
+
+ assert_that(result, equal_to("gif"))
+
+ def test_when_there_is_no_subtype_then_none_is_returned(self):
+ image = self._image_with_content_type("image")
+
+ result = mammoth.images.image_filename_extension(image)
+
+ assert_that(result, equal_to(None))
+
+ def _image_with_content_type(self, content_type):
+ return mammoth.documents.Image(alt_text="", content_type=content_type, open=None)