IcoImagePlugin: raise specific exception like CurImagePlugin if no images

This commit is contained in:
Aarni Koskela 2023-02-22 10:36:10 +02:00
parent 583dd3b424
commit b7055aeaba
3 changed files with 9 additions and 0 deletions

BIN
Tests/images/no_icons.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6 B

View File

@ -229,3 +229,8 @@ def test_draw_reloaded(tmp_path):
with Image.open(outfile) as im:
assert_image_equal_tofile(im, "Tests/images/hopper_draw.ico")
def test_empty():
with pytest.raises(SyntaxError, match="No images were found"):
IcoImagePlugin.IcoImageFile("Tests/images/no_icons.ico")

View File

@ -172,6 +172,10 @@ class IcoFile:
self.entry.append(icon_header)
if not self.entry:
msg = "No images were found"
raise TypeError(msg)
self.entry = sorted(self.entry, key=lambda x: x["color_depth"])
# ICO images are usually squares
# self.entry = sorted(self.entry, key=lambda x: x['width'])