diff --git a/Tests/helper.py b/Tests/helper.py index 989215ca4..2db550b02 100644 --- a/Tests/helper.py +++ b/Tests/helper.py @@ -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, diff --git a/Tests/test_image.py b/Tests/test_image.py index c960e84de..92a8732b7 100644 --- a/Tests/test_image.py +++ b/Tests/test_image.py @@ -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()