1
1
from __future__ import annotations
2
2
3
+ from io import BytesIO
4
+
3
5
import pytest
4
6
5
7
from 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
6
11
7
12
TEST_FILE = "Tests/images/deerstalker.cur"
8
13
@@ -17,6 +22,24 @@ def test_sanity() -> None:
17
22
assert im .getpixel ((16 , 16 )) == (84 , 87 , 86 , 255 )
18
23
19
24
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
+
20
43
def test_invalid_file () -> None :
21
44
invalid_file = "Tests/images/flower.jpg"
22
45
@@ -26,6 +49,7 @@ def test_invalid_file() -> None:
26
49
no_cursors_file = "Tests/images/no_cursors.cur"
27
50
28
51
cur = CurImagePlugin .CurImageFile (TEST_FILE )
52
+ assert cur .fp is not None
29
53
cur .fp .close ()
30
54
with open (no_cursors_file , "rb" ) as cur .fp :
31
55
with pytest .raises (TypeError ):
0 commit comments