4330
|
1 |
#Copyright ReportLab Europe Ltd. 2000-2017
|
2963
|
2 |
#see license.txt for license details
|
|
3 |
"""
|
|
4 |
Tests for getBounds methods of various graphical widgets
|
|
5 |
"""
|
|
6 |
|
2966
|
7 |
import unittest
|
2984
|
8 |
from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, printLocation
|
|
9 |
setOutDir(__name__)
|
2963
|
10 |
|
|
11 |
from reportlab.graphics import shapes
|
|
12 |
##from reportlab.graphics.charts.barcharts import VerticalBarChart
|
|
13 |
##from reportlab.graphics.charts.linecharts import HorizontalLineChart
|
|
14 |
##from reportlab.graphics.charts.piecharts import Pie
|
|
15 |
##from reportlab.graphics.charts.legends import Legend
|
|
16 |
|
|
17 |
class BoundsTestCase(unittest.TestCase):
|
|
18 |
def testLine(self):
|
|
19 |
s = shapes.Line(10,20,30,40)
|
|
20 |
assert s.getBounds() == (10,20,30,40)
|
|
21 |
|
|
22 |
def testRect(self):
|
|
23 |
s = shapes.Rect(10,20,30,40) #width, height
|
|
24 |
assert s.getBounds() == (10,20,40,60)
|
|
25 |
|
|
26 |
def testCircle(self):
|
|
27 |
s = shapes.Circle(100, 50, 10)
|
|
28 |
assert s.getBounds() == (90,40,110,60)
|
|
29 |
|
|
30 |
def testEllipse(self):
|
|
31 |
s = shapes.Ellipse(100, 50, 10, 5)
|
|
32 |
assert s.getBounds() == (90,45,110,55)
|
|
33 |
|
|
34 |
def testWedge(self):
|
|
35 |
s = shapes.Wedge(0,0,10,0,90)
|
|
36 |
assert s.getBounds() == (0,0,10,10), 'expected (0,0,10,10) got %s' % repr(s.getBounds())
|
|
37 |
|
|
38 |
def testPolygon(self):
|
|
39 |
points = [0,0,10,30,25,15]
|
|
40 |
s = shapes.Polygon(points)
|
|
41 |
assert s.getBounds() == (0,0,25,30)
|
|
42 |
|
|
43 |
s = shapes.PolyLine(points)
|
|
44 |
assert s.getBounds() == (0,0,25,30)
|
|
45 |
|
|
46 |
def testString(self):
|
|
47 |
s = shapes.String(0,0,'Hello World', fontName='Courier',fontSize=10)
|
|
48 |
assert s.getBounds() == (0, -2.0, 66.0, 10)
|
|
49 |
|
|
50 |
def testGroup(self):
|
|
51 |
g = shapes.Group()
|
|
52 |
g.add(shapes.Rect(0,0,10,10))
|
|
53 |
g.add(shapes.Rect(50,50,10,10))
|
|
54 |
assert g.getBounds() == (0,0,60,60)
|
|
55 |
|
|
56 |
g.translate(40,40)
|
|
57 |
assert g.getBounds() == (40,40,100,100)
|
|
58 |
|
|
59 |
g.translate(-40,-40)
|
|
60 |
g.rotate(90)
|
|
61 |
#approx bounds needed, trig functions create an error of 3e-15
|
3721
|
62 |
assert list(map(int, g.getBounds())) == [-60,0,0,60]
|
2963
|
63 |
|
|
64 |
def testWidget(self):
|
|
65 |
from reportlab.graphics.charts.barcharts import VerticalBarChart
|
|
66 |
vbc = VerticalBarChart()
|
|
67 |
vbc.x = 50
|
|
68 |
vbc.y = 50
|
|
69 |
from reportlab.graphics.widgetbase import Sizer
|
|
70 |
siz = Sizer()
|
|
71 |
siz.add(vbc, 'vbc')
|
3326
|
72 |
assert siz.getBounds()[0:2] != (0,0)
|
2963
|
73 |
|
|
74 |
|
|
75 |
def makeSuite():
|
|
76 |
return makeSuiteForClasses(BoundsTestCase)
|
|
77 |
|
|
78 |
|
|
79 |
#noruntests
|
|
80 |
if __name__ == "__main__":
|
|
81 |
unittest.TextTestRunner().run(makeSuite())
|
|
82 |
printLocation()
|