1212# (referenced from https://wiki.mozilla.org/APNG_Specification)
1313def test_apng_basic () -> None :
1414 with Image .open ("Tests/images/apng/single_frame.png" ) as im :
15+ assert isinstance (im , PngImagePlugin .PngImageFile )
1516 assert not im .is_animated
1617 assert im .n_frames == 1
1718 assert im .get_format_mimetype () == "image/apng"
@@ -20,6 +21,7 @@ def test_apng_basic() -> None:
2021 assert im .getpixel ((64 , 32 )) == (0 , 255 , 0 , 255 )
2122
2223 with Image .open ("Tests/images/apng/single_frame_default.png" ) as im :
24+ assert isinstance (im , PngImagePlugin .PngImageFile )
2325 assert im .is_animated
2426 assert im .n_frames == 2
2527 assert im .get_format_mimetype () == "image/apng"
@@ -52,60 +54,71 @@ def test_apng_basic() -> None:
5254)
5355def test_apng_fdat (filename : str ) -> None :
5456 with Image .open (filename ) as im :
57+ assert isinstance (im , PngImagePlugin .PngImageFile )
5558 im .seek (im .n_frames - 1 )
5659 assert im .getpixel ((0 , 0 )) == (0 , 255 , 0 , 255 )
5760 assert im .getpixel ((64 , 32 )) == (0 , 255 , 0 , 255 )
5861
5962
6063def test_apng_dispose () -> None :
6164 with Image .open ("Tests/images/apng/dispose_op_none.png" ) as im :
65+ assert isinstance (im , PngImagePlugin .PngImageFile )
6266 im .seek (im .n_frames - 1 )
6367 assert im .getpixel ((0 , 0 )) == (0 , 255 , 0 , 255 )
6468 assert im .getpixel ((64 , 32 )) == (0 , 255 , 0 , 255 )
6569
6670 with Image .open ("Tests/images/apng/dispose_op_background.png" ) as im :
71+ assert isinstance (im , PngImagePlugin .PngImageFile )
6772 im .seek (im .n_frames - 1 )
6873 assert im .getpixel ((0 , 0 )) == (0 , 0 , 0 , 0 )
6974 assert im .getpixel ((64 , 32 )) == (0 , 0 , 0 , 0 )
7075
7176 with Image .open ("Tests/images/apng/dispose_op_background_final.png" ) as im :
77+ assert isinstance (im , PngImagePlugin .PngImageFile )
7278 im .seek (im .n_frames - 1 )
7379 assert im .getpixel ((0 , 0 )) == (0 , 255 , 0 , 255 )
7480 assert im .getpixel ((64 , 32 )) == (0 , 255 , 0 , 255 )
7581
7682 with Image .open ("Tests/images/apng/dispose_op_previous.png" ) as im :
83+ assert isinstance (im , PngImagePlugin .PngImageFile )
7784 im .seek (im .n_frames - 1 )
7885 assert im .getpixel ((0 , 0 )) == (0 , 255 , 0 , 255 )
7986 assert im .getpixel ((64 , 32 )) == (0 , 255 , 0 , 255 )
8087
8188 with Image .open ("Tests/images/apng/dispose_op_previous_final.png" ) as im :
89+ assert isinstance (im , PngImagePlugin .PngImageFile )
8290 im .seek (im .n_frames - 1 )
8391 assert im .getpixel ((0 , 0 )) == (0 , 255 , 0 , 255 )
8492 assert im .getpixel ((64 , 32 )) == (0 , 255 , 0 , 255 )
8593
8694 with Image .open ("Tests/images/apng/dispose_op_previous_first.png" ) as im :
95+ assert isinstance (im , PngImagePlugin .PngImageFile )
8796 im .seek (im .n_frames - 1 )
8897 assert im .getpixel ((0 , 0 )) == (0 , 0 , 0 , 0 )
8998 assert im .getpixel ((64 , 32 )) == (0 , 0 , 0 , 0 )
9099
91100
92101def test_apng_dispose_region () -> None :
93102 with Image .open ("Tests/images/apng/dispose_op_none_region.png" ) as im :
103+ assert isinstance (im , PngImagePlugin .PngImageFile )
94104 im .seek (im .n_frames - 1 )
95105 assert im .getpixel ((0 , 0 )) == (0 , 255 , 0 , 255 )
96106 assert im .getpixel ((64 , 32 )) == (0 , 255 , 0 , 255 )
97107
98108 with Image .open ("Tests/images/apng/dispose_op_background_before_region.png" ) as im :
109+ assert isinstance (im , PngImagePlugin .PngImageFile )
99110 im .seek (im .n_frames - 1 )
100111 assert im .getpixel ((0 , 0 )) == (0 , 0 , 0 , 0 )
101112 assert im .getpixel ((64 , 32 )) == (0 , 0 , 0 , 0 )
102113
103114 with Image .open ("Tests/images/apng/dispose_op_background_region.png" ) as im :
115+ assert isinstance (im , PngImagePlugin .PngImageFile )
104116 im .seek (im .n_frames - 1 )
105117 assert im .getpixel ((0 , 0 )) == (0 , 0 , 255 , 255 )
106118 assert im .getpixel ((64 , 32 )) == (0 , 0 , 0 , 0 )
107119
108120 with Image .open ("Tests/images/apng/dispose_op_previous_region.png" ) as im :
121+ assert isinstance (im , PngImagePlugin .PngImageFile )
109122 im .seek (im .n_frames - 1 )
110123 assert im .getpixel ((0 , 0 )) == (0 , 255 , 0 , 255 )
111124 assert im .getpixel ((64 , 32 )) == (0 , 255 , 0 , 255 )
@@ -132,6 +145,7 @@ def test_apng_dispose_op_previous_frame() -> None:
132145 # ],
133146 # )
134147 with Image .open ("Tests/images/apng/dispose_op_previous_frame.png" ) as im :
148+ assert isinstance (im , PngImagePlugin .PngImageFile )
135149 im .seek (im .n_frames - 1 )
136150 assert im .getpixel ((0 , 0 )) == (255 , 0 , 0 , 255 )
137151
@@ -145,26 +159,31 @@ def test_apng_dispose_op_background_p_mode() -> None:
145159
146160def test_apng_blend () -> None :
147161 with Image .open ("Tests/images/apng/blend_op_source_solid.png" ) as im :
162+ assert isinstance (im , PngImagePlugin .PngImageFile )
148163 im .seek (im .n_frames - 1 )
149164 assert im .getpixel ((0 , 0 )) == (0 , 255 , 0 , 255 )
150165 assert im .getpixel ((64 , 32 )) == (0 , 255 , 0 , 255 )
151166
152167 with Image .open ("Tests/images/apng/blend_op_source_transparent.png" ) as im :
168+ assert isinstance (im , PngImagePlugin .PngImageFile )
153169 im .seek (im .n_frames - 1 )
154170 assert im .getpixel ((0 , 0 )) == (0 , 0 , 0 , 0 )
155171 assert im .getpixel ((64 , 32 )) == (0 , 0 , 0 , 0 )
156172
157173 with Image .open ("Tests/images/apng/blend_op_source_near_transparent.png" ) as im :
174+ assert isinstance (im , PngImagePlugin .PngImageFile )
158175 im .seek (im .n_frames - 1 )
159176 assert im .getpixel ((0 , 0 )) == (0 , 255 , 0 , 2 )
160177 assert im .getpixel ((64 , 32 )) == (0 , 255 , 0 , 2 )
161178
162179 with Image .open ("Tests/images/apng/blend_op_over.png" ) as im :
180+ assert isinstance (im , PngImagePlugin .PngImageFile )
163181 im .seek (im .n_frames - 1 )
164182 assert im .getpixel ((0 , 0 )) == (0 , 255 , 0 , 255 )
165183 assert im .getpixel ((64 , 32 )) == (0 , 255 , 0 , 255 )
166184
167185 with Image .open ("Tests/images/apng/blend_op_over_near_transparent.png" ) as im :
186+ assert isinstance (im , PngImagePlugin .PngImageFile )
168187 im .seek (im .n_frames - 1 )
169188 assert im .getpixel ((0 , 0 )) == (0 , 255 , 0 , 97 )
170189 assert im .getpixel ((64 , 32 )) == (0 , 255 , 0 , 255 )
@@ -178,6 +197,7 @@ def test_apng_blend_transparency() -> None:
178197
179198def test_apng_chunk_order () -> None :
180199 with Image .open ("Tests/images/apng/fctl_actl.png" ) as im :
200+ assert isinstance (im , PngImagePlugin .PngImageFile )
181201 im .seek (im .n_frames - 1 )
182202 assert im .getpixel ((0 , 0 )) == (0 , 255 , 0 , 255 )
183203 assert im .getpixel ((64 , 32 )) == (0 , 255 , 0 , 255 )
@@ -233,38 +253,44 @@ def test_apng_num_plays() -> None:
233253
234254def test_apng_mode () -> None :
235255 with Image .open ("Tests/images/apng/mode_16bit.png" ) as im :
256+ assert isinstance (im , PngImagePlugin .PngImageFile )
236257 assert im .mode == "RGBA"
237258 im .seek (im .n_frames - 1 )
238259 assert im .getpixel ((0 , 0 )) == (0 , 0 , 128 , 191 )
239260 assert im .getpixel ((64 , 32 )) == (0 , 0 , 128 , 191 )
240261
241262 with Image .open ("Tests/images/apng/mode_grayscale.png" ) as im :
263+ assert isinstance (im , PngImagePlugin .PngImageFile )
242264 assert im .mode == "L"
243265 im .seek (im .n_frames - 1 )
244266 assert im .getpixel ((0 , 0 )) == 128
245267 assert im .getpixel ((64 , 32 )) == 255
246268
247269 with Image .open ("Tests/images/apng/mode_grayscale_alpha.png" ) as im :
270+ assert isinstance (im , PngImagePlugin .PngImageFile )
248271 assert im .mode == "LA"
249272 im .seek (im .n_frames - 1 )
250273 assert im .getpixel ((0 , 0 )) == (128 , 191 )
251274 assert im .getpixel ((64 , 32 )) == (128 , 191 )
252275
253276 with Image .open ("Tests/images/apng/mode_palette.png" ) as im :
277+ assert isinstance (im , PngImagePlugin .PngImageFile )
254278 assert im .mode == "P"
255279 im .seek (im .n_frames - 1 )
256280 im = im .convert ("RGB" )
257281 assert im .getpixel ((0 , 0 )) == (0 , 255 , 0 )
258282 assert im .getpixel ((64 , 32 )) == (0 , 255 , 0 )
259283
260284 with Image .open ("Tests/images/apng/mode_palette_alpha.png" ) as im :
285+ assert isinstance (im , PngImagePlugin .PngImageFile )
261286 assert im .mode == "P"
262287 im .seek (im .n_frames - 1 )
263288 im = im .convert ("RGBA" )
264289 assert im .getpixel ((0 , 0 )) == (0 , 255 , 0 , 255 )
265290 assert im .getpixel ((64 , 32 )) == (0 , 255 , 0 , 255 )
266291
267292 with Image .open ("Tests/images/apng/mode_palette_1bit_alpha.png" ) as im :
293+ assert isinstance (im , PngImagePlugin .PngImageFile )
268294 assert im .mode == "P"
269295 im .seek (im .n_frames - 1 )
270296 im = im .convert ("RGBA" )
@@ -274,52 +300,63 @@ def test_apng_mode() -> None:
274300
275301def test_apng_chunk_errors () -> None :
276302 with Image .open ("Tests/images/apng/chunk_no_actl.png" ) as im :
303+ assert isinstance (im , PngImagePlugin .PngImageFile )
277304 assert not im .is_animated
278305
279306 with pytest .warns (UserWarning ):
280307 with Image .open ("Tests/images/apng/chunk_multi_actl.png" ) as im :
281308 im .load ()
309+ assert isinstance (im , PngImagePlugin .PngImageFile )
282310 assert not im .is_animated
283311
284312 with Image .open ("Tests/images/apng/chunk_actl_after_idat.png" ) as im :
313+ assert isinstance (im , PngImagePlugin .PngImageFile )
285314 assert not im .is_animated
286315
287316 with Image .open ("Tests/images/apng/chunk_no_fctl.png" ) as im :
317+ assert isinstance (im , PngImagePlugin .PngImageFile )
288318 with pytest .raises (SyntaxError ):
289319 im .seek (im .n_frames - 1 )
290320
291321 with Image .open ("Tests/images/apng/chunk_repeat_fctl.png" ) as im :
322+ assert isinstance (im , PngImagePlugin .PngImageFile )
292323 with pytest .raises (SyntaxError ):
293324 im .seek (im .n_frames - 1 )
294325
295326 with Image .open ("Tests/images/apng/chunk_no_fdat.png" ) as im :
327+ assert isinstance (im , PngImagePlugin .PngImageFile )
296328 with pytest .raises (SyntaxError ):
297329 im .seek (im .n_frames - 1 )
298330
299331
300332def test_apng_syntax_errors () -> None :
301333 with pytest .warns (UserWarning ):
302334 with Image .open ("Tests/images/apng/syntax_num_frames_zero.png" ) as im :
335+ assert isinstance (im , PngImagePlugin .PngImageFile )
303336 assert not im .is_animated
304337 with pytest .raises (OSError ):
305338 im .load ()
306339
307340 with pytest .warns (UserWarning ):
308341 with Image .open ("Tests/images/apng/syntax_num_frames_zero_default.png" ) as im :
342+ assert isinstance (im , PngImagePlugin .PngImageFile )
309343 assert not im .is_animated
310344 im .load ()
311345
312346 # we can handle this case gracefully
313347 with Image .open ("Tests/images/apng/syntax_num_frames_low.png" ) as im :
348+ assert isinstance (im , PngImagePlugin .PngImageFile )
314349 im .seek (im .n_frames - 1 )
315350
316351 with pytest .raises (OSError ):
317352 with Image .open ("Tests/images/apng/syntax_num_frames_high.png" ) as im :
353+ assert isinstance (im , PngImagePlugin .PngImageFile )
318354 im .seek (im .n_frames - 1 )
319355 im .load ()
320356
321357 with pytest .warns (UserWarning ):
322358 with Image .open ("Tests/images/apng/syntax_num_frames_invalid.png" ) as im :
359+ assert isinstance (im , PngImagePlugin .PngImageFile )
323360 assert not im .is_animated
324361 im .load ()
325362
@@ -339,6 +376,7 @@ def test_apng_syntax_errors() -> None:
339376def test_apng_sequence_errors (test_file : str ) -> None :
340377 with pytest .raises (SyntaxError ):
341378 with Image .open (f"Tests/images/apng/{ test_file } " ) as im :
379+ assert isinstance (im , PngImagePlugin .PngImageFile )
342380 im .seek (im .n_frames - 1 )
343381 im .load ()
344382
@@ -349,6 +387,7 @@ def test_apng_save(tmp_path: Path) -> None:
349387 im .save (test_file , save_all = True )
350388
351389 with Image .open (test_file ) as im :
390+ assert isinstance (im , PngImagePlugin .PngImageFile )
352391 im .load ()
353392 assert not im .is_animated
354393 assert im .n_frames == 1
@@ -364,6 +403,7 @@ def test_apng_save(tmp_path: Path) -> None:
364403 )
365404
366405 with Image .open (test_file ) as im :
406+ assert isinstance (im , PngImagePlugin .PngImageFile )
367407 im .load ()
368408 assert im .is_animated
369409 assert im .n_frames == 2
@@ -403,6 +443,7 @@ def test_apng_save_split_fdat(tmp_path: Path) -> None:
403443 append_images = frames ,
404444 )
405445 with Image .open (test_file ) as im :
446+ assert isinstance (im , PngImagePlugin .PngImageFile )
406447 im .seek (im .n_frames - 1 )
407448 im .load ()
408449
@@ -445,6 +486,7 @@ def test_apng_save_duration_loop(tmp_path: Path) -> None:
445486 test_file , save_all = True , append_images = [frame , frame ], duration = [500 , 100 , 150 ]
446487 )
447488 with Image .open (test_file ) as im :
489+ assert isinstance (im , PngImagePlugin .PngImageFile )
448490 assert im .n_frames == 1
449491 assert "duration" not in im .info
450492
@@ -456,6 +498,7 @@ def test_apng_save_duration_loop(tmp_path: Path) -> None:
456498 duration = [500 , 100 , 150 ],
457499 )
458500 with Image .open (test_file ) as im :
501+ assert isinstance (im , PngImagePlugin .PngImageFile )
459502 assert im .n_frames == 2
460503 assert im .info ["duration" ] == 600
461504
@@ -466,6 +509,7 @@ def test_apng_save_duration_loop(tmp_path: Path) -> None:
466509 frame .info ["duration" ] = 300
467510 frame .save (test_file , save_all = True , append_images = [frame , different_frame ])
468511 with Image .open (test_file ) as im :
512+ assert isinstance (im , PngImagePlugin .PngImageFile )
469513 assert im .n_frames == 2
470514 assert im .info ["duration" ] == 600
471515
0 commit comments