0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-12-01 11:41:20 +01:00

Added test that image is closed on exception

This was an actual bug but forgot to add a regression test for it earlier
This commit is contained in:
Karl Hobley 2015-05-06 13:16:15 +01:00
parent 6ae8213e05
commit 62c0021843

View File

@ -238,6 +238,17 @@ class TestGetWillowImage(TestCase):
self.assertTrue(self.image.file.closed)
def test_closes_image_on_exception(self):
# This tests that willow closes images when the with is exited with an exception
try:
with self.image.get_willow_image():
self.assertFalse(self.image.file.closed)
raise ValueError("Something went wrong!")
except ValueError:
pass
self.assertTrue(self.image.file.closed)
def test_doesnt_close_open_image(self):
# This tests that when the image file is already open, get_willow_image doesn't close it (#1256)
self.image.file.open('rb')