mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-11 17:56:18 +03:00
open file check for windows, on jpeg where we don't mmap the file
This commit is contained in:
parent
86c1704646
commit
db338ca19a
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue
Block a user