Skip to content

Commit c42e6ba

Browse files
Merge pull request #1 from radarhere/patch-2
Added test and flush file pointer
2 parents feb3103 + 9125631 commit c42e6ba

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

Tests/test_file_sgi.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ def roundtrip(img):
7373
img.save(out, format="sgi")
7474
assert_image_equal_tofile(img, out)
7575

76+
out = str(tmp_path / "fp.sgi")
77+
with open(out, "wb") as fp:
78+
img.save(fp)
79+
assert_image_equal_tofile(img, out)
80+
81+
assert not fp.closed
82+
7683
for mode in ("L", "RGB", "RGBA"):
7784
roundtrip(hopper(mode))
7885

src/PIL/SgiImagePlugin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ def _save(im, fp, filename):
193193
for channel in im.split():
194194
fp.write(channel.tobytes("raw", rawmode, 0, orientation))
195195

196+
if hasattr(fp, "flush"):
197+
fp.flush()
198+
196199

197200
class SGI16Decoder(ImageFile.PyDecoder):
198201
_pulls_fd = True

0 commit comments

Comments
 (0)