11from __future__ import annotations
22
3+ from io import BytesIO
4+
35import pytest
46
57from PIL import CurImagePlugin , Image
8+ from PIL ._binary import o8
9+ from PIL ._binary import o16le as o16
10+ from PIL ._binary import o32le as o32
611
712TEST_FILE = "Tests/images/deerstalker.cur"
813
@@ -17,6 +22,24 @@ def test_sanity() -> None:
1722 assert im .getpixel ((16 , 16 )) == (84 , 87 , 86 , 255 )
1823
1924
25+ def test_largest_cursor () -> None :
26+ magic = b"\x00 \x00 \x02 \x00 "
27+ sizes = ((1 , 1 ), (8 , 8 ), (4 , 4 ))
28+ data = magic + o16 (len (sizes ))
29+ for w , h in sizes :
30+ image_offset = 6 + len (sizes ) * 16 if (w , h ) == max (sizes ) else 0
31+ data += o8 (w ) + o8 (h ) + o8 (0 ) * 10 + o32 (image_offset )
32+ data += (
33+ o32 (12 ) # header size
34+ + o16 (8 ) # width
35+ + o16 (16 ) # height
36+ + o16 (0 ) # planes
37+ + o16 (1 ) # bits
38+ )
39+ with Image .open (BytesIO (data )) as im :
40+ assert im .size == (8 , 8 )
41+
42+
2043def test_invalid_file () -> None :
2144 invalid_file = "Tests/images/flower.jpg"
2245
@@ -26,6 +49,7 @@ def test_invalid_file() -> None:
2649 no_cursors_file = "Tests/images/no_cursors.cur"
2750
2851 cur = CurImagePlugin .CurImageFile (TEST_FILE )
52+ assert cur .fp is not None
2953 cur .fp .close ()
3054 with open (no_cursors_file , "rb" ) as cur .fp :
3155 with pytest .raises (TypeError ):
0 commit comments