mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-12 18:26:17 +03:00
Split into x and y errors
This commit is contained in:
parent
b84c29a035
commit
a4965a7eaa
|
@ -1504,18 +1504,19 @@ def test_polygon2():
|
|||
assert_image_similar_tofile(im, expected, 1)
|
||||
|
||||
|
||||
def test_incorrectly_ordered_coordinates():
|
||||
@pytest.mark.parametrize("xy", ((1, 1, 0, 1), (1, 1, 1, 0)))
|
||||
def test_incorrectly_ordered_coordinates(xy):
|
||||
im = Image.new("RGB", (W, H))
|
||||
draw = ImageDraw.Draw(im)
|
||||
with pytest.raises(ValueError):
|
||||
draw.arc((1, 1, 0, 0), 10, 260)
|
||||
draw.arc(xy, 10, 260)
|
||||
with pytest.raises(ValueError):
|
||||
draw.chord((1, 1, 0, 0), 10, 260)
|
||||
draw.chord(xy, 10, 260)
|
||||
with pytest.raises(ValueError):
|
||||
draw.ellipse((1, 1, 0, 0))
|
||||
draw.ellipse(xy)
|
||||
with pytest.raises(ValueError):
|
||||
draw.pieslice((1, 1, 0, 0), 10, 260)
|
||||
draw.pieslice(xy, 10, 260)
|
||||
with pytest.raises(ValueError):
|
||||
draw.rectangle((1, 1, 0, 0))
|
||||
draw.rectangle(xy)
|
||||
with pytest.raises(ValueError):
|
||||
draw.rounded_rectangle((1, 1, 0, 0))
|
||||
draw.rounded_rectangle(xy)
|
||||
|
|
|
@ -303,11 +303,11 @@ class ImageDraw:
|
|||
(x0, y0), (x1, y1) = xy
|
||||
else:
|
||||
x0, y0, x1, y1 = xy
|
||||
if x1 < x0 or y1 < y0:
|
||||
msg = (
|
||||
"x1 must be greater than or equal to x0,"
|
||||
" and y1 must be greater than or equal to y0"
|
||||
)
|
||||
if x1 < x0:
|
||||
msg = "x1 must be greater than or equal to x0"
|
||||
raise ValueError(msg)
|
||||
if y1 < y0:
|
||||
msg = "y1 must be greater than or equal to y0"
|
||||
raise ValueError(msg)
|
||||
if corners is None:
|
||||
corners = (True, True, True, True)
|
||||
|
|
|
@ -251,8 +251,10 @@ PyImaging_GetBuffer(PyObject *buffer, Py_buffer *view) {
|
|||
static const char *must_be_sequence = "argument must be a sequence";
|
||||
static const char *must_be_two_coordinates =
|
||||
"coordinate list must contain exactly 2 coordinates";
|
||||
static const char *incorrectly_ordered_coordinates =
|
||||
"x1 must be greater than or equal to x0, and y1 must be greater than or equal to y0";
|
||||
static const char *incorrectly_ordered_x_coordinate =
|
||||
"x1 must be greater than or equal to x0";
|
||||
static const char *incorrectly_ordered_y_coordinate =
|
||||
"y1 must be greater than or equal to y0";
|
||||
static const char *wrong_mode = "unrecognized image mode";
|
||||
static const char *wrong_raw_mode = "unrecognized raw mode";
|
||||
static const char *outside_image = "image index out of range";
|
||||
|
@ -2807,8 +2809,13 @@ _draw_arc(ImagingDrawObject *self, PyObject *args) {
|
|||
free(xy);
|
||||
return NULL;
|
||||
}
|
||||
if (xy[2] < xy[0] || xy[3] < xy[1]) {
|
||||
PyErr_SetString(PyExc_ValueError, incorrectly_ordered_coordinates);
|
||||
if (xy[2] < xy[0]) {
|
||||
PyErr_SetString(PyExc_ValueError, incorrectly_ordered_x_coordinate);
|
||||
free(xy);
|
||||
return NULL;
|
||||
}
|
||||
if (xy[3] < xy[1]) {
|
||||
PyErr_SetString(PyExc_ValueError, incorrectly_ordered_y_coordinate);
|
||||
free(xy);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -2893,8 +2900,13 @@ _draw_chord(ImagingDrawObject *self, PyObject *args) {
|
|||
free(xy);
|
||||
return NULL;
|
||||
}
|
||||
if (xy[2] < xy[0] || xy[3] < xy[1]) {
|
||||
PyErr_SetString(PyExc_ValueError, incorrectly_ordered_coordinates);
|
||||
if (xy[2] < xy[0]) {
|
||||
PyErr_SetString(PyExc_ValueError, incorrectly_ordered_x_coordinate);
|
||||
free(xy);
|
||||
return NULL;
|
||||
}
|
||||
if (xy[3] < xy[1]) {
|
||||
PyErr_SetString(PyExc_ValueError, incorrectly_ordered_y_coordinate);
|
||||
free(xy);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -2944,8 +2956,13 @@ _draw_ellipse(ImagingDrawObject *self, PyObject *args) {
|
|||
free(xy);
|
||||
return NULL;
|
||||
}
|
||||
if (xy[2] < xy[0] || xy[3] < xy[1]) {
|
||||
PyErr_SetString(PyExc_ValueError, incorrectly_ordered_coordinates);
|
||||
if (xy[2] < xy[0]) {
|
||||
PyErr_SetString(PyExc_ValueError, incorrectly_ordered_x_coordinate);
|
||||
free(xy);
|
||||
return NULL;
|
||||
}
|
||||
if (xy[3] < xy[1]) {
|
||||
PyErr_SetString(PyExc_ValueError, incorrectly_ordered_y_coordinate);
|
||||
free(xy);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -3118,8 +3135,13 @@ _draw_pieslice(ImagingDrawObject *self, PyObject *args) {
|
|||
free(xy);
|
||||
return NULL;
|
||||
}
|
||||
if (xy[2] < xy[0] || xy[3] < xy[1]) {
|
||||
PyErr_SetString(PyExc_ValueError, incorrectly_ordered_coordinates);
|
||||
if (xy[2] < xy[0]) {
|
||||
PyErr_SetString(PyExc_ValueError, incorrectly_ordered_x_coordinate);
|
||||
free(xy);
|
||||
return NULL;
|
||||
}
|
||||
if (xy[3] < xy[1]) {
|
||||
PyErr_SetString(PyExc_ValueError, incorrectly_ordered_y_coordinate);
|
||||
free(xy);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -3219,8 +3241,13 @@ _draw_rectangle(ImagingDrawObject *self, PyObject *args) {
|
|||
free(xy);
|
||||
return NULL;
|
||||
}
|
||||
if (xy[2] < xy[0] || xy[3] < xy[1]) {
|
||||
PyErr_SetString(PyExc_ValueError, incorrectly_ordered_coordinates);
|
||||
if (xy[2] < xy[0]) {
|
||||
PyErr_SetString(PyExc_ValueError, incorrectly_ordered_x_coordinate);
|
||||
free(xy);
|
||||
return NULL;
|
||||
}
|
||||
if (xy[3] < xy[1]) {
|
||||
PyErr_SetString(PyExc_ValueError, incorrectly_ordered_y_coordinate);
|
||||
free(xy);
|
||||
return NULL;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user