From 51d84d68e3954be9e0ced6353ee6d6ff54b56721 Mon Sep 17 00:00:00 2001 From: hugovk Date: Tue, 30 Dec 2014 16:20:42 +0200 Subject: [PATCH] Failing test for ResourceWarning on Python 3 --- Tests/helper.py | 17 ++++++++++------- Tests/test_image.py | 10 ++++++++++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/Tests/helper.py b/Tests/helper.py index 563f42060..79d2d5b81 100644 --- a/Tests/helper.py +++ b/Tests/helper.py @@ -116,13 +116,16 @@ class PillowTestCase(unittest.TestCase): result = func() # Verify some things. - self.assertGreaterEqual(len(w), 1) - found = False - for v in w: - if issubclass(v.category, warn_class): - found = True - break - self.assertTrue(found) + if warn_class is None: + self.assertEqual(len(w), 0) + else: + self.assertGreaterEqual(len(w), 1) + found = False + for v in w: + if issubclass(v.category, warn_class): + found = True + break + self.assertTrue(found) return result def skipKnownBadTest(self, msg=None, platform=None, diff --git a/Tests/test_image.py b/Tests/test_image.py index 26e45b10a..156164f0c 100644 --- a/Tests/test_image.py +++ b/Tests/test_image.py @@ -196,6 +196,16 @@ class TestImage(PillowTestCase): im3 = Image.open('Tests/images/effect_spread.png') self.assert_image_similar(im2, im3, 110) + def test_no_resource_warning_on_save(self): + # https://github.com/python-pillow/Pillow/issues/835 + # Arrange + test_file = 'Tests/images/hopper.png' + + # Act/Assert + with Image.open(test_file) as im: + self.assert_warning(None, lambda: im.save('test_img.jpg')) + + if __name__ == '__main__': unittest.main()