1- import io
21import re
32import sys
43import warnings
4+ from io import BytesIO
55
66import pytest
77
@@ -102,10 +102,10 @@ def test_write_rgb(self, tmp_path):
102102 def test_write_method (self , tmp_path ):
103103 self ._roundtrip (tmp_path , self .rgb_mode , 12.0 , {"method" : 6 })
104104
105- buffer_no_args = io . BytesIO ()
105+ buffer_no_args = BytesIO ()
106106 hopper ().save (buffer_no_args , format = "WEBP" )
107107
108- buffer_method = io . BytesIO ()
108+ buffer_method = BytesIO ()
109109 hopper ().save (buffer_method , format = "WEBP" , method = 6 )
110110 assert buffer_no_args .getbuffer () != buffer_method .getbuffer ()
111111
@@ -122,6 +122,30 @@ def test_save_all(self, tmp_path):
122122 reloaded .seek (1 )
123123 assert_image_similar (im2 , reloaded , 1 )
124124
125+ @skip_unless_feature ("webp_anim" )
126+ def test_save_all_progress (self ):
127+ out = BytesIO ()
128+ progress = []
129+
130+ def callback (filename , frame_number , n_frames ):
131+ progress .append ((filename , frame_number , n_frames ))
132+
133+ Image .new ("RGB" , (1 , 1 )).save (out , "WEBP" , save_all = True , progress = callback )
134+ assert progress == [(None , 1 , 1 )]
135+
136+ out = BytesIO ()
137+ progress = []
138+
139+ with Image .open ("Tests/images/iss634.webp" ) as im :
140+ im2 = Image .new ("RGB" , im .size )
141+ im .save (out , "WEBP" , save_all = True , append_images = [im2 ], progress = callback )
142+
143+ expected = []
144+ for i in range (42 ):
145+ expected .append (("Tests/images/iss634.webp" , i + 1 , 43 ))
146+ expected .append ((None , 43 , 43 ))
147+ assert progress == expected
148+
125149 def test_icc_profile (self , tmp_path ):
126150 self ._roundtrip (tmp_path , self .rgb_mode , 12.5 , {"icc_profile" : None })
127151 if _webp .HAVE_WEBPANIM :
0 commit comments