open file check for windows, on jpeg where we don't mmap the file

This commit is contained in:
wiredfool 2017-04-01 17:18:38 +01:00
parent 86c1704646
commit db338ca19a

View File

@ -3,6 +3,7 @@ from helper import djpeg_available, cjpeg_available
from io import BytesIO from io import BytesIO
import os import os
import sys
from PIL import Image from PIL import Image
from PIL import ImageFile from PIL import ImageFile
@ -501,5 +502,27 @@ class TestFileJpeg(PillowTestCase):
self.assertEqual(im.info['dpi'], reloaded.info['dpi']) 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__': if __name__ == '__main__':
unittest.main() unittest.main()