mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-24 17:06:16 +03:00
Merge pull request #7005 from radarhere/unclosed_file
This commit is contained in:
commit
be244b5070
|
@ -56,6 +56,7 @@ def test_handler(tmp_path):
|
|||
|
||||
def load(self, im):
|
||||
self.loaded = True
|
||||
im.fp.close()
|
||||
return Image.new("RGB", (1, 1))
|
||||
|
||||
def save(self, im, fp, filename):
|
||||
|
|
|
@ -60,6 +60,7 @@ def test_stub_deprecated():
|
|||
|
||||
def load(self, im):
|
||||
self.loaded = True
|
||||
im.fp.close()
|
||||
return Image.new("RGB", (1, 1))
|
||||
|
||||
handler = Handler()
|
||||
|
|
|
@ -18,6 +18,16 @@ def test_sanity():
|
|||
assert_image_equal_tofile(im, "Tests/images/input_bw_one_band.png")
|
||||
|
||||
|
||||
def test_close():
|
||||
with Image.open("Tests/images/input_bw_one_band.fpx") as im:
|
||||
pass
|
||||
assert im.ole.fp.closed
|
||||
|
||||
im = Image.open("Tests/images/input_bw_one_band.fpx")
|
||||
im.close()
|
||||
assert im.ole.fp.closed
|
||||
|
||||
|
||||
def test_invalid_file():
|
||||
# Test an invalid OLE file
|
||||
invalid_file = "Tests/images/flower.jpg"
|
||||
|
|
|
@ -56,6 +56,7 @@ def test_handler(tmp_path):
|
|||
|
||||
def load(self, im):
|
||||
self.loaded = True
|
||||
im.fp.close()
|
||||
return Image.new("RGB", (1, 1))
|
||||
|
||||
def save(self, im, fp, filename):
|
||||
|
|
|
@ -57,6 +57,7 @@ def test_handler(tmp_path):
|
|||
|
||||
def load(self, im):
|
||||
self.loaded = True
|
||||
im.fp.close()
|
||||
return Image.new("RGB", (1, 1))
|
||||
|
||||
def save(self, im, fp, filename):
|
||||
|
|
|
@ -51,6 +51,16 @@ def test_seek():
|
|||
assert im.tell() == 0
|
||||
|
||||
|
||||
def test_close():
|
||||
with Image.open(TEST_FILE) as im:
|
||||
pass
|
||||
assert im.ole.fp.closed
|
||||
|
||||
im = Image.open(TEST_FILE)
|
||||
im.close()
|
||||
assert im.ole.fp.closed
|
||||
|
||||
|
||||
def test_invalid_file():
|
||||
# Test an invalid OLE file
|
||||
invalid_file = "Tests/images/flower.jpg"
|
||||
|
|
|
@ -55,8 +55,8 @@ def test_show_without_viewers():
|
|||
viewers = ImageShow._viewers
|
||||
ImageShow._viewers = []
|
||||
|
||||
im = hopper()
|
||||
assert not ImageShow.show(im)
|
||||
with hopper() as im:
|
||||
assert not ImageShow.show(im)
|
||||
|
||||
ImageShow._viewers = viewers
|
||||
|
||||
|
|
|
@ -235,6 +235,14 @@ class FpxImageFile(ImageFile.ImageFile):
|
|||
|
||||
return ImageFile.ImageFile.load(self)
|
||||
|
||||
def close(self):
|
||||
self.ole.close()
|
||||
super().close()
|
||||
|
||||
def __exit__(self, *args):
|
||||
self.ole.close()
|
||||
super().__exit__()
|
||||
|
||||
|
||||
#
|
||||
# --------------------------------------------------------------------
|
||||
|
|
|
@ -89,6 +89,14 @@ class MicImageFile(TiffImagePlugin.TiffImageFile):
|
|||
def tell(self):
|
||||
return self.frame
|
||||
|
||||
def close(self):
|
||||
self.ole.close()
|
||||
super().close()
|
||||
|
||||
def __exit__(self, *args):
|
||||
self.ole.close()
|
||||
super().__exit__()
|
||||
|
||||
|
||||
#
|
||||
# --------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue
Block a user