mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-04-27 20:43:43 +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)
|
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))
|
im = Image.new("RGB", (W, H))
|
||||||
draw = ImageDraw.Draw(im)
|
draw = ImageDraw.Draw(im)
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
draw.arc((1, 1, 0, 0), 10, 260)
|
draw.arc(xy, 10, 260)
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
draw.chord((1, 1, 0, 0), 10, 260)
|
draw.chord(xy, 10, 260)
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
draw.ellipse((1, 1, 0, 0))
|
draw.ellipse(xy)
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
draw.pieslice((1, 1, 0, 0), 10, 260)
|
draw.pieslice(xy, 10, 260)
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
draw.rectangle((1, 1, 0, 0))
|
draw.rectangle(xy)
|
||||||
with pytest.raises(ValueError):
|
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
|
(x0, y0), (x1, y1) = xy
|
||||||
else:
|
else:
|
||||||
x0, y0, x1, y1 = xy
|
x0, y0, x1, y1 = xy
|
||||||
if x1 < x0 or y1 < y0:
|
if x1 < x0:
|
||||||
msg = (
|
msg = "x1 must be greater than or equal to x0"
|
||||||
"x1 must be greater than or equal to x0,"
|
raise ValueError(msg)
|
||||||
" and y1 must be greater than or equal to y0"
|
if y1 < y0:
|
||||||
)
|
msg = "y1 must be greater than or equal to y0"
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
if corners is None:
|
if corners is None:
|
||||||
corners = (True, True, True, True)
|
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_sequence = "argument must be a sequence";
|
||||||
static const char *must_be_two_coordinates =
|
static const char *must_be_two_coordinates =
|
||||||
"coordinate list must contain exactly 2 coordinates";
|
"coordinate list must contain exactly 2 coordinates";
|
||||||
static const char *incorrectly_ordered_coordinates =
|
static const char *incorrectly_ordered_x_coordinate =
|
||||||
"x1 must be greater than or equal to x0, and y1 must be greater than or equal to y0";
|
"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_mode = "unrecognized image mode";
|
||||||
static const char *wrong_raw_mode = "unrecognized raw mode";
|
static const char *wrong_raw_mode = "unrecognized raw mode";
|
||||||
static const char *outside_image = "image index out of range";
|
static const char *outside_image = "image index out of range";
|
||||||
|
@ -2807,8 +2809,13 @@ _draw_arc(ImagingDrawObject *self, PyObject *args) {
|
||||||
free(xy);
|
free(xy);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (xy[2] < xy[0] || xy[3] < xy[1]) {
|
if (xy[2] < xy[0]) {
|
||||||
PyErr_SetString(PyExc_ValueError, incorrectly_ordered_coordinates);
|
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);
|
free(xy);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -2893,8 +2900,13 @@ _draw_chord(ImagingDrawObject *self, PyObject *args) {
|
||||||
free(xy);
|
free(xy);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (xy[2] < xy[0] || xy[3] < xy[1]) {
|
if (xy[2] < xy[0]) {
|
||||||
PyErr_SetString(PyExc_ValueError, incorrectly_ordered_coordinates);
|
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);
|
free(xy);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -2944,8 +2956,13 @@ _draw_ellipse(ImagingDrawObject *self, PyObject *args) {
|
||||||
free(xy);
|
free(xy);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (xy[2] < xy[0] || xy[3] < xy[1]) {
|
if (xy[2] < xy[0]) {
|
||||||
PyErr_SetString(PyExc_ValueError, incorrectly_ordered_coordinates);
|
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);
|
free(xy);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -3118,8 +3135,13 @@ _draw_pieslice(ImagingDrawObject *self, PyObject *args) {
|
||||||
free(xy);
|
free(xy);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (xy[2] < xy[0] || xy[3] < xy[1]) {
|
if (xy[2] < xy[0]) {
|
||||||
PyErr_SetString(PyExc_ValueError, incorrectly_ordered_coordinates);
|
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);
|
free(xy);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -3219,8 +3241,13 @@ _draw_rectangle(ImagingDrawObject *self, PyObject *args) {
|
||||||
free(xy);
|
free(xy);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (xy[2] < xy[0] || xy[3] < xy[1]) {
|
if (xy[2] < xy[0]) {
|
||||||
PyErr_SetString(PyExc_ValueError, incorrectly_ordered_coordinates);
|
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);
|
free(xy);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user