mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 17:36:18 +03:00
Do not try to close fp if fp is empty
This commit is contained in:
parent
cb79b1fa89
commit
14af7bb5ac
|
@ -1,3 +1,4 @@
|
|||
import logging
|
||||
import os
|
||||
|
||||
import pytest
|
||||
|
@ -23,6 +24,14 @@ def test_close():
|
|||
im.getpixel((0, 0))
|
||||
|
||||
|
||||
def test_close_after_load(caplog):
|
||||
im = Image.open("Tests/images/hopper.gif")
|
||||
im.load()
|
||||
with caplog.at_level(logging.DEBUG):
|
||||
im.close()
|
||||
assert len(caplog.records) == 0
|
||||
|
||||
|
||||
def test_contextmanager():
|
||||
fn = None
|
||||
with Image.open("Tests/images/hopper.gif") as im:
|
||||
|
|
|
@ -594,6 +594,7 @@ class Image:
|
|||
try:
|
||||
if hasattr(self, "_close__fp"):
|
||||
self._close__fp()
|
||||
if self.fp:
|
||||
self.fp.close()
|
||||
self.fp = None
|
||||
except Exception as msg:
|
||||
|
|
Loading…
Reference in New Issue
Block a user