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"
@@ -49,60 +51,71 @@ def test_apng_basic() -> None:
4951)
5052def test_apng_fdat (filename : str ) -> None :
5153 with Image .open (filename ) as im :
54+ assert isinstance (im , PngImagePlugin .PngImageFile )
5255 im .seek (im .n_frames - 1 )
5356 assert im .getpixel ((0 , 0 )) == (0 , 255 , 0 , 255 )
5457 assert im .getpixel ((64 , 32 )) == (0 , 255 , 0 , 255 )
5558
5659
5760def test_apng_dispose () -> None :
5861 with Image .open ("Tests/images/apng/dispose_op_none.png" ) as im :
62+ assert isinstance (im , PngImagePlugin .PngImageFile )
5963 im .seek (im .n_frames - 1 )
6064 assert im .getpixel ((0 , 0 )) == (0 , 255 , 0 , 255 )
6165 assert im .getpixel ((64 , 32 )) == (0 , 255 , 0 , 255 )
6266
6367 with Image .open ("Tests/images/apng/dispose_op_background.png" ) as im :
68+ assert isinstance (im , PngImagePlugin .PngImageFile )
6469 im .seek (im .n_frames - 1 )
6570 assert im .getpixel ((0 , 0 )) == (0 , 0 , 0 , 0 )
6671 assert im .getpixel ((64 , 32 )) == (0 , 0 , 0 , 0 )
6772
6873 with Image .open ("Tests/images/apng/dispose_op_background_final.png" ) as im :
74+ assert isinstance (im , PngImagePlugin .PngImageFile )
6975 im .seek (im .n_frames - 1 )
7076 assert im .getpixel ((0 , 0 )) == (0 , 255 , 0 , 255 )
7177 assert im .getpixel ((64 , 32 )) == (0 , 255 , 0 , 255 )
7278
7379 with Image .open ("Tests/images/apng/dispose_op_previous.png" ) as im :
80+ assert isinstance (im , PngImagePlugin .PngImageFile )
7481 im .seek (im .n_frames - 1 )
7582 assert im .getpixel ((0 , 0 )) == (0 , 255 , 0 , 255 )
7683 assert im .getpixel ((64 , 32 )) == (0 , 255 , 0 , 255 )
7784
7885 with Image .open ("Tests/images/apng/dispose_op_previous_final.png" ) as im :
86+ assert isinstance (im , PngImagePlugin .PngImageFile )
7987 im .seek (im .n_frames - 1 )
8088 assert im .getpixel ((0 , 0 )) == (0 , 255 , 0 , 255 )
8189 assert im .getpixel ((64 , 32 )) == (0 , 255 , 0 , 255 )
8290
8391 with Image .open ("Tests/images/apng/dispose_op_previous_first.png" ) as im :
92+ assert isinstance (im , PngImagePlugin .PngImageFile )
8493 im .seek (im .n_frames - 1 )
8594 assert im .getpixel ((0 , 0 )) == (0 , 0 , 0 , 0 )
8695 assert im .getpixel ((64 , 32 )) == (0 , 0 , 0 , 0 )
8796
8897
8998def test_apng_dispose_region () -> None :
9099 with Image .open ("Tests/images/apng/dispose_op_none_region.png" ) as im :
100+ assert isinstance (im , PngImagePlugin .PngImageFile )
91101 im .seek (im .n_frames - 1 )
92102 assert im .getpixel ((0 , 0 )) == (0 , 255 , 0 , 255 )
93103 assert im .getpixel ((64 , 32 )) == (0 , 255 , 0 , 255 )
94104
95105 with Image .open ("Tests/images/apng/dispose_op_background_before_region.png" ) as im :
106+ assert isinstance (im , PngImagePlugin .PngImageFile )
96107 im .seek (im .n_frames - 1 )
97108 assert im .getpixel ((0 , 0 )) == (0 , 0 , 0 , 0 )
98109 assert im .getpixel ((64 , 32 )) == (0 , 0 , 0 , 0 )
99110
100111 with Image .open ("Tests/images/apng/dispose_op_background_region.png" ) as im :
112+ assert isinstance (im , PngImagePlugin .PngImageFile )
101113 im .seek (im .n_frames - 1 )
102114 assert im .getpixel ((0 , 0 )) == (0 , 0 , 255 , 255 )
103115 assert im .getpixel ((64 , 32 )) == (0 , 0 , 0 , 0 )
104116
105117 with Image .open ("Tests/images/apng/dispose_op_previous_region.png" ) as im :
118+ assert isinstance (im , PngImagePlugin .PngImageFile )
106119 im .seek (im .n_frames - 1 )
107120 assert im .getpixel ((0 , 0 )) == (0 , 255 , 0 , 255 )
108121 assert im .getpixel ((64 , 32 )) == (0 , 255 , 0 , 255 )
@@ -129,6 +142,7 @@ def test_apng_dispose_op_previous_frame() -> None:
129142 # ],
130143 # )
131144 with Image .open ("Tests/images/apng/dispose_op_previous_frame.png" ) as im :
145+ assert isinstance (im , PngImagePlugin .PngImageFile )
132146 im .seek (im .n_frames - 1 )
133147 assert im .getpixel ((0 , 0 )) == (255 , 0 , 0 , 255 )
134148
@@ -142,26 +156,31 @@ def test_apng_dispose_op_background_p_mode() -> None:
142156
143157def test_apng_blend () -> None :
144158 with Image .open ("Tests/images/apng/blend_op_source_solid.png" ) as im :
159+ assert isinstance (im , PngImagePlugin .PngImageFile )
145160 im .seek (im .n_frames - 1 )
146161 assert im .getpixel ((0 , 0 )) == (0 , 255 , 0 , 255 )
147162 assert im .getpixel ((64 , 32 )) == (0 , 255 , 0 , 255 )
148163
149164 with Image .open ("Tests/images/apng/blend_op_source_transparent.png" ) as im :
165+ assert isinstance (im , PngImagePlugin .PngImageFile )
150166 im .seek (im .n_frames - 1 )
151167 assert im .getpixel ((0 , 0 )) == (0 , 0 , 0 , 0 )
152168 assert im .getpixel ((64 , 32 )) == (0 , 0 , 0 , 0 )
153169
154170 with Image .open ("Tests/images/apng/blend_op_source_near_transparent.png" ) as im :
171+ assert isinstance (im , PngImagePlugin .PngImageFile )
155172 im .seek (im .n_frames - 1 )
156173 assert im .getpixel ((0 , 0 )) == (0 , 255 , 0 , 2 )
157174 assert im .getpixel ((64 , 32 )) == (0 , 255 , 0 , 2 )
158175
159176 with Image .open ("Tests/images/apng/blend_op_over.png" ) as im :
177+ assert isinstance (im , PngImagePlugin .PngImageFile )
160178 im .seek (im .n_frames - 1 )
161179 assert im .getpixel ((0 , 0 )) == (0 , 255 , 0 , 255 )
162180 assert im .getpixel ((64 , 32 )) == (0 , 255 , 0 , 255 )
163181
164182 with Image .open ("Tests/images/apng/blend_op_over_near_transparent.png" ) as im :
183+ assert isinstance (im , PngImagePlugin .PngImageFile )
165184 im .seek (im .n_frames - 1 )
166185 assert im .getpixel ((0 , 0 )) == (0 , 255 , 0 , 97 )
167186 assert im .getpixel ((64 , 32 )) == (0 , 255 , 0 , 255 )
@@ -175,6 +194,7 @@ def test_apng_blend_transparency() -> None:
175194
176195def test_apng_chunk_order () -> None :
177196 with Image .open ("Tests/images/apng/fctl_actl.png" ) as im :
197+ assert isinstance (im , PngImagePlugin .PngImageFile )
178198 im .seek (im .n_frames - 1 )
179199 assert im .getpixel ((0 , 0 )) == (0 , 255 , 0 , 255 )
180200 assert im .getpixel ((64 , 32 )) == (0 , 255 , 0 , 255 )
@@ -230,38 +250,44 @@ def test_apng_num_plays() -> None:
230250
231251def test_apng_mode () -> None :
232252 with Image .open ("Tests/images/apng/mode_16bit.png" ) as im :
253+ assert isinstance (im , PngImagePlugin .PngImageFile )
233254 assert im .mode == "RGBA"
234255 im .seek (im .n_frames - 1 )
235256 assert im .getpixel ((0 , 0 )) == (0 , 0 , 128 , 191 )
236257 assert im .getpixel ((64 , 32 )) == (0 , 0 , 128 , 191 )
237258
238259 with Image .open ("Tests/images/apng/mode_grayscale.png" ) as im :
260+ assert isinstance (im , PngImagePlugin .PngImageFile )
239261 assert im .mode == "L"
240262 im .seek (im .n_frames - 1 )
241263 assert im .getpixel ((0 , 0 )) == 128
242264 assert im .getpixel ((64 , 32 )) == 255
243265
244266 with Image .open ("Tests/images/apng/mode_grayscale_alpha.png" ) as im :
267+ assert isinstance (im , PngImagePlugin .PngImageFile )
245268 assert im .mode == "LA"
246269 im .seek (im .n_frames - 1 )
247270 assert im .getpixel ((0 , 0 )) == (128 , 191 )
248271 assert im .getpixel ((64 , 32 )) == (128 , 191 )
249272
250273 with Image .open ("Tests/images/apng/mode_palette.png" ) as im :
274+ assert isinstance (im , PngImagePlugin .PngImageFile )
251275 assert im .mode == "P"
252276 im .seek (im .n_frames - 1 )
253277 im = im .convert ("RGB" )
254278 assert im .getpixel ((0 , 0 )) == (0 , 255 , 0 )
255279 assert im .getpixel ((64 , 32 )) == (0 , 255 , 0 )
256280
257281 with Image .open ("Tests/images/apng/mode_palette_alpha.png" ) as im :
282+ assert isinstance (im , PngImagePlugin .PngImageFile )
258283 assert im .mode == "P"
259284 im .seek (im .n_frames - 1 )
260285 im = im .convert ("RGBA" )
261286 assert im .getpixel ((0 , 0 )) == (0 , 255 , 0 , 255 )
262287 assert im .getpixel ((64 , 32 )) == (0 , 255 , 0 , 255 )
263288
264289 with Image .open ("Tests/images/apng/mode_palette_1bit_alpha.png" ) as im :
290+ assert isinstance (im , PngImagePlugin .PngImageFile )
265291 assert im .mode == "P"
266292 im .seek (im .n_frames - 1 )
267293 im = im .convert ("RGBA" )
@@ -271,44 +297,53 @@ def test_apng_mode() -> None:
271297
272298def test_apng_chunk_errors () -> None :
273299 with Image .open ("Tests/images/apng/chunk_no_actl.png" ) as im :
300+ assert isinstance (im , PngImagePlugin .PngImageFile )
274301 assert not im .is_animated
275302
276303 with pytest .warns (UserWarning ):
277304 with Image .open ("Tests/images/apng/chunk_multi_actl.png" ) as im :
278305 im .load ()
306+ assert isinstance (im , PngImagePlugin .PngImageFile )
279307 assert not im .is_animated
280308
281309 with Image .open ("Tests/images/apng/chunk_actl_after_idat.png" ) as im :
310+ assert isinstance (im , PngImagePlugin .PngImageFile )
282311 assert not im .is_animated
283312
284313 with Image .open ("Tests/images/apng/chunk_no_fctl.png" ) as im :
314+ assert isinstance (im , PngImagePlugin .PngImageFile )
285315 with pytest .raises (SyntaxError ):
286316 im .seek (im .n_frames - 1 )
287317
288318 with Image .open ("Tests/images/apng/chunk_repeat_fctl.png" ) as im :
319+ assert isinstance (im , PngImagePlugin .PngImageFile )
289320 with pytest .raises (SyntaxError ):
290321 im .seek (im .n_frames - 1 )
291322
292323 with Image .open ("Tests/images/apng/chunk_no_fdat.png" ) as im :
324+ assert isinstance (im , PngImagePlugin .PngImageFile )
293325 with pytest .raises (SyntaxError ):
294326 im .seek (im .n_frames - 1 )
295327
296328
297329def test_apng_syntax_errors () -> None :
298330 with pytest .warns (UserWarning ):
299331 with Image .open ("Tests/images/apng/syntax_num_frames_zero.png" ) as im :
332+ assert isinstance (im , PngImagePlugin .PngImageFile )
300333 assert not im .is_animated
301334 with pytest .raises (OSError ):
302335 im .load ()
303336
304337 with pytest .warns (UserWarning ):
305338 with Image .open ("Tests/images/apng/syntax_num_frames_zero_default.png" ) as im :
339+ assert isinstance (im , PngImagePlugin .PngImageFile )
306340 assert not im .is_animated
307341 im .load ()
308342
309343 # we can handle this case gracefully
310344 exception = None
311345 with Image .open ("Tests/images/apng/syntax_num_frames_low.png" ) as im :
346+ assert isinstance (im , PngImagePlugin .PngImageFile )
312347 try :
313348 im .seek (im .n_frames - 1 )
314349 except Exception as e :
@@ -317,11 +352,13 @@ def test_apng_syntax_errors() -> None:
317352
318353 with pytest .raises (OSError ):
319354 with Image .open ("Tests/images/apng/syntax_num_frames_high.png" ) as im :
355+ assert isinstance (im , PngImagePlugin .PngImageFile )
320356 im .seek (im .n_frames - 1 )
321357 im .load ()
322358
323359 with pytest .warns (UserWarning ):
324360 with Image .open ("Tests/images/apng/syntax_num_frames_invalid.png" ) as im :
361+ assert isinstance (im , PngImagePlugin .PngImageFile )
325362 assert not im .is_animated
326363 im .load ()
327364
@@ -341,6 +378,7 @@ def test_apng_syntax_errors() -> None:
341378def test_apng_sequence_errors (test_file : str ) -> None :
342379 with pytest .raises (SyntaxError ):
343380 with Image .open (f"Tests/images/apng/{ test_file } " ) as im :
381+ assert isinstance (im , PngImagePlugin .PngImageFile )
344382 im .seek (im .n_frames - 1 )
345383 im .load ()
346384
@@ -351,6 +389,7 @@ def test_apng_save(tmp_path: Path) -> None:
351389 im .save (test_file , save_all = True )
352390
353391 with Image .open (test_file ) as im :
392+ assert isinstance (im , PngImagePlugin .PngImageFile )
354393 im .load ()
355394 assert not im .is_animated
356395 assert im .n_frames == 1
@@ -366,6 +405,7 @@ def test_apng_save(tmp_path: Path) -> None:
366405 )
367406
368407 with Image .open (test_file ) as im :
408+ assert isinstance (im , PngImagePlugin .PngImageFile )
369409 im .load ()
370410 assert im .is_animated
371411 assert im .n_frames == 2
@@ -405,6 +445,7 @@ def test_apng_save_split_fdat(tmp_path: Path) -> None:
405445 append_images = frames ,
406446 )
407447 with Image .open (test_file ) as im :
448+ assert isinstance (im , PngImagePlugin .PngImageFile )
408449 exception = None
409450 try :
410451 im .seek (im .n_frames - 1 )
@@ -452,6 +493,7 @@ def test_apng_save_duration_loop(tmp_path: Path) -> None:
452493 test_file , save_all = True , append_images = [frame , frame ], duration = [500 , 100 , 150 ]
453494 )
454495 with Image .open (test_file ) as im :
496+ assert isinstance (im , PngImagePlugin .PngImageFile )
455497 assert im .n_frames == 1
456498 assert "duration" not in im .info
457499
@@ -473,6 +515,7 @@ def test_apng_save_duration_loop(tmp_path: Path) -> None:
473515 frame .info ["duration" ] = 300
474516 frame .save (test_file , save_all = True , append_images = [frame , different_frame ])
475517 with Image .open (test_file ) as im :
518+ assert isinstance (im , PngImagePlugin .PngImageFile )
476519 assert im .n_frames == 2
477520 assert im .info ["duration" ] == 600
478521
0 commit comments