diff --git a/Tests/test_file_cur.py b/Tests/test_file_cur.py index 23055a0ad..1628007ee 100644 --- a/Tests/test_file_cur.py +++ b/Tests/test_file_cur.py @@ -26,6 +26,7 @@ class TestFileCur(PillowTestCase): no_cursors_file = "Tests/images/no_cursors.cur" cur = CurImagePlugin.CurImageFile(TEST_FILE) + cur.fp.close() with open(no_cursors_file, "rb") as cur.fp: self.assertRaises(TypeError, cur._open) diff --git a/Tests/test_file_icns.py b/Tests/test_file_icns.py index b19cf2e4c..5e0f377c4 100644 --- a/Tests/test_file_icns.py +++ b/Tests/test_file_icns.py @@ -17,7 +17,10 @@ class TestFileIcns(PillowTestCase): # Loading this icon by default should result in the largest size # (512x512@2x) being loaded im = Image.open(TEST_FILE) - im.load() + + # Assert that there is no unclosed file warning + self.assert_warning(None, im.load) + self.assertEqual(im.mode, "RGBA") self.assertEqual(im.size, (1024, 1024)) self.assertEqual(im.format, "ICNS") diff --git a/Tests/test_file_png.py b/Tests/test_file_png.py index c958c0b39..ca7d3c039 100644 --- a/Tests/test_file_png.py +++ b/Tests/test_file_png.py @@ -327,7 +327,9 @@ class TestFilePng(PillowTestCase): # Check open/load/verify exception (@PIL150) im = Image.open(TEST_PNG_FILE) - im.verify() + + # Assert that there is no unclosed file warning + self.assert_warning(None, im.verify) im = Image.open(TEST_PNG_FILE) im.load() diff --git a/src/PIL/IcnsImagePlugin.py b/src/PIL/IcnsImagePlugin.py index d156b240f..2ea66675f 100644 --- a/src/PIL/IcnsImagePlugin.py +++ b/src/PIL/IcnsImagePlugin.py @@ -311,6 +311,8 @@ class IcnsImageFile(ImageFile.ImageFile): self.im = im.im self.mode = im.mode self.size = im.size + if self._exclusive_fp: + self.fp.close() self.fp = None self.icns = None self.tile = () diff --git a/src/PIL/PngImagePlugin.py b/src/PIL/PngImagePlugin.py index 15077fceb..b89bd0efc 100644 --- a/src/PIL/PngImagePlugin.py +++ b/src/PIL/PngImagePlugin.py @@ -600,6 +600,8 @@ class PngImageFile(ImageFile.ImageFile): self.png.verify() self.png.close() + if self._exclusive_fp: + self.fp.close() self.fp = None def load_prepare(self):