-
Notifications
You must be signed in to change notification settings - Fork 2
/
selftest.py
147 lines (106 loc) · 3.39 KB
/
selftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# $Id$
# -*- coding: iso-8859-1 -*-
# sanity check
import Image
from aggdraw import *
def testdraw():
"""
>>> draw = Draw("RGB")
Traceback (most recent call last):
AttributeError: 'str' object has no attribute 'mode'
>>> draw = Draw("RGB", (800, 600))
>>> draw.mode, draw.size
('RGB', (800, 600))
>>> draw = Draw("RGB", (800, 600), "white")
>>> draw.mode, draw.size
('RGB', (800, 600))
>>> im = Image.new("RGB", (600, 800))
>>> draw = Draw(im)
>>> draw.mode, draw.size
('RGB', (600, 800))
"""
def testpen():
"""
>>> pen = Pen("black")
>>> pen = Pen("black", 1)
>>> pen = Pen("black", 1.5)
>>> pen = Pen("black", 1, opacity=128)
>>> pen = Pen(0)
>>> pen = Pen((0,0,0))
>>> pen = Pen("rgb(0,0,0)")
>>> pen = Pen("gold")
"""
def testbrush():
"""
>>> brush = Brush("black")
>>> brush = Brush("black", opacity=128)
>>> brush = Brush(0)
>>> brush = Brush((0,0,0))
>>> brush = Brush("rgb(0,0,0)")
>>> brush = Brush("gold")
"""
def testgraphics():
"""
>>> draw = Draw("RGB", (500, 500))
>>> pen = Pen("black")
>>> brush = Brush("black")
>>> draw.line((50, 50, 100, 100), pen)
>>> draw.rectangle((50, 150, 100, 200), pen)
>>> draw.rectangle((50, 220, 100, 270), brush)
>>> draw.rectangle((50, 290, 100, 340), brush, pen)
>>> draw.rectangle((50, 360, 100, 410), pen, brush)
>>> draw.ellipse((120, 150, 170, 200), pen)
>>> draw.ellipse((120, 220, 170, 270), brush)
>>> draw.ellipse((120, 290, 170, 340), brush, pen)
>>> draw.ellipse((120, 360, 170, 410), pen, brush)
>>> draw.polygon((190+25, 150, 190, 200, 190+50, 200), pen)
>>> draw.polygon((190+25, 220, 190, 270, 190+50, 270), brush)
>>> draw.polygon((190+25, 290, 190, 340, 190+50, 340), brush, pen)
>>> draw.polygon((190+25, 360, 190, 410, 190+50, 410), pen, brush)
"""
def testpath():
"""
>>> p = Path()
>>> p = Path([0,0])
>>> p = Path([0,0,0,0])
>>> p.moveto(0, 0)
>>> p.lineto(1, 1)
>>> p.coords()
[0.0, 0.0, 1.0, 1.0]
>>> p.curveto(0, 0, 0, 0, 0, 0)
>>> p.close()
>>> p.coords()
[0.0, 0.0, 1.0, 1.0, 0.125, 0.125, 0.0, 0.0]
>>> draw = Draw("RGB", (800, 600))
>>> draw.line(p)
>>> draw.polygon(p)
>>> draw.symbol((0, 0), p)
"""
def testsymbol():
"""
>>> s = Symbol("M0,0L0,0L0,0L0,0Z")
>>> s = Symbol("M0,0L0,0,0,0,0,0Z", 10)
>>> s = Symbol("M0,0C0,0,0,0,0,0Z")
>>> s = Symbol("M0,0S0,0,0,0,0,0Z")
>>> s = Symbol("m0,0l0,0l0,0l0,0z")
>>> s = Symbol("m0,0l0,0,0,0,0,0z", 10)
>>> s = Symbol("m0,0c0,0,0,0,0,0z")
>>> s = Symbol("m0,0s0,0,0,0,0,0z")
"""
def testtransform():
"""
>>> draw = Draw("RGB", (500, 500))
>>> draw.settransform()
>>> draw.settransform((250, 250))
>>> draw.settransform((1, 0, 250, 0, 1, 250))
>>> draw.settransform((2.0, 0.5, 250, 0.5, 2.0, 250))
>>> draw.settransform()
"""
if __name__ == "__main__":
# use doctest to make sure the test program behaves as documented!
import doctest, selftest
status = doctest.testmod(selftest)
if status[0]:
print "*** %s tests of %d failed." % status
else:
print "%s tests passed." % status[1]