@@ -350,7 +350,7 @@ def test_apng_save(tmp_path):
350350 im .load ()
351351 assert not im .is_animated
352352 assert im .n_frames == 1
353- assert im .get_format_mimetype () == "image/apng "
353+ assert im .get_format_mimetype () == "image/png "
354354 assert im .info .get ("default_image" ) is None
355355 assert im .getpixel ((0 , 0 )) == (0 , 255 , 0 , 255 )
356356 assert im .getpixel ((64 , 32 )) == (0 , 255 , 0 , 255 )
@@ -450,26 +450,29 @@ def test_apng_save_duration_loop(tmp_path):
450450 test_file , save_all = True , append_images = [frame , frame ], duration = [500 , 100 , 150 ]
451451 )
452452 with Image .open (test_file ) as im :
453- im .load ()
454453 assert im .n_frames == 1
455- assert im . info . get ( "duration" ) == 750
454+ assert "duration" not in im . info
456455
457- # test info duration
458- frame .info ["duration" ] = 750
459- frame .save (test_file , save_all = True )
456+ different_frame = Image .new ("RGBA" , (128 , 64 ))
457+ frame .save (
458+ test_file ,
459+ save_all = True ,
460+ append_images = [frame , different_frame ],
461+ duration = [500 , 100 , 150 ],
462+ )
460463 with Image .open (test_file ) as im :
461- assert im .info . get ( "duration" ) == 750
462-
464+ assert im .n_frames == 2
465+ assert im . info [ "duration" ] == 600
463466
464- def test_apng_save_duplicate_duration (tmp_path ):
465- test_file = str (tmp_path / "temp.png" )
466- frame = Image .new ("RGB" , (1 , 1 ))
467+ im .seek (1 )
468+ assert im .info ["duration" ] == 150
467469
468- # Test a single duration is correctly combined across duplicate frames
469- frame .save (test_file , save_all = True , append_images = [frame , frame ], duration = 500 )
470+ # test info duration
471+ frame .info ["duration" ] = 300
472+ frame .save (test_file , save_all = True , append_images = [frame , different_frame ])
470473 with Image .open (test_file ) as im :
471- assert im .n_frames == 1
472- assert im .info . get ( "duration" ) == 1500
474+ assert im .n_frames == 2
475+ assert im .info [ "duration" ] == 600
473476
474477
475478def test_apng_save_disposal (tmp_path ):
@@ -674,15 +677,16 @@ def test_seek_after_close():
674677
675678@pytest .mark .parametrize ("mode" , ("RGBA" , "RGB" , "P" ))
676679@pytest .mark .parametrize ("default_image" , (True , False ))
677- def test_different_modes_in_later_frames (mode , default_image , tmp_path ):
680+ @pytest .mark .parametrize ("duplicate" , (True , False ))
681+ def test_different_modes_in_later_frames (mode , default_image , duplicate , tmp_path ):
678682 test_file = str (tmp_path / "temp.png" )
679683
680684 im = Image .new ("L" , (1 , 1 ))
681685 im .save (
682686 test_file ,
683687 save_all = True ,
684688 default_image = default_image ,
685- append_images = [Image .new (mode , (1 , 1 ))],
689+ append_images = [im . convert ( mode ) if duplicate else Image .new (mode , (1 , 1 ), 1 )],
686690 )
687691 with Image .open (test_file ) as reloaded :
688692 assert reloaded .mode == mode
0 commit comments