From e8122600f6171d7786b011433e7fbbeae793d8ca Mon Sep 17 00:00:00 2001 From: Marcus Brinkmann Date: Fri, 4 Nov 2016 17:09:30 +0100 Subject: [PATCH] Test for: Close file handle in TiffImagePlugin when image is closed. --- Tests/test_file_tiff.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Tests/test_file_tiff.py b/Tests/test_file_tiff.py index cf00551ba..9fefec633 100644 --- a/Tests/test_file_tiff.py +++ b/Tests/test_file_tiff.py @@ -1,6 +1,7 @@ import logging from io import BytesIO import struct +import sys from helper import unittest, PillowTestCase, hopper, py3 @@ -468,6 +469,21 @@ class TestFileTiff(PillowTestCase): self.assertEqual(b'Dummy value', reloaded.info['icc_profile']) +@unittest.skipUnless(sys.platform.startswith('win32'), "Windows only") +class TestFileTiffW32(PillowTestCase): + def test_fd_leak(self): + 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) + im.load() + self.assertRaises(Exception, lambda: os.remove(tmpfile)) + + im.close() + os.remove(tmpfile) if __name__ == '__main__': unittest.main()