mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-03-03 19:45:56 +03:00
Merge pull request #4823 from radarhere/close
Do not try to close file pointer if file pointer is empty
This commit is contained in:
commit
27d34d2f13
|
@ -1,3 +1,4 @@
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -23,6 +24,14 @@ def test_close():
|
||||||
im.getpixel((0, 0))
|
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():
|
def test_contextmanager():
|
||||||
fn = None
|
fn = None
|
||||||
with Image.open("Tests/images/hopper.gif") as im:
|
with Image.open("Tests/images/hopper.gif") as im:
|
||||||
|
|
|
@ -594,6 +594,7 @@ class Image:
|
||||||
try:
|
try:
|
||||||
if hasattr(self, "_close__fp"):
|
if hasattr(self, "_close__fp"):
|
||||||
self._close__fp()
|
self._close__fp()
|
||||||
|
if self.fp:
|
||||||
self.fp.close()
|
self.fp.close()
|
||||||
self.fp = None
|
self.fp = None
|
||||||
except Exception as msg:
|
except Exception as msg:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user