diff --git a/Tests/images/imagedraw_line.png b/Tests/images/imagedraw_line.png new file mode 100644 index 000000000..6d0e6994d Binary files /dev/null and b/Tests/images/imagedraw_line.png differ diff --git a/Tests/images/imagedraw_point.png b/Tests/images/imagedraw_point.png new file mode 100644 index 000000000..ab7c1a322 Binary files /dev/null and b/Tests/images/imagedraw_point.png differ diff --git a/Tests/images/imagedraw_polygon.png b/Tests/images/imagedraw_polygon.png new file mode 100644 index 000000000..5f160be76 Binary files /dev/null and b/Tests/images/imagedraw_polygon.png differ diff --git a/Tests/images/imagedraw_rectangle.png b/Tests/images/imagedraw_rectangle.png new file mode 100644 index 000000000..782d84461 Binary files /dev/null and b/Tests/images/imagedraw_rectangle.png differ diff --git a/Tests/test_imagedraw.py b/Tests/test_imagedraw.py index 9904457af..727275c2d 100644 --- a/Tests/test_imagedraw.py +++ b/Tests/test_imagedraw.py @@ -16,6 +16,10 @@ y1 = int(x0 * 3) bbox1 = [(x0, y0), (x1, y1)] bbox2 = [x0, y0, x1, y1] +# Two kinds of coordinate sequences +points1 = [(10, 10), (20, 40), (30, 30)] +points2 = [10, 10, 20, 40, 30, 30] + def test_sanity(): @@ -109,6 +113,27 @@ def test_ellipse2(): helper_ellipse(bbox2) +def helper_line(points): + # Arrange + im = Image.new("RGB", (w, h)) + draw = ImageDraw.Draw(im) + + # Act + draw.line(points1, fill="yellow", width=2) + del draw + + # Assert + assert_image_equal(im, Image.open("Tests/images/imagedraw_line.png")) + + +def test_line1(): + helper_line(points1) + + +def test_line2(): + helper_line(points2) + + def helper_pieslice(bbox): # Arrange im = Image.new("RGB", (w, h)) @@ -131,4 +156,67 @@ def test_pieslice2(): helper_pieslice(bbox2) +def helper_point(points): + # Arrange + im = Image.new("RGB", (w, h)) + draw = ImageDraw.Draw(im) + + # Act + draw.point(points1, fill="yellow") + del draw + + # Assert + assert_image_equal(im, Image.open("Tests/images/imagedraw_point.png")) + + +def test_point1(): + helper_point(points1) + + +def test_point2(): + helper_point(points2) + + +def helper_polygon(points): + # Arrange + im = Image.new("RGB", (w, h)) + draw = ImageDraw.Draw(im) + + # Act + draw.polygon(points1, fill="red", outline="blue") + del draw + + # Assert + assert_image_equal(im, Image.open("Tests/images/imagedraw_polygon.png")) + + +def test_polygon1(): + helper_polygon(points1) + + +def test_polygon2(): + helper_polygon(points2) + + +def helper_rectangle(bbox): + # Arrange + im = Image.new("RGB", (w, h)) + draw = ImageDraw.Draw(im) + + # Act + draw.rectangle(bbox, fill="black", outline="green") + del draw + + # Assert + assert_image_equal(im, Image.open("Tests/images/imagedraw_rectangle.png")) + + +def test_rectangle1(): + helper_rectangle(bbox1) + + +def test_rectangle2(): + helper_rectangle(bbox2) + + # End of file