From c5e111e6b8b9633bce046a988c9f6e49f2358627 Mon Sep 17 00:00:00 2001 From: homm Date: Tue, 4 Oct 2016 03:06:35 +0300 Subject: [PATCH 1/2] allow lists as arguments for Image.new --- PIL/Image.py | 6 +++--- Tests/test_image.py | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/PIL/Image.py b/PIL/Image.py index bbfee34b6..a23a7d92c 100644 --- a/PIL/Image.py +++ b/PIL/Image.py @@ -1020,7 +1020,7 @@ class Image(object): 4-tuple defining the left, upper, right, and lower pixel coordinate. - Note: Prior to Pillow 3.4.0, this was a lazy operation. + Note: Prior to Pillow 3.4.0, this was a lazy operation. :param box: The crop rectangle, as a (left, upper, right, lower)-tuple. :rtype: :py:class:`~PIL.Image.Image` @@ -1993,7 +1993,7 @@ def _check_size(size): :returns: True, or raises a ValueError """ - if not isinstance(size, tuple): + if not isinstance(size, (list, tuple)): raise ValueError("Size must be a tuple") if len(size) != 2: raise ValueError("Size must be a tuple of length 2") @@ -2019,7 +2019,7 @@ def new(mode, size, color=0): """ _check_size(size) - + if color is None: # don't initialize return Image()._new(core.new(mode, size)) diff --git a/Tests/test_image.py b/Tests/test_image.py index 8657bd2e6..ce7c928b9 100644 --- a/Tests/test_image.py +++ b/Tests/test_image.py @@ -238,7 +238,7 @@ class TestImage(PillowTestCase): self.assert_image_similar(im2, im3, 110) def test_check_size(self): - # Checking that the _check_size function throws value errors when we want it to. + # Checking that the _check_size function throws value errors when we want it to. with self.assertRaises(ValueError): Image.new('RGB', 0) # not a tuple with self.assertRaises(ValueError): @@ -247,19 +247,21 @@ class TestImage(PillowTestCase): Image.new('RGB', (0,0)) # w,h <= 0 self.assertTrue(Image.new('RGB', (1,1))) + # Should pass lists too + self.assertTrue(Image.new('RGB', [1,1])) def test_storage_neg(self): # Storage.c accepted negative values for xsize, ysize. Was # test_neg_ppm, but the core function for that has been # removed Calling directly into core to test the error in # Storage.c, rather than the size check above - + with self.assertRaises(ValueError): Image.core.fill('RGB', (2,-2), (0,0,0)) - + if __name__ == '__main__': unittest.main() From 923f0bb9b3fc935c609a72d85372238b55fcca37 Mon Sep 17 00:00:00 2001 From: homm Date: Tue, 4 Oct 2016 03:11:53 +0300 Subject: [PATCH 2/2] improve test --- Tests/test_image.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Tests/test_image.py b/Tests/test_image.py index ce7c928b9..6b24a988b 100644 --- a/Tests/test_image.py +++ b/Tests/test_image.py @@ -248,7 +248,8 @@ class TestImage(PillowTestCase): self.assertTrue(Image.new('RGB', (1,1))) # Should pass lists too - self.assertTrue(Image.new('RGB', [1,1])) + i = Image.new('RGB', [1,1]) + self.assertEqual(type(i.size), tuple) def test_storage_neg(self): # Storage.c accepted negative values for xsize, ysize. Was