'get_image_dimensions() called with a filename should closed the file.'

@unittest.skipUnless(Image, 'PIL    not    installed')
def test_closing_of_filenames(self):

    class FileWrapper(object, ):
        _closed = []
        def __init__(self, f):
            self.f = f
        def __getattr__(self, name):
            return getattr(self.f, name)
        def close(self):
            self._closed.append(True)
            self.f.close()
    def catching_open(*args):
        return FileWrapper(open(*args))
    from django.core.files import images
    images.open = catching_open
    try:
        get_image_dimensions(os.path.join(os.path.dirname(__file__), 'test1.png'))
    finally:
        del images.open
    self.assertTrue(FileWrapper._closed)
