@@ -837,22 +837,6 @@ def test_read_multiple_comment_blocks():
837
837
assert im .info ["comment" ] == b"Test comment 1\n Test comment 2"
838
838
839
839
840
- def test_write_comment (tmp_path ):
841
- out = str (tmp_path / "temp.gif" )
842
- with Image .open ("Tests/images/dispose_prev.gif" ) as im :
843
- im .save (out , save_all = True , comment = "Test" )
844
- with Image .open (out ) as reread :
845
- # Comments written should appear only in first frame
846
- assert reread .info ["comment" ] == b"Test"
847
- for i , frame in enumerate (ImageSequence .Iterator (reread )):
848
- assert (
849
- i == 0
850
- and frame .info ["comment" ] == b"Test"
851
- or i != 0
852
- and "comment" not in frame .info
853
- )
854
-
855
-
856
840
def test_empty_string_comment (tmp_path ):
857
841
out = str (tmp_path / "temp.gif" )
858
842
with Image .open ("Tests/images/chi.gif" ) as im :
@@ -866,6 +850,37 @@ def test_empty_string_comment(tmp_path):
866
850
assert "comment" not in frame .info
867
851
868
852
853
+ def test_retain_comment_in_subsequent_frames (tmp_path ):
854
+ # Test that a comment block at the beginning is kept
855
+ with Image .open ("Tests/images/chi.gif" ) as im :
856
+ for frame in ImageSequence .Iterator (im ):
857
+ assert frame .info ["comment" ] == b"Created with GIMP"
858
+
859
+ with Image .open ("Tests/images/second_frame_comment.gif" ) as im :
860
+ assert "comment" not in im .info
861
+
862
+ # Test that a comment in the middle is read
863
+ im .seek (1 )
864
+ assert im .info ["comment" ] == b"Comment in the second frame"
865
+
866
+ # Test that it is still present in a later frame
867
+ im .seek (2 )
868
+ assert im .info ["comment" ] == b"Comment in the second frame"
869
+
870
+ # Test that rewinding removes the comment
871
+ im .seek (0 )
872
+ assert "comment" not in im .info
873
+
874
+ # Test that a saved image keeps the comment
875
+ out = str (tmp_path / "temp.gif" )
876
+ with Image .open ("Tests/images/dispose_prev.gif" ) as im :
877
+ im .save (out , save_all = True , comment = "Test" )
878
+
879
+ with Image .open (out ) as reread :
880
+ for frame in ImageSequence .Iterator (reread ):
881
+ assert frame .info ["comment" ] == b"Test"
882
+
883
+
869
884
def test_version (tmp_path ):
870
885
out = str (tmp_path / "temp.gif" )
871
886
0 commit comments