Test lists and tuples

This commit is contained in:
Andrew Murray 2022-12-31 15:42:38 +11:00 committed by Yay295
parent 55d6cf5127
commit b05bc34604
3 changed files with 128 additions and 91 deletions

View File

@ -110,11 +110,13 @@ def test_qtables_leak():
) )
] ]
qtables = [standard_l_qtable, standard_chrominance_qtable] for qtables in (
(standard_l_qtable, standard_chrominance_qtable),
for _ in range(iterations): [standard_l_qtable, standard_chrominance_qtable],
test_output = BytesIO() ):
im.save(test_output, "JPEG", qtables=qtables) for _ in range(iterations):
test_output = BytesIO()
im.save(test_output, "JPEG", qtables=qtables)
def test_exif_leak(): def test_exif_leak():

View File

@ -27,15 +27,21 @@ X1 = int(X0 * 3)
Y0 = int(H / 4) Y0 = int(H / 4)
Y1 = int(X0 * 3) Y1 = int(X0 * 3)
# Two kinds of bounding box # Bounding boxes
BBOX1 = [(X0, Y0), (X1, Y1)] BBOX = (((X0, Y0), (X1, Y1)), [(X0, Y0), (X1, Y1)], (X0, Y0, X1, Y1), [X0, Y0, X1, Y1])
BBOX2 = [X0, Y0, X1, Y1]
# Two kinds of coordinate sequences # Coordinate sequences
POINTS1 = [(10, 10), (20, 40), (30, 30)] POINTS = (
POINTS2 = [10, 10, 20, 40, 30, 30] ((10, 10), (20, 40), (30, 30)),
[(10, 10), (20, 40), (30, 30)],
(10, 10, 20, 40, 30, 30),
[10, 10, 20, 40, 30, 30],
)
KITE_POINTS = [(10, 50), (70, 10), (90, 50), (70, 90), (10, 50)] KITE_POINTS = (
((10, 50), (70, 10), (90, 50), (70, 90), (10, 50)),
[(10, 50), (70, 10), (90, 50), (70, 90), (10, 50)],
)
def test_sanity(): def test_sanity():
@ -63,7 +69,7 @@ def test_mode_mismatch():
ImageDraw.ImageDraw(im, mode="L") ImageDraw.ImageDraw(im, mode="L")
@pytest.mark.parametrize("bbox", (BBOX1, BBOX2)) @pytest.mark.parametrize("bbox", BBOX)
@pytest.mark.parametrize("start, end", ((0, 180), (0.5, 180.4))) @pytest.mark.parametrize("start, end", ((0, 180), (0.5, 180.4)))
def test_arc(bbox, start, end): def test_arc(bbox, start, end):
# Arrange # Arrange
@ -77,7 +83,8 @@ def test_arc(bbox, start, end):
assert_image_similar_tofile(im, "Tests/images/imagedraw_arc.png", 1) assert_image_similar_tofile(im, "Tests/images/imagedraw_arc.png", 1)
def test_arc_end_le_start(): @pytest.mark.parametrize("bbox", BBOX)
def test_arc_end_le_start(bbox):
# Arrange # Arrange
im = Image.new("RGB", (W, H)) im = Image.new("RGB", (W, H))
draw = ImageDraw.Draw(im) draw = ImageDraw.Draw(im)
@ -85,13 +92,14 @@ def test_arc_end_le_start():
end = 0 end = 0
# Act # Act
draw.arc(BBOX1, start=start, end=end) draw.arc(bbox, start=start, end=end)
# Assert # Assert
assert_image_equal_tofile(im, "Tests/images/imagedraw_arc_end_le_start.png") assert_image_equal_tofile(im, "Tests/images/imagedraw_arc_end_le_start.png")
def test_arc_no_loops(): @pytest.mark.parametrize("bbox", BBOX)
def test_arc_no_loops(bbox):
# No need to go in loops # No need to go in loops
# Arrange # Arrange
im = Image.new("RGB", (W, H)) im = Image.new("RGB", (W, H))
@ -100,57 +108,61 @@ def test_arc_no_loops():
end = 370 end = 370
# Act # Act
draw.arc(BBOX1, start=start, end=end) draw.arc(bbox, start=start, end=end)
# Assert # Assert
assert_image_similar_tofile(im, "Tests/images/imagedraw_arc_no_loops.png", 1) assert_image_similar_tofile(im, "Tests/images/imagedraw_arc_no_loops.png", 1)
def test_arc_width(): @pytest.mark.parametrize("bbox", BBOX)
def test_arc_width(bbox):
# Arrange # Arrange
im = Image.new("RGB", (W, H)) im = Image.new("RGB", (W, H))
draw = ImageDraw.Draw(im) draw = ImageDraw.Draw(im)
# Act # Act
draw.arc(BBOX1, 10, 260, width=5) draw.arc(bbox, 10, 260, width=5)
# Assert # Assert
assert_image_similar_tofile(im, "Tests/images/imagedraw_arc_width.png", 1) assert_image_similar_tofile(im, "Tests/images/imagedraw_arc_width.png", 1)
def test_arc_width_pieslice_large(): @pytest.mark.parametrize("bbox", BBOX)
def test_arc_width_pieslice_large(bbox):
# Tests an arc with a large enough width that it is a pieslice # Tests an arc with a large enough width that it is a pieslice
# Arrange # Arrange
im = Image.new("RGB", (W, H)) im = Image.new("RGB", (W, H))
draw = ImageDraw.Draw(im) draw = ImageDraw.Draw(im)
# Act # Act
draw.arc(BBOX1, 10, 260, fill="yellow", width=100) draw.arc(bbox, 10, 260, fill="yellow", width=100)
# Assert # Assert
assert_image_similar_tofile(im, "Tests/images/imagedraw_arc_width_pieslice.png", 1) assert_image_similar_tofile(im, "Tests/images/imagedraw_arc_width_pieslice.png", 1)
def test_arc_width_fill(): @pytest.mark.parametrize("bbox", BBOX)
def test_arc_width_fill(bbox):
# Arrange # Arrange
im = Image.new("RGB", (W, H)) im = Image.new("RGB", (W, H))
draw = ImageDraw.Draw(im) draw = ImageDraw.Draw(im)
# Act # Act
draw.arc(BBOX1, 10, 260, fill="yellow", width=5) draw.arc(bbox, 10, 260, fill="yellow", width=5)
# Assert # Assert
assert_image_similar_tofile(im, "Tests/images/imagedraw_arc_width_fill.png", 1) assert_image_similar_tofile(im, "Tests/images/imagedraw_arc_width_fill.png", 1)
def test_arc_width_non_whole_angle(): @pytest.mark.parametrize("bbox", BBOX)
def test_arc_width_non_whole_angle(bbox):
# Arrange # Arrange
im = Image.new("RGB", (W, H)) im = Image.new("RGB", (W, H))
draw = ImageDraw.Draw(im) draw = ImageDraw.Draw(im)
expected = "Tests/images/imagedraw_arc_width_non_whole_angle.png" expected = "Tests/images/imagedraw_arc_width_non_whole_angle.png"
# Act # Act
draw.arc(BBOX1, 10, 259.5, width=5) draw.arc(bbox, 10, 259.5, width=5)
# Assert # Assert
assert_image_similar_tofile(im, expected, 1) assert_image_similar_tofile(im, expected, 1)
@ -184,7 +196,7 @@ def test_bitmap():
@pytest.mark.parametrize("mode", ("RGB", "L")) @pytest.mark.parametrize("mode", ("RGB", "L"))
@pytest.mark.parametrize("bbox", (BBOX1, BBOX2)) @pytest.mark.parametrize("bbox", BBOX)
def test_chord(mode, bbox): def test_chord(mode, bbox):
# Arrange # Arrange
im = Image.new(mode, (W, H)) im = Image.new(mode, (W, H))
@ -198,37 +210,40 @@ def test_chord(mode, bbox):
assert_image_similar_tofile(im, expected, 1) assert_image_similar_tofile(im, expected, 1)
def test_chord_width(): @pytest.mark.parametrize("bbox", BBOX)
def test_chord_width(bbox):
# Arrange # Arrange
im = Image.new("RGB", (W, H)) im = Image.new("RGB", (W, H))
draw = ImageDraw.Draw(im) draw = ImageDraw.Draw(im)
# Act # Act
draw.chord(BBOX1, 10, 260, outline="yellow", width=5) draw.chord(bbox, 10, 260, outline="yellow", width=5)
# Assert # Assert
assert_image_similar_tofile(im, "Tests/images/imagedraw_chord_width.png", 1) assert_image_similar_tofile(im, "Tests/images/imagedraw_chord_width.png", 1)
def test_chord_width_fill(): @pytest.mark.parametrize("bbox", BBOX)
def test_chord_width_fill(bbox):
# Arrange # Arrange
im = Image.new("RGB", (W, H)) im = Image.new("RGB", (W, H))
draw = ImageDraw.Draw(im) draw = ImageDraw.Draw(im)
# Act # Act
draw.chord(BBOX1, 10, 260, fill="red", outline="yellow", width=5) draw.chord(bbox, 10, 260, fill="red", outline="yellow", width=5)
# Assert # Assert
assert_image_similar_tofile(im, "Tests/images/imagedraw_chord_width_fill.png", 1) assert_image_similar_tofile(im, "Tests/images/imagedraw_chord_width_fill.png", 1)
def test_chord_zero_width(): @pytest.mark.parametrize("bbox", BBOX)
def test_chord_zero_width(bbox):
# Arrange # Arrange
im = Image.new("RGB", (W, H)) im = Image.new("RGB", (W, H))
draw = ImageDraw.Draw(im) draw = ImageDraw.Draw(im)
# Act # Act
draw.chord(BBOX1, 10, 260, fill="red", outline="yellow", width=0) draw.chord(bbox, 10, 260, fill="red", outline="yellow", width=0)
# Assert # Assert
assert_image_equal_tofile(im, "Tests/images/imagedraw_chord_zero_width.png") assert_image_equal_tofile(im, "Tests/images/imagedraw_chord_zero_width.png")
@ -247,7 +262,7 @@ def test_chord_too_fat():
@pytest.mark.parametrize("mode", ("RGB", "L")) @pytest.mark.parametrize("mode", ("RGB", "L"))
@pytest.mark.parametrize("bbox", (BBOX1, BBOX2)) @pytest.mark.parametrize("bbox", BBOX)
def test_ellipse(mode, bbox): def test_ellipse(mode, bbox):
# Arrange # Arrange
im = Image.new(mode, (W, H)) im = Image.new(mode, (W, H))
@ -261,13 +276,14 @@ def test_ellipse(mode, bbox):
assert_image_similar_tofile(im, expected, 1) assert_image_similar_tofile(im, expected, 1)
def test_ellipse_translucent(): @pytest.mark.parametrize("bbox", BBOX)
def test_ellipse_translucent(bbox):
# Arrange # Arrange
im = Image.new("RGB", (W, H)) im = Image.new("RGB", (W, H))
draw = ImageDraw.Draw(im, "RGBA") draw = ImageDraw.Draw(im, "RGBA")
# Act # Act
draw.ellipse(BBOX1, fill=(0, 255, 0, 127)) draw.ellipse(bbox, fill=(0, 255, 0, 127))
# Assert # Assert
expected = "Tests/images/imagedraw_ellipse_translucent.png" expected = "Tests/images/imagedraw_ellipse_translucent.png"
@ -297,13 +313,14 @@ def test_ellipse_symmetric():
assert_image_equal(im, im.transpose(Image.Transpose.FLIP_LEFT_RIGHT)) assert_image_equal(im, im.transpose(Image.Transpose.FLIP_LEFT_RIGHT))
def test_ellipse_width(): @pytest.mark.parametrize("bbox", BBOX)
def test_ellipse_width(bbox):
# Arrange # Arrange
im = Image.new("RGB", (W, H)) im = Image.new("RGB", (W, H))
draw = ImageDraw.Draw(im) draw = ImageDraw.Draw(im)
# Act # Act
draw.ellipse(BBOX1, outline="blue", width=5) draw.ellipse(bbox, outline="blue", width=5)
# Assert # Assert
assert_image_similar_tofile(im, "Tests/images/imagedraw_ellipse_width.png", 1) assert_image_similar_tofile(im, "Tests/images/imagedraw_ellipse_width.png", 1)
@ -321,25 +338,27 @@ def test_ellipse_width_large():
assert_image_similar_tofile(im, "Tests/images/imagedraw_ellipse_width_large.png", 1) assert_image_similar_tofile(im, "Tests/images/imagedraw_ellipse_width_large.png", 1)
def test_ellipse_width_fill(): @pytest.mark.parametrize("bbox", BBOX)
def test_ellipse_width_fill(bbox):
# Arrange # Arrange
im = Image.new("RGB", (W, H)) im = Image.new("RGB", (W, H))
draw = ImageDraw.Draw(im) draw = ImageDraw.Draw(im)
# Act # Act
draw.ellipse(BBOX1, fill="green", outline="blue", width=5) draw.ellipse(bbox, fill="green", outline="blue", width=5)
# Assert # Assert
assert_image_similar_tofile(im, "Tests/images/imagedraw_ellipse_width_fill.png", 1) assert_image_similar_tofile(im, "Tests/images/imagedraw_ellipse_width_fill.png", 1)
def test_ellipse_zero_width(): @pytest.mark.parametrize("bbox", BBOX)
def test_ellipse_zero_width(bbox):
# Arrange # Arrange
im = Image.new("RGB", (W, H)) im = Image.new("RGB", (W, H))
draw = ImageDraw.Draw(im) draw = ImageDraw.Draw(im)
# Act # Act
draw.ellipse(BBOX1, fill="green", outline="blue", width=0) draw.ellipse(bbox, fill="green", outline="blue", width=0)
# Assert # Assert
assert_image_equal_tofile(im, "Tests/images/imagedraw_ellipse_zero_width.png") assert_image_equal_tofile(im, "Tests/images/imagedraw_ellipse_zero_width.png")
@ -380,7 +399,7 @@ def test_ellipse_various_sizes_filled():
) )
@pytest.mark.parametrize("points", (POINTS1, POINTS2)) @pytest.mark.parametrize("points", POINTS)
def test_line(points): def test_line(points):
# Arrange # Arrange
im = Image.new("RGB", (W, H)) im = Image.new("RGB", (W, H))
@ -452,7 +471,7 @@ def test_transform():
assert_image_equal(im, expected) assert_image_equal(im, expected)
@pytest.mark.parametrize("bbox", (BBOX1, BBOX2)) @pytest.mark.parametrize("bbox", BBOX)
@pytest.mark.parametrize("start, end", ((-92, 46), (-92.2, 46.2))) @pytest.mark.parametrize("start, end", ((-92, 46), (-92.2, 46.2)))
def test_pieslice(bbox, start, end): def test_pieslice(bbox, start, end):
# Arrange # Arrange
@ -466,38 +485,41 @@ def test_pieslice(bbox, start, end):
assert_image_similar_tofile(im, "Tests/images/imagedraw_pieslice.png", 1) assert_image_similar_tofile(im, "Tests/images/imagedraw_pieslice.png", 1)
def test_pieslice_width(): @pytest.mark.parametrize("bbox", BBOX)
def test_pieslice_width(bbox):
# Arrange # Arrange
im = Image.new("RGB", (W, H)) im = Image.new("RGB", (W, H))
draw = ImageDraw.Draw(im) draw = ImageDraw.Draw(im)
# Act # Act
draw.pieslice(BBOX1, 10, 260, outline="blue", width=5) draw.pieslice(bbox, 10, 260, outline="blue", width=5)
# Assert # Assert
assert_image_similar_tofile(im, "Tests/images/imagedraw_pieslice_width.png", 1) assert_image_similar_tofile(im, "Tests/images/imagedraw_pieslice_width.png", 1)
def test_pieslice_width_fill(): @pytest.mark.parametrize("bbox", BBOX)
def test_pieslice_width_fill(bbox):
# Arrange # Arrange
im = Image.new("RGB", (W, H)) im = Image.new("RGB", (W, H))
draw = ImageDraw.Draw(im) draw = ImageDraw.Draw(im)
expected = "Tests/images/imagedraw_pieslice_width_fill.png" expected = "Tests/images/imagedraw_pieslice_width_fill.png"
# Act # Act
draw.pieslice(BBOX1, 10, 260, fill="white", outline="blue", width=5) draw.pieslice(bbox, 10, 260, fill="white", outline="blue", width=5)
# Assert # Assert
assert_image_similar_tofile(im, expected, 1) assert_image_similar_tofile(im, expected, 1)
def test_pieslice_zero_width(): @pytest.mark.parametrize("bbox", BBOX)
def test_pieslice_zero_width(bbox):
# Arrange # Arrange
im = Image.new("RGB", (W, H)) im = Image.new("RGB", (W, H))
draw = ImageDraw.Draw(im) draw = ImageDraw.Draw(im)
# Act # Act
draw.pieslice(BBOX1, 10, 260, fill="white", outline="blue", width=0) draw.pieslice(bbox, 10, 260, fill="white", outline="blue", width=0)
# Assert # Assert
assert_image_equal_tofile(im, "Tests/images/imagedraw_pieslice_zero_width.png") assert_image_equal_tofile(im, "Tests/images/imagedraw_pieslice_zero_width.png")
@ -545,7 +567,7 @@ def test_pieslice_no_spikes():
assert_image_equal(im, im_pre_erase) assert_image_equal(im, im_pre_erase)
@pytest.mark.parametrize("points", (POINTS1, POINTS2)) @pytest.mark.parametrize("points", POINTS)
def test_point(points): def test_point(points):
# Arrange # Arrange
im = Image.new("RGB", (W, H)) im = Image.new("RGB", (W, H))
@ -558,7 +580,7 @@ def test_point(points):
assert_image_equal_tofile(im, "Tests/images/imagedraw_point.png") assert_image_equal_tofile(im, "Tests/images/imagedraw_point.png")
@pytest.mark.parametrize("points", (POINTS1, POINTS2)) @pytest.mark.parametrize("points", POINTS)
def test_polygon(points): def test_polygon(points):
# Arrange # Arrange
im = Image.new("RGB", (W, H)) im = Image.new("RGB", (W, H))
@ -572,7 +594,8 @@ def test_polygon(points):
@pytest.mark.parametrize("mode", ("RGB", "L")) @pytest.mark.parametrize("mode", ("RGB", "L"))
def test_polygon_kite(mode): @pytest.mark.parametrize("kite_points", KITE_POINTS)
def test_polygon_kite(mode, kite_points):
# Test drawing lines of different gradients (dx>dy, dy>dx) and # Test drawing lines of different gradients (dx>dy, dy>dx) and
# vertical (dx==0) and horizontal (dy==0) lines # vertical (dx==0) and horizontal (dy==0) lines
# Arrange # Arrange
@ -581,7 +604,7 @@ def test_polygon_kite(mode):
expected = f"Tests/images/imagedraw_polygon_kite_{mode}.png" expected = f"Tests/images/imagedraw_polygon_kite_{mode}.png"
# Act # Act
draw.polygon(KITE_POINTS, fill="blue", outline="yellow") draw.polygon(kite_points, fill="blue", outline="yellow")
# Assert # Assert
assert_image_equal_tofile(im, expected) assert_image_equal_tofile(im, expected)
@ -628,7 +651,7 @@ def test_polygon_translucent():
assert_image_equal_tofile(im, expected) assert_image_equal_tofile(im, expected)
@pytest.mark.parametrize("bbox", (BBOX1, BBOX2)) @pytest.mark.parametrize("bbox", BBOX)
def test_rectangle(bbox): def test_rectangle(bbox):
# Arrange # Arrange
im = Image.new("RGB", (W, H)) im = Image.new("RGB", (W, H))
@ -655,63 +678,68 @@ def test_big_rectangle():
assert_image_similar_tofile(im, "Tests/images/imagedraw_big_rectangle.png", 1) assert_image_similar_tofile(im, "Tests/images/imagedraw_big_rectangle.png", 1)
def test_rectangle_width(): @pytest.mark.parametrize("bbox", BBOX)
def test_rectangle_width(bbox):
# Arrange # Arrange
im = Image.new("RGB", (W, H)) im = Image.new("RGB", (W, H))
draw = ImageDraw.Draw(im) draw = ImageDraw.Draw(im)
expected = "Tests/images/imagedraw_rectangle_width.png" expected = "Tests/images/imagedraw_rectangle_width.png"
# Act # Act
draw.rectangle(BBOX1, outline="green", width=5) draw.rectangle(bbox, outline="green", width=5)
# Assert # Assert
assert_image_equal_tofile(im, expected) assert_image_equal_tofile(im, expected)
def test_rectangle_width_fill(): @pytest.mark.parametrize("bbox", BBOX)
def test_rectangle_width_fill(bbox):
# Arrange # Arrange
im = Image.new("RGB", (W, H)) im = Image.new("RGB", (W, H))
draw = ImageDraw.Draw(im) draw = ImageDraw.Draw(im)
expected = "Tests/images/imagedraw_rectangle_width_fill.png" expected = "Tests/images/imagedraw_rectangle_width_fill.png"
# Act # Act
draw.rectangle(BBOX1, fill="blue", outline="green", width=5) draw.rectangle(bbox, fill="blue", outline="green", width=5)
# Assert # Assert
assert_image_equal_tofile(im, expected) assert_image_equal_tofile(im, expected)
def test_rectangle_zero_width(): @pytest.mark.parametrize("bbox", BBOX)
def test_rectangle_zero_width(bbox):
# Arrange # Arrange
im = Image.new("RGB", (W, H)) im = Image.new("RGB", (W, H))
draw = ImageDraw.Draw(im) draw = ImageDraw.Draw(im)
# Act # Act
draw.rectangle(BBOX1, fill="blue", outline="green", width=0) draw.rectangle(bbox, fill="blue", outline="green", width=0)
# Assert # Assert
assert_image_equal_tofile(im, "Tests/images/imagedraw_rectangle_zero_width.png") assert_image_equal_tofile(im, "Tests/images/imagedraw_rectangle_zero_width.png")
def test_rectangle_I16(): @pytest.mark.parametrize("bbox", BBOX)
def test_rectangle_I16(bbox):
# Arrange # Arrange
im = Image.new("I;16", (W, H)) im = Image.new("I;16", (W, H))
draw = ImageDraw.Draw(im) draw = ImageDraw.Draw(im)
# Act # Act
draw.rectangle(BBOX1, fill="black", outline="green") draw.rectangle(bbox, fill="black", outline="green")
# Assert # Assert
assert_image_equal_tofile(im.convert("I"), "Tests/images/imagedraw_rectangle_I.png") assert_image_equal_tofile(im.convert("I"), "Tests/images/imagedraw_rectangle_I.png")
def test_rectangle_translucent_outline(): @pytest.mark.parametrize("bbox", BBOX)
def test_rectangle_translucent_outline(bbox):
# Arrange # Arrange
im = Image.new("RGB", (W, H)) im = Image.new("RGB", (W, H))
draw = ImageDraw.Draw(im, "RGBA") draw = ImageDraw.Draw(im, "RGBA")
# Act # Act
draw.rectangle(BBOX1, fill="black", outline=(0, 255, 0, 127), width=5) draw.rectangle(bbox, fill="black", outline=(0, 255, 0, 127), width=5)
# Assert # Assert
assert_image_equal_tofile( assert_image_equal_tofile(
@ -758,13 +786,14 @@ def test_rounded_rectangle_non_integer_radius(xy, radius, type):
) )
def test_rounded_rectangle_zero_radius(): @pytest.mark.parametrize("bbox", BBOX)
def test_rounded_rectangle_zero_radius(bbox):
# Arrange # Arrange
im = Image.new("RGB", (W, H)) im = Image.new("RGB", (W, H))
draw = ImageDraw.Draw(im) draw = ImageDraw.Draw(im)
# Act # Act
draw.rounded_rectangle(BBOX1, 0, fill="blue", outline="green", width=5) draw.rounded_rectangle(bbox, 0, fill="blue", outline="green", width=5)
# Assert # Assert
assert_image_equal_tofile(im, "Tests/images/imagedraw_rectangle_width_fill.png") assert_image_equal_tofile(im, "Tests/images/imagedraw_rectangle_width_fill.png")
@ -794,14 +823,15 @@ def test_rounded_rectangle_translucent(xy, suffix):
) )
def test_floodfill(): @pytest.mark.parametrize("bbox", BBOX)
def test_floodfill(bbox):
red = ImageColor.getrgb("red") red = ImageColor.getrgb("red")
for mode, value in [("L", 1), ("RGBA", (255, 0, 0, 0)), ("RGB", red)]: for mode, value in [("L", 1), ("RGBA", (255, 0, 0, 0)), ("RGB", red)]:
# Arrange # Arrange
im = Image.new(mode, (W, H)) im = Image.new(mode, (W, H))
draw = ImageDraw.Draw(im) draw = ImageDraw.Draw(im)
draw.rectangle(BBOX2, outline="yellow", fill="green") draw.rectangle(bbox, outline="yellow", fill="green")
centre_point = (int(W / 2), int(H / 2)) centre_point = (int(W / 2), int(H / 2))
# Act # Act
@ -826,13 +856,14 @@ def test_floodfill():
assert_image_equal(im, Image.new("RGB", (1, 1), red)) assert_image_equal(im, Image.new("RGB", (1, 1), red))
def test_floodfill_border(): @pytest.mark.parametrize("bbox", BBOX)
def test_floodfill_border(bbox):
# floodfill() is experimental # floodfill() is experimental
# Arrange # Arrange
im = Image.new("RGB", (W, H)) im = Image.new("RGB", (W, H))
draw = ImageDraw.Draw(im) draw = ImageDraw.Draw(im)
draw.rectangle(BBOX2, outline="yellow", fill="green") draw.rectangle(bbox, outline="yellow", fill="green")
centre_point = (int(W / 2), int(H / 2)) centre_point = (int(W / 2), int(H / 2))
# Act # Act
@ -847,13 +878,14 @@ def test_floodfill_border():
assert_image_equal_tofile(im, "Tests/images/imagedraw_floodfill2.png") assert_image_equal_tofile(im, "Tests/images/imagedraw_floodfill2.png")
def test_floodfill_thresh(): @pytest.mark.parametrize("bbox", BBOX)
def test_floodfill_thresh(bbox):
# floodfill() is experimental # floodfill() is experimental
# Arrange # Arrange
im = Image.new("RGB", (W, H)) im = Image.new("RGB", (W, H))
draw = ImageDraw.Draw(im) draw = ImageDraw.Draw(im)
draw.rectangle(BBOX2, outline="darkgreen", fill="green") draw.rectangle(bbox, outline="darkgreen", fill="green")
centre_point = (int(W / 2), int(H / 2)) centre_point = (int(W / 2), int(H / 2))
# Act # Act
@ -1291,7 +1323,8 @@ def test_setting_default_font():
assert isinstance(draw.getfont(), ImageFont.ImageFont) assert isinstance(draw.getfont(), ImageFont.ImageFont)
def test_same_color_outline(): @pytest.mark.parametrize("bbox", BBOX)
def test_same_color_outline(bbox):
# Prepare shape # Prepare shape
x0, y0 = 5, 5 x0, y0 = 5, 5
x1, y1 = 5, 50 x1, y1 = 5, 50
@ -1307,12 +1340,12 @@ def test_same_color_outline():
for mode in ["RGB", "L"]: for mode in ["RGB", "L"]:
for fill, outline in [["red", None], ["red", "red"], ["red", "#f00"]]: for fill, outline in [["red", None], ["red", "red"], ["red", "#f00"]]:
for operation, args in { for operation, args in {
"chord": [BBOX1, 0, 180], "chord": [bbox, 0, 180],
"ellipse": [BBOX1], "ellipse": [bbox],
"shape": [s], "shape": [s],
"pieslice": [BBOX1, -90, 45], "pieslice": [bbox, -90, 45],
"polygon": [[(18, 30), (85, 30), (60, 72)]], "polygon": [[(18, 30), (85, 30), (60, 72)]],
"rectangle": [BBOX1], "rectangle": [bbox],
}.items(): }.items():
# Arrange # Arrange
im = Image.new(mode, (W, H)) im = Image.new(mode, (W, H))

View File

@ -27,15 +27,16 @@ X1 = int(X0 * 3)
Y0 = int(H / 4) Y0 = int(H / 4)
Y1 = int(X0 * 3) Y1 = int(X0 * 3)
# Two kinds of bounding box # Bounding boxes
BBOX1 = [(X0, Y0), (X1, Y1)] BBOX = (((X0, Y0), (X1, Y1)), [(X0, Y0), (X1, Y1)], (X0, Y0, X1, Y1), [X0, Y0, X1, Y1])
BBOX2 = [X0, Y0, X1, Y1]
# Two kinds of coordinate sequences # Coordinate sequences
POINTS1 = [(10, 10), (20, 40), (30, 30)] POINTS = (
POINTS2 = [10, 10, 20, 40, 30, 30] ((10, 10), (20, 40), (30, 30)),
[(10, 10), (20, 40), (30, 30)],
KITE_POINTS = [(10, 50), (70, 10), (90, 50), (70, 90), (10, 50)] (10, 10, 20, 40, 30, 30),
[10, 10, 20, 40, 30, 30],
)
FONT_PATH = "Tests/fonts/FreeMono.ttf" FONT_PATH = "Tests/fonts/FreeMono.ttf"
@ -52,7 +53,7 @@ def test_sanity():
draw.line(list(range(10)), pen) draw.line(list(range(10)), pen)
@pytest.mark.parametrize("bbox", (BBOX1, BBOX2)) @pytest.mark.parametrize("bbox", BBOX)
def test_ellipse(bbox): def test_ellipse(bbox):
# Arrange # Arrange
im = Image.new("RGB", (W, H)) im = Image.new("RGB", (W, H))
@ -80,7 +81,7 @@ def test_ellipse_edge():
assert_image_similar_tofile(im, "Tests/images/imagedraw_ellipse_edge.png", 1) assert_image_similar_tofile(im, "Tests/images/imagedraw_ellipse_edge.png", 1)
@pytest.mark.parametrize("points", (POINTS1, POINTS2)) @pytest.mark.parametrize("points", POINTS)
def test_line(points): def test_line(points):
# Arrange # Arrange
im = Image.new("RGB", (W, H)) im = Image.new("RGB", (W, H))
@ -94,7 +95,8 @@ def test_line(points):
assert_image_equal_tofile(im, "Tests/images/imagedraw_line.png") assert_image_equal_tofile(im, "Tests/images/imagedraw_line.png")
def test_line_pen_as_brush(): @pytest.mark.parametrize("points", POINTS)
def test_line_pen_as_brush(points):
# Arrange # Arrange
im = Image.new("RGB", (W, H)) im = Image.new("RGB", (W, H))
draw = ImageDraw2.Draw(im) draw = ImageDraw2.Draw(im)
@ -103,13 +105,13 @@ def test_line_pen_as_brush():
# Act # Act
# Pass in the pen as the brush parameter # Pass in the pen as the brush parameter
draw.line(POINTS1, pen, brush) draw.line(points, pen, brush)
# Assert # Assert
assert_image_equal_tofile(im, "Tests/images/imagedraw_line.png") assert_image_equal_tofile(im, "Tests/images/imagedraw_line.png")
@pytest.mark.parametrize("points", (POINTS1, POINTS2)) @pytest.mark.parametrize("points", POINTS)
def test_polygon(points): def test_polygon(points):
# Arrange # Arrange
im = Image.new("RGB", (W, H)) im = Image.new("RGB", (W, H))
@ -124,7 +126,7 @@ def test_polygon(points):
assert_image_equal_tofile(im, "Tests/images/imagedraw_polygon.png") assert_image_equal_tofile(im, "Tests/images/imagedraw_polygon.png")
@pytest.mark.parametrize("bbox", (BBOX1, BBOX2)) @pytest.mark.parametrize("bbox", BBOX)
def test_rectangle(bbox): def test_rectangle(bbox):
# Arrange # Arrange
im = Image.new("RGB", (W, H)) im = Image.new("RGB", (W, H))