From db338ca19a122afc4937bf76d805562ee86533ed Mon Sep 17 00:00:00 2001 From: wiredfool Date: Sat, 1 Apr 2017 17:18:38 +0100 Subject: [PATCH] open file check for windows, on jpeg where we don't mmap the file --- Tests/test_file_jpeg.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Tests/test_file_jpeg.py b/Tests/test_file_jpeg.py index f90a29162..6679ec9af 100644 --- a/Tests/test_file_jpeg.py +++ b/Tests/test_file_jpeg.py @@ -3,6 +3,7 @@ from helper import djpeg_available, cjpeg_available from io import BytesIO import os +import sys from PIL import Image from PIL import ImageFile @@ -501,5 +502,27 @@ class TestFileJpeg(PillowTestCase): self.assertEqual(im.info['dpi'], reloaded.info['dpi']) +@unittest.skipUnless(sys.platform.startswith('win32'), "Windows only") +class TestFileCloseW32(PillowTestCase): + def setUp(self): + if "jpeg_encoder" not in codecs or "jpeg_decoder" not in codecs: + self.skipTest("jpeg support not available") + + def test_fd_leak(self): + tmpfile = self.tempfile("temp.jpg") + import os + + with Image.open("Tests/images/hopper.jpg") as im: + im.save(tmpfile) + + im = Image.open(tmpfile) + fp = im.fp + self.assertFalse(fp.closed) + self.assertRaises(Exception, lambda: os.remove(tmpfile)) + im.load() + self.assertTrue(fp.closed) + # this should not fail, as load should have closed the file. + os.remove(tmpfile) + if __name__ == '__main__': unittest.main()