mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-26 01:04:29 +03:00
add tests, fix implementation
This commit is contained in:
parent
04ebc23939
commit
e16ab0ad2e
|
@ -1975,9 +1975,12 @@ class Image(object):
|
|||
"""
|
||||
self.load()
|
||||
|
||||
if isStringType(channel) and len(channel) == 1:
|
||||
if channel in self.im.mode:
|
||||
channel = self.im.mode.index(channel)
|
||||
if isStringType(channel):
|
||||
try:
|
||||
channel = self.getbands().index(channel)
|
||||
except ValueError:
|
||||
raise ValueError(
|
||||
'The image has no channel "{}"'.format(channel))
|
||||
|
||||
return self._new(self.im.getband(channel))
|
||||
|
||||
|
|
|
@ -145,14 +145,28 @@ class TestImage(PillowTestCase):
|
|||
self.assertEqual(im.size[1], orig_size[1] + 2*ymargin)
|
||||
|
||||
def test_getbands(self):
|
||||
# Arrange
|
||||
# Assert
|
||||
self.assertEqual(hopper('RGB').getbands(), ('R', 'G', 'B'))
|
||||
self.assertEqual(hopper('YCbCr').getbands(), ('Y', 'Cb', 'Cr'))
|
||||
|
||||
def test_getchannel_wrong_params(self):
|
||||
im = hopper()
|
||||
|
||||
# Act
|
||||
bands = im.getbands()
|
||||
self.assertRaises(ValueError, im.getchannel, -1)
|
||||
self.assertRaises(ValueError, im.getchannel, 3)
|
||||
self.assertRaises(ValueError, im.getchannel, 'Z')
|
||||
self.assertRaises(ValueError, im.getchannel, '1')
|
||||
|
||||
# Assert
|
||||
self.assertEqual(bands, ('R', 'G', 'B'))
|
||||
def test_getchannel(self):
|
||||
im = hopper('YCbCr')
|
||||
Y, Cb, Cr = im.split()
|
||||
|
||||
self.assert_image_equal(Y, im.getchannel(0))
|
||||
self.assert_image_equal(Y, im.getchannel('Y'))
|
||||
self.assert_image_equal(Cb, im.getchannel(1))
|
||||
self.assert_image_equal(Cb, im.getchannel('Cb'))
|
||||
self.assert_image_equal(Cr, im.getchannel(2))
|
||||
self.assert_image_equal(Cr, im.getchannel('Cr'))
|
||||
|
||||
def test_getbbox(self):
|
||||
# Arrange
|
||||
|
|
Loading…
Reference in New Issue
Block a user