1
1
from __future__ import annotations
2
2
3
+ from pathlib import Path
4
+
3
5
import pytest
4
6
5
7
from PIL import Image
6
8
7
9
from .helper import assert_image , assert_image_equal , assert_image_similar , hopper
8
10
9
11
10
- def test_sanity ():
11
- def convert (im , mode ) :
12
+ def test_sanity () -> None :
13
+ def convert (im : Image . Image , mode : str ) -> None :
12
14
out = im .convert (mode )
13
15
assert out .mode == mode
14
16
assert out .size == im .size
@@ -40,13 +42,13 @@ def convert(im, mode):
40
42
convert (im , output_mode )
41
43
42
44
43
- def test_unsupported_conversion ():
45
+ def test_unsupported_conversion () -> None :
44
46
im = hopper ()
45
47
with pytest .raises (ValueError ):
46
48
im .convert ("INVALID" )
47
49
48
50
49
- def test_default ():
51
+ def test_default () -> None :
50
52
im = hopper ("P" )
51
53
assert im .mode == "P"
52
54
converted_im = im .convert ()
@@ -62,18 +64,18 @@ def test_default():
62
64
# ref https://github.com/python-pillow/Pillow/issues/274
63
65
64
66
65
- def _test_float_conversion (im ) :
67
+ def _test_float_conversion (im : Image . Image ) -> None :
66
68
orig = im .getpixel ((5 , 5 ))
67
69
converted = im .convert ("F" ).getpixel ((5 , 5 ))
68
70
assert orig == converted
69
71
70
72
71
- def test_8bit ():
73
+ def test_8bit () -> None :
72
74
with Image .open ("Tests/images/hopper.jpg" ) as im :
73
75
_test_float_conversion (im .convert ("L" ))
74
76
75
77
76
- def test_16bit ():
78
+ def test_16bit () -> None :
77
79
with Image .open ("Tests/images/16bit.cropped.tif" ) as im :
78
80
_test_float_conversion (im )
79
81
@@ -83,19 +85,19 @@ def test_16bit():
83
85
assert im_i16 .getpixel ((0 , 0 )) == 65535
84
86
85
87
86
- def test_16bit_workaround ():
88
+ def test_16bit_workaround () -> None :
87
89
with Image .open ("Tests/images/16bit.cropped.tif" ) as im :
88
90
_test_float_conversion (im .convert ("I" ))
89
91
90
92
91
- def test_opaque ():
93
+ def test_opaque () -> None :
92
94
alpha = hopper ("P" ).convert ("PA" ).getchannel ("A" )
93
95
94
96
solid = Image .new ("L" , (128 , 128 ), 255 )
95
97
assert_image_equal (alpha , solid )
96
98
97
99
98
- def test_rgba_p ():
100
+ def test_rgba_p () -> None :
99
101
im = hopper ("RGBA" )
100
102
im .putalpha (hopper ("L" ))
101
103
@@ -105,14 +107,14 @@ def test_rgba_p():
105
107
assert_image_similar (im , comparable , 20 )
106
108
107
109
108
- def test_rgba ():
110
+ def test_rgba () -> None :
109
111
with Image .open ("Tests/images/transparent.png" ) as im :
110
112
assert im .mode == "RGBA"
111
113
112
114
assert_image_similar (im .convert ("RGBa" ).convert ("RGB" ), im .convert ("RGB" ), 1.5 )
113
115
114
116
115
- def test_trns_p (tmp_path ) :
117
+ def test_trns_p (tmp_path : Path ) -> None :
116
118
im = hopper ("P" )
117
119
im .info ["transparency" ] = 0
118
120
@@ -131,7 +133,7 @@ def test_trns_p(tmp_path):
131
133
132
134
133
135
@pytest .mark .parametrize ("mode" , ("LA" , "PA" , "RGBA" ))
134
- def test_trns_p_transparency (mode ) :
136
+ def test_trns_p_transparency (mode : str ) -> None :
135
137
# Arrange
136
138
im = hopper ("P" )
137
139
im .info ["transparency" ] = 128
@@ -148,7 +150,7 @@ def test_trns_p_transparency(mode):
148
150
assert converted_im .palette is None
149
151
150
152
151
- def test_trns_l (tmp_path ) :
153
+ def test_trns_l (tmp_path : Path ) -> None :
152
154
im = hopper ("L" )
153
155
im .info ["transparency" ] = 128
154
156
@@ -171,7 +173,7 @@ def test_trns_l(tmp_path):
171
173
im_p .save (f )
172
174
173
175
174
- def test_trns_RGB (tmp_path ) :
176
+ def test_trns_RGB (tmp_path : Path ) -> None :
175
177
im = hopper ("RGB" )
176
178
im .info ["transparency" ] = im .getpixel ((0 , 0 ))
177
179
@@ -201,7 +203,7 @@ def test_trns_RGB(tmp_path):
201
203
202
204
203
205
@pytest .mark .parametrize ("convert_mode" , ("L" , "LA" , "I" ))
204
- def test_l_macro_rounding (convert_mode ) :
206
+ def test_l_macro_rounding (convert_mode : str ) -> None :
205
207
for mode in ("P" , "PA" ):
206
208
im = Image .new (mode , (1 , 1 ))
207
209
im .palette .getcolor ((0 , 1 , 2 ))
@@ -214,7 +216,7 @@ def test_l_macro_rounding(convert_mode):
214
216
assert converted_color == 1
215
217
216
218
217
- def test_gif_with_rgba_palette_to_p ():
219
+ def test_gif_with_rgba_palette_to_p () -> None :
218
220
# See https://github.com/python-pillow/Pillow/issues/2433
219
221
with Image .open ("Tests/images/hopper.gif" ) as im :
220
222
im .info ["transparency" ] = 255
@@ -226,7 +228,7 @@ def test_gif_with_rgba_palette_to_p():
226
228
im_p .load ()
227
229
228
230
229
- def test_p_la ():
231
+ def test_p_la () -> None :
230
232
im = hopper ("RGBA" )
231
233
alpha = hopper ("L" )
232
234
im .putalpha (alpha )
@@ -236,7 +238,7 @@ def test_p_la():
236
238
assert_image_similar (alpha , comparable , 5 )
237
239
238
240
239
- def test_p2pa_alpha ():
241
+ def test_p2pa_alpha () -> None :
240
242
with Image .open ("Tests/images/tiny.png" ) as im :
241
243
assert im .mode == "P"
242
244
@@ -250,13 +252,13 @@ def test_p2pa_alpha():
250
252
assert im_a .getpixel ((x , y )) == alpha
251
253
252
254
253
- def test_p2pa_palette ():
255
+ def test_p2pa_palette () -> None :
254
256
with Image .open ("Tests/images/tiny.png" ) as im :
255
257
im_pa = im .convert ("PA" )
256
258
assert im_pa .getpalette () == im .getpalette ()
257
259
258
260
259
- def test_matrix_illegal_conversion ():
261
+ def test_matrix_illegal_conversion () -> None :
260
262
# Arrange
261
263
im = hopper ("CMYK" )
262
264
# fmt: off
@@ -272,7 +274,7 @@ def test_matrix_illegal_conversion():
272
274
im .convert (mode = "CMYK" , matrix = matrix )
273
275
274
276
275
- def test_matrix_wrong_mode ():
277
+ def test_matrix_wrong_mode () -> None :
276
278
# Arrange
277
279
im = hopper ("L" )
278
280
# fmt: off
@@ -289,7 +291,7 @@ def test_matrix_wrong_mode():
289
291
290
292
291
293
@pytest .mark .parametrize ("mode" , ("RGB" , "L" ))
292
- def test_matrix_xyz (mode ) :
294
+ def test_matrix_xyz (mode : str ) -> None :
293
295
# Arrange
294
296
im = hopper ("RGB" )
295
297
im .info ["transparency" ] = (255 , 0 , 0 )
@@ -317,7 +319,7 @@ def test_matrix_xyz(mode):
317
319
assert converted_im .info ["transparency" ] == 105
318
320
319
321
320
- def test_matrix_identity ():
322
+ def test_matrix_identity () -> None :
321
323
# Arrange
322
324
im = hopper ("RGB" )
323
325
# fmt: off
0 commit comments