Skip to content

Commit

Permalink
More ImageDraw tests. Some may need redoing after issues python-pillo…
Browse files Browse the repository at this point in the history
…w#367 and python-pillow#463 are sorted.
  • Loading branch information
hugovk committed May 12, 2014
1 parent 84c7d25 commit 6b274b4
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 0 deletions.
Binary file added Tests/images/imagedraw_line.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Tests/images/imagedraw_point.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Tests/images/imagedraw_polygon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Tests/images/imagedraw_rectangle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
88 changes: 88 additions & 0 deletions Tests/test_imagedraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
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():

Expand Down Expand Up @@ -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))
Expand All @@ -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

0 comments on commit 6b274b4

Please sign in to comment.