mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-12 10:16:17 +03:00
Merge pull request #4927 from radarhere/tuple
This commit is contained in:
commit
309cb9e5c4
|
@ -498,6 +498,12 @@ class TestImage:
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
Image.core.fill("RGB", (2, -2), (0, 0, 0))
|
Image.core.fill("RGB", (2, -2), (0, 0, 0))
|
||||||
|
|
||||||
|
def test_one_item_tuple(self):
|
||||||
|
for mode in ("I", "F", "L"):
|
||||||
|
im = Image.new(mode, (100, 100), (5,))
|
||||||
|
px = im.load()
|
||||||
|
assert px[0, 0] == 5
|
||||||
|
|
||||||
def test_linear_gradient_wrong_mode(self):
|
def test_linear_gradient_wrong_mode(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
wrong_mode = "RGB"
|
wrong_mode = "RGB"
|
||||||
|
|
|
@ -330,21 +330,22 @@ class TestCffi(AccessTest):
|
||||||
class TestImagePutPixelError(AccessTest):
|
class TestImagePutPixelError(AccessTest):
|
||||||
IMAGE_MODES1 = ["L", "LA", "RGB", "RGBA"]
|
IMAGE_MODES1 = ["L", "LA", "RGB", "RGBA"]
|
||||||
IMAGE_MODES2 = ["I", "I;16", "BGR;15"]
|
IMAGE_MODES2 = ["I", "I;16", "BGR;15"]
|
||||||
INVALID_TYPES1 = ["foo", 1.0, None]
|
INVALID_TYPES = ["foo", 1.0, None]
|
||||||
INVALID_TYPES2 = [*INVALID_TYPES1, (10,)]
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("mode", IMAGE_MODES1)
|
@pytest.mark.parametrize("mode", IMAGE_MODES1)
|
||||||
def test_putpixel_type_error1(self, mode):
|
def test_putpixel_type_error1(self, mode):
|
||||||
im = hopper(mode)
|
im = hopper(mode)
|
||||||
for v in self.INVALID_TYPES1:
|
for v in self.INVALID_TYPES:
|
||||||
with pytest.raises(TypeError, match="color must be int or tuple"):
|
with pytest.raises(TypeError, match="color must be int or tuple"):
|
||||||
im.putpixel((0, 0), v)
|
im.putpixel((0, 0), v)
|
||||||
|
|
||||||
@pytest.mark.parametrize("mode", IMAGE_MODES2)
|
@pytest.mark.parametrize("mode", IMAGE_MODES2)
|
||||||
def test_putpixel_type_error2(self, mode):
|
def test_putpixel_type_error2(self, mode):
|
||||||
im = hopper(mode)
|
im = hopper(mode)
|
||||||
for v in self.INVALID_TYPES2:
|
for v in self.INVALID_TYPES:
|
||||||
with pytest.raises(TypeError, match="color must be int"):
|
with pytest.raises(
|
||||||
|
TypeError, match="color must be int or single-element tuple"
|
||||||
|
):
|
||||||
im.putpixel((0, 0), v)
|
im.putpixel((0, 0), v)
|
||||||
|
|
||||||
@pytest.mark.parametrize("mode", IMAGE_MODES1 + IMAGE_MODES2)
|
@pytest.mark.parametrize("mode", IMAGE_MODES1 + IMAGE_MODES2)
|
||||||
|
|
|
@ -518,6 +518,9 @@ getink(PyObject* color, Imaging im, char* ink)
|
||||||
be cast to either UINT8 or INT32 */
|
be cast to either UINT8 or INT32 */
|
||||||
|
|
||||||
int rIsInt = 0;
|
int rIsInt = 0;
|
||||||
|
if (PyTuple_Check(color) && PyTuple_Size(color) == 1) {
|
||||||
|
color = PyTuple_GetItem(color, 0);
|
||||||
|
}
|
||||||
if (im->type == IMAGING_TYPE_UINT8 ||
|
if (im->type == IMAGING_TYPE_UINT8 ||
|
||||||
im->type == IMAGING_TYPE_INT32 ||
|
im->type == IMAGING_TYPE_INT32 ||
|
||||||
im->type == IMAGING_TYPE_SPECIAL) {
|
im->type == IMAGING_TYPE_SPECIAL) {
|
||||||
|
@ -533,7 +536,7 @@ getink(PyObject* color, Imaging im, char* ink)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
PyErr_SetString(PyExc_TypeError, "color must be int");
|
PyErr_SetString(PyExc_TypeError, "color must be int or single-element tuple");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user