author | robin <robin@reportlab.com> |
Tue, 07 Mar 2017 10:00:34 +0000 | |
changeset 4330 | 617ffa6bbdc8 |
parent 4252 | fe660f227cac |
permissions | -rw-r--r-- |
4330 | 1 |
#Copyright ReportLab Europe Ltd. 2000-2017 |
2963 | 2 |
#see license.txt for license details |
3 |
""" |
|
4 |
This does a test drawing with lots of things in it, running |
|
5 |
with and without attribute checking. |
|
6 |
""" |
|
2967
ea62529bd1df
reportlab-2.2: first stage changes in on the trunk
rgbecker
parents:
2966
diff
changeset
|
7 |
__version__ = '''$Id$''' |
2984 | 8 |
from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, outputfile, printLocation |
9 |
setOutDir(__name__) |
|
2963 | 10 |
import os, sys, time |
11 |
import reportlab.rl_config |
|
2966 | 12 |
import unittest |
2963 | 13 |
from reportlab.lib import colors |
14 |
from reportlab.lib.units import cm |
|
15 |
from reportlab.pdfgen.canvas import Canvas |
|
16 |
from reportlab.pdfbase.pdfmetrics import stringWidth |
|
17 |
from reportlab.platypus import Flowable |
|
18 |
from reportlab.graphics.shapes import * |
|
19 |
from reportlab.graphics.charts.piecharts import Pie |
|
20 |
||
21 |
||
22 |
class GraphicsSpeedTestCase(unittest.TestCase): |
|
23 |
"Test speed of the graphics rendering process." |
|
24 |
||
25 |
def test0(self, isFast=0): |
|
26 |
"""Hello World, on a rectangular background. |
|
27 |
||
28 |
The rectangle's fillColor is yellow. |
|
29 |
The string's fillColor is red. |
|
30 |
""" |
|
31 |
reportlab.rl_config.shapeChecking = not isFast |
|
32 |
||
33 |
pdfPath = outputfile('test_graphics_speed_fast.pdf') |
|
34 |
c = Canvas(pdfPath) |
|
35 |
t0 = time.time() |
|
36 |
||
37 |
d = Drawing(400, 200) |
|
38 |
num = 100 |
|
39 |
for i in range(num): |
|
40 |
pc = Pie() |
|
41 |
pc.x = 150 |
|
42 |
pc.y = 50 |
|
43 |
pc.data = [10,20,30,40,50,60] |
|
44 |
pc.labels = ['a','b','c','d','e','f'] |
|
45 |
pc.slices.strokeWidth=0.5 |
|
46 |
pc.slices[3].popout = 20 |
|
47 |
pc.slices[3].strokeWidth = 2 |
|
48 |
pc.slices[3].strokeDashArray = [2,2] |
|
49 |
pc.slices[3].labelRadius = 1.75 |
|
50 |
pc.slices[3].fontColor = colors.red |
|
51 |
d.add(pc) |
|
52 |
d.drawOn(c, 80, 500) |
|
53 |
||
54 |
t1 = time.time() |
|
55 |
||
56 |
result = 'drew %d pie charts in %0.4f' % (num, t1 - t0) |
|
57 |
open(outputfile('test_graphics_speed_test%s.log' % (isFast+1)), 'w').write(result) |
|
58 |
||
59 |
def test1(self, isFast=1): |
|
60 |
"Same as test1(), but with shape checking turned on." |
|
61 |
self.test0(isFast) |
|
62 |
||
63 |
if False: |
|
64 |
def test2(self): |
|
65 |
"This is a profiled version of test1()." |
|
66 |
try: |
|
67 |
import profile |
|
68 |
except ImportError: |
|
69 |
return |
|
70 |
fileName = outputfile('test_graphics_speed_profile.log') |
|
71 |
# This runs ok, when only this test script is executed, |
|
72 |
# but fails, when imported from runAll.py... |
|
73 |
profile.run("t = GraphicsSpeedTestCase('test2')", fileName) |
|
74 |
||
75 |
def makeSuite(): |
|
76 |
return makeSuiteForClasses(GraphicsSpeedTestCase) |
|
77 |
||
78 |
||
79 |
#noruntests |
|
80 |
if __name__ == "__main__": |
|
81 |
unittest.TextTestRunner().run(makeSuite()) |
|
82 |
printLocation() |