added unix test for fd leak

This commit is contained in:
wiredfool 2017-01-02 20:56:19 +00:00
parent e4e0e0d2bf
commit 900c5e5bf2

View File

@ -469,6 +469,22 @@ class TestFileTiff(PillowTestCase):
self.assertEqual(b'Dummy value', reloaded.info['icc_profile'])
def test_close_on_load(self):
# same as test_fd_leak, but runs on unixlike os
tmpfile = self.tempfile("temp.tif")
import os
with Image.open("Tests/images/uint16_1_4660.tif") as im:
im.save(tmpfile)
im = Image.open(tmpfile)
fp = im.fp
self.assertFalse(fp.closed)
im.load()
self.assertTrue(fp.closed)
@unittest.skipUnless(sys.platform.startswith('win32'), "Windows only")
class TestFileTiffW32(PillowTestCase):
def test_fd_leak(self):
@ -479,8 +495,11 @@ class TestFileTiffW32(PillowTestCase):
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)