Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions Tests/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,18 @@ def assert_warning(self, warn_class, func, *args, **kwargs):
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,
"Expected no warnings, got %s" %
list(v.category for v in w))
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,
Expand Down
14 changes: 12 additions & 2 deletions Tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,6 @@ def test_remap_palette(self):
im = hopper()
self.assertRaises(ValueError, im.remap_palette, None)


def test__new(self):
from PIL import ImagePalette

Expand All @@ -496,7 +495,8 @@ def _make_new(base_image, im, palette_result=None):
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)

Expand All @@ -505,6 +505,15 @@ def _make_new(base_image, im, palette_result=None):
_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
Expand Down Expand Up @@ -534,5 +543,6 @@ def test_encode_registry_fail(self):
('args',),
extra=('extra',))


if __name__ == '__main__':
unittest.main()
12 changes: 11 additions & 1 deletion Tests/test_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ def test_zero_size(self):

self.assertEqual(im.size, (0, 0))


def test_bool(self):
# https://github.com/python-pillow/Pillow/issues/2044
a = numpy.zeros((10,2), dtype=numpy.bool)
Expand All @@ -221,5 +220,16 @@ def test_bool(self):
im2 = Image.fromarray(a)
self.assertEqual(im2.getdata()[0], 255)

def test_no_resource_warning_for_numpy_array(self):
# https://github.com/python-pillow/Pillow/issues/835
# Arrange
from numpy import array
test_file = 'Tests/images/hopper.png'
im = Image.open(test_file)

# Act/Assert
self.assert_warning(None, lambda: array(im))


if __name__ == '__main__':
unittest.main()