Failing test for ResourceWarning on Python 3

This commit is contained in:
hugovk 2014-12-30 16:20:42 +02:00
parent 04c96f6030
commit 77f0608c4e
2 changed files with 22 additions and 9 deletions

View File

@ -121,13 +121,16 @@ class PillowTestCase(unittest.TestCase):
result = func(*args, **kwargs)
# 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,

View File

@ -478,7 +478,6 @@ class TestImage(PillowTestCase):
im = hopper()
self.assertRaises(ValueError, im.remap_palette, None)
def test__new(self):
from PIL import ImagePalette
@ -496,7 +495,8 @@ class TestImage(PillowTestCase):
self.assertEqual(new_im.size, im.size)
self.assertEqual(new_im.info, base_image.info)
if palette_result is not None:
self.assertEqual(new_im.palette.tobytes(), palette_result.tobytes())
self.assertEqual(new_im.palette.tobytes(),
palette_result.tobytes())
else:
self.assertEqual(new_im.palette, None)
@ -505,6 +505,15 @@ class TestImage(PillowTestCase):
_make_new(im, blank_p, ImagePalette.ImagePalette())
_make_new(im, blank_pa, ImagePalette.ImagePalette())
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'))
class MockEncoder(object):
pass
@ -534,5 +543,6 @@ class TestRegistry(PillowTestCase):
('args',),
extra=('extra',))
if __name__ == '__main__':
unittest.main()