@@ -303,11 +303,11 @@ def test_apng_chunk_errors() -> None:
303303 assert isinstance (im , PngImagePlugin .PngImageFile )
304304 assert not im .is_animated
305305
306- with pytest .warns (UserWarning ):
307- with Image .open ("Tests/images/apng/chunk_multi_actl.png" ) as im :
308- im . load ( )
309- assert isinstance ( im , PngImagePlugin . PngImageFile )
310- assert not im .is_animated
306+ with pytest .warns (UserWarning , match = "Invalid APNG" ):
307+ im = Image .open ("Tests/images/apng/chunk_multi_actl.png" )
308+ assert isinstance ( im , PngImagePlugin . PngImageFile )
309+ assert not im . is_animated
310+ im .close ()
311311
312312 with Image .open ("Tests/images/apng/chunk_actl_after_idat.png" ) as im :
313313 assert isinstance (im , PngImagePlugin .PngImageFile )
@@ -330,18 +330,20 @@ def test_apng_chunk_errors() -> None:
330330
331331
332332def test_apng_syntax_errors () -> None :
333- with pytest .warns (UserWarning ):
334- with Image .open ("Tests/images/apng/syntax_num_frames_zero.png" ) as im :
335- assert isinstance (im , PngImagePlugin .PngImageFile )
336- assert not im .is_animated
337- with pytest .raises (OSError ):
338- im .load ()
333+ with pytest .warns (UserWarning , match = "Invalid APNG" ):
334+ im = Image .open ("Tests/images/apng/syntax_num_frames_zero.png" )
335+ assert isinstance (im , PngImagePlugin .PngImageFile )
336+ assert not im .is_animated
337+ with pytest .raises (OSError ):
338+ im .load ()
339+ im .close ()
339340
340- with pytest .warns (UserWarning ):
341- with Image .open ("Tests/images/apng/syntax_num_frames_zero_default.png" ) as im :
342- assert isinstance (im , PngImagePlugin .PngImageFile )
343- assert not im .is_animated
344- im .load ()
341+ with pytest .warns (UserWarning , match = "Invalid APNG" ):
342+ im = Image .open ("Tests/images/apng/syntax_num_frames_zero_default.png" )
343+ assert isinstance (im , PngImagePlugin .PngImageFile )
344+ assert not im .is_animated
345+ im .load ()
346+ im .close ()
345347
346348 # we can handle this case gracefully
347349 with Image .open ("Tests/images/apng/syntax_num_frames_low.png" ) as im :
@@ -354,11 +356,12 @@ def test_apng_syntax_errors() -> None:
354356 im .seek (im .n_frames - 1 )
355357 im .load ()
356358
357- with pytest .warns (UserWarning ):
358- with Image .open ("Tests/images/apng/syntax_num_frames_invalid.png" ) as im :
359- assert isinstance (im , PngImagePlugin .PngImageFile )
360- assert not im .is_animated
361- im .load ()
359+ with pytest .warns (UserWarning , match = "Invalid APNG" ):
360+ im = Image .open ("Tests/images/apng/syntax_num_frames_invalid.png" )
361+ assert isinstance (im , PngImagePlugin .PngImageFile )
362+ assert not im .is_animated
363+ im .load ()
364+ im .close ()
362365
363366
364367@pytest .mark .parametrize (
0 commit comments