@@ -86,18 +86,26 @@ def test_app(self):
86
86
assert len (im .applist ) == 2
87
87
88
88
assert im .info ["comment" ] == b"File written by Adobe Photoshop\xa8 4.0\x00 "
89
+ assert im .app ["COM" ] == im .info ["comment" ]
89
90
90
- def test_com_write (self ):
91
- dummy_text = "this is a test comment"
91
+ def test_comment_write (self ):
92
92
with Image .open (TEST_FILE ) as im :
93
- with BytesIO () as buf :
94
- im .save (buf , format = "JPEG" )
95
- with Image .open (buf ) as im2 :
96
- assert im .app ["COM" ] == im2 .app ["COM" ]
97
- with BytesIO () as buf :
98
- im .save (buf , format = "JPEG" , comment = dummy_text )
99
- with Image .open (buf ) as im2 :
100
- assert im2 .app ["COM" ].decode () == dummy_text
93
+ assert im .info ["comment" ] == b"File written by Adobe Photoshop\xa8 4.0\x00 "
94
+
95
+ # Test that existing comment is saved by default
96
+ out = BytesIO ()
97
+ im .save (out , format = "JPEG" )
98
+ with Image .open (out ) as reloaded :
99
+ assert im .info ["comment" ] == reloaded .info ["comment" ]
100
+
101
+ # Test that a comment argument overrides the default comment
102
+ for comment in ("Test comment text" , b"Text comment text" ):
103
+ out = BytesIO ()
104
+ im .save (out , format = "JPEG" , comment = comment )
105
+ with Image .open (out ) as reloaded :
106
+ if not isinstance (comment , bytes ):
107
+ comment = comment .encode ()
108
+ assert reloaded .info ["comment" ] == comment
101
109
102
110
def test_cmyk (self ):
103
111
# Test CMYK handling. Thanks to Tim and Charlie for test data,
0 commit comments