mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-24 17:06:16 +03:00
Throw TypeError if no cursors were found in .cur file
This commit is contained in:
parent
ea2982f284
commit
0c3e224537
|
@ -66,6 +66,8 @@ class CurImageFile(BmpImagePlugin.BmpImageFile):
|
|||
# print "hotspot y", i16(s[6:])
|
||||
# print "bytes", i32(s[8:])
|
||||
# print "offset", i32(s[12:])
|
||||
if not m:
|
||||
raise TypeError("No cursors were found")
|
||||
|
||||
# load as bitmap
|
||||
self._bitmap(i32(m[12:]) + offset)
|
||||
|
|
BIN
Tests/images/no_cursors.cur
Normal file
BIN
Tests/images/no_cursors.cur
Normal file
Binary file not shown.
After Width: | Height: | Size: 6 B |
|
@ -2,17 +2,14 @@ from helper import unittest, PillowTestCase
|
|||
|
||||
from PIL import Image, CurImagePlugin
|
||||
|
||||
TEST_FILE = "Tests/images/deerstalker.cur"
|
||||
|
||||
|
||||
class TestFileCur(PillowTestCase):
|
||||
|
||||
def test_sanity(self):
|
||||
# Arrange
|
||||
test_file = "Tests/images/deerstalker.cur"
|
||||
im = Image.open(TEST_FILE)
|
||||
|
||||
# Act
|
||||
im = Image.open(test_file)
|
||||
|
||||
# Assert
|
||||
self.assertEqual(im.size, (32, 32))
|
||||
self.assertIsInstance(im, CurImagePlugin.CurImageFile)
|
||||
# Check some pixel colors to ensure image is loaded properly
|
||||
|
@ -26,6 +23,12 @@ class TestFileCur(PillowTestCase):
|
|||
self.assertRaises(SyntaxError,
|
||||
lambda: CurImagePlugin.CurImageFile(invalid_file))
|
||||
|
||||
no_cursors_file = "Tests/images/no_cursors.cur"
|
||||
|
||||
cur = CurImagePlugin.CurImageFile(TEST_FILE)
|
||||
cur.fp = open(no_cursors_file, "rb")
|
||||
self.assertRaises(TypeError, cur._open)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Loading…
Reference in New Issue
Block a user