Skip to content

Commit

Permalink
Ensure SVG files are given a mime type (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
RealOrangeOne authored Sep 6, 2023
1 parent 7bf6489 commit c07cafe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ def test_mime_type_must_be_implemented(self):
with self.assertRaises(NotImplementedError):
broken.mime_type

def test_implementations_have_required_methods(self):
for image_class in ImageFile.__subclasses__():
if image_class == BrokenImageFileImplementation:
continue

with self.subTest(image_class):
self.assertTrue(hasattr(image_class, "mime_type"))
self.assertTrue(hasattr(image_class, "format_name"))


class TestDetectImageFormatFromStream(unittest.TestCase):
"""
Expand Down Expand Up @@ -92,6 +101,7 @@ def test_opens_svg(self):
image = Image.open(f)
self.assertIsInstance(image, SvgImageFile)
self.assertEqual(image.format_name, "svg")
self.assertEqual(image.mime_type, "image/svg+xml")

def test_invalid_svg_raises(self):
f = io.BytesIO(b"<svg><")
Expand Down
1 change: 1 addition & 0 deletions willow/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ def mime_type(self):

class SvgImageFile(ImageFile):
format_name = "svg"
mime_type = "image/svg+xml"

def __init__(self, f, dom=None):
if dom is None:
Expand Down

0 comments on commit c07cafe

Please sign in to comment.