author | robin <robin@reportlab.com> |
Tue, 07 Mar 2017 10:00:34 +0000 | |
changeset 4330 | 617ffa6bbdc8 |
parent 4252 | fe660f227cac |
child 4523 | 38996c0a8955 |
permissions | -rw-r--r-- |
4330 | 1 |
#Copyright ReportLab Europe Ltd. 2000-2017 |
2963 | 2 |
#see license.txt for license details |
3 |
"""Tests for the reportlab.lib.sequencer module. |
|
4 |
""" |
|
4252 | 5 |
__version__='3.3.0' |
2984 | 6 |
from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, printLocation |
7 |
setOutDir(__name__) |
|
2963 | 8 |
import sys, random |
2966 | 9 |
import unittest |
2963 | 10 |
from reportlab.lib.sequencer import Sequencer |
11 |
||
12 |
||
13 |
class SequencerTestCase(unittest.TestCase): |
|
14 |
"Test Sequencer usage." |
|
15 |
||
16 |
def test0(self): |
|
17 |
"Test sequencer default counter." |
|
18 |
||
19 |
seq = Sequencer() |
|
20 |
msg = 'Initial value is not zero!' |
|
21 |
assert seq._this() == 0, msg |
|
22 |
||
23 |
||
24 |
def test1(self): |
|
25 |
"Test incrementing default counter." |
|
26 |
||
27 |
seq = Sequencer() |
|
28 |
||
29 |
for i in range(1, 101): |
|
3822 | 30 |
n = seq.next() |
2963 | 31 |
msg = 'Sequence value is not correct!' |
32 |
assert seq._this() == n, msg |
|
33 |
||
34 |
||
35 |
def test2(self): |
|
36 |
"Test resetting default counter." |
|
37 |
||
38 |
seq = Sequencer() |
|
39 |
start = seq._this() |
|
40 |
||
41 |
for i in range(1, 101): |
|
3822 | 42 |
n = seq.next() |
2963 | 43 |
|
44 |
seq.reset() |
|
45 |
||
46 |
msg = 'Sequence value not correctly reset!' |
|
47 |
assert seq._this() == start, msg |
|
48 |
||
49 |
||
50 |
def test3(self): |
|
51 |
"Test incrementing dedicated counter." |
|
52 |
||
53 |
seq = Sequencer() |
|
54 |
||
55 |
for i in range(1, 101): |
|
56 |
n = seq.next('myCounter1') |
|
57 |
msg = 'Sequence value is not correct!' |
|
58 |
assert seq._this('myCounter1') == n, msg |
|
59 |
||
60 |
||
61 |
def test4(self): |
|
62 |
"Test resetting dedicated counter." |
|
63 |
||
64 |
seq = Sequencer() |
|
65 |
start = seq._this('myCounter1') |
|
66 |
||
67 |
for i in range(1, 101): |
|
68 |
n = seq.next('myCounter1') |
|
69 |
||
70 |
seq.reset('myCounter1') |
|
71 |
||
72 |
msg = 'Sequence value not correctly reset!' |
|
73 |
assert seq._this('myCounter1') == start, msg |
|
74 |
||
75 |
||
76 |
def test5(self): |
|
77 |
"Test incrementing multiple dedicated counters." |
|
78 |
||
79 |
seq = Sequencer() |
|
80 |
startMyCounter0 = seq._this('myCounter0') |
|
81 |
startMyCounter1 = seq._this('myCounter1') |
|
82 |
||
83 |
for i in range(1, 101): |
|
84 |
n = seq.next('myCounter0') |
|
85 |
msg = 'Sequence value is not correct!' |
|
86 |
assert seq._this('myCounter0') == n, msg |
|
87 |
m = seq.next('myCounter1') |
|
88 |
msg = 'Sequence value is not correct!' |
|
89 |
assert seq._this('myCounter1') == m, msg |
|
90 |
||
4068
600b2453d5a3
added test of chaining multi-level sequencers
Andy Robinson <andy@reportlab.com>
parents:
3822
diff
changeset
|
91 |
def testChain(self): |
600b2453d5a3
added test of chaining multi-level sequencers
Andy Robinson <andy@reportlab.com>
parents:
3822
diff
changeset
|
92 |
"Test auto resetting of subsections" |
600b2453d5a3
added test of chaining multi-level sequencers
Andy Robinson <andy@reportlab.com>
parents:
3822
diff
changeset
|
93 |
seq = Sequencer() |
600b2453d5a3
added test of chaining multi-level sequencers
Andy Robinson <andy@reportlab.com>
parents:
3822
diff
changeset
|
94 |
seq.chain('h1', 'h2') #creates them and links |
600b2453d5a3
added test of chaining multi-level sequencers
Andy Robinson <andy@reportlab.com>
parents:
3822
diff
changeset
|
95 |
self.assertEquals(seq.next('h1'), 1) |
600b2453d5a3
added test of chaining multi-level sequencers
Andy Robinson <andy@reportlab.com>
parents:
3822
diff
changeset
|
96 |
self.assertEquals(seq.next('h1'), 2) |
600b2453d5a3
added test of chaining multi-level sequencers
Andy Robinson <andy@reportlab.com>
parents:
3822
diff
changeset
|
97 |
self.assertEquals(seq.next('h2'), 1) |
600b2453d5a3
added test of chaining multi-level sequencers
Andy Robinson <andy@reportlab.com>
parents:
3822
diff
changeset
|
98 |
self.assertEquals(seq.next('h2'), 2) |
600b2453d5a3
added test of chaining multi-level sequencers
Andy Robinson <andy@reportlab.com>
parents:
3822
diff
changeset
|
99 |
self.assertEquals(seq.next('h2'), 3) |
600b2453d5a3
added test of chaining multi-level sequencers
Andy Robinson <andy@reportlab.com>
parents:
3822
diff
changeset
|
100 |
|
600b2453d5a3
added test of chaining multi-level sequencers
Andy Robinson <andy@reportlab.com>
parents:
3822
diff
changeset
|
101 |
#start chapter 3 |
600b2453d5a3
added test of chaining multi-level sequencers
Andy Robinson <andy@reportlab.com>
parents:
3822
diff
changeset
|
102 |
self.assertEquals(seq.next('h1'), 3) |
600b2453d5a3
added test of chaining multi-level sequencers
Andy Robinson <andy@reportlab.com>
parents:
3822
diff
changeset
|
103 |
#...and the first section should be numbered 1, not 4 |
600b2453d5a3
added test of chaining multi-level sequencers
Andy Robinson <andy@reportlab.com>
parents:
3822
diff
changeset
|
104 |
self.assertEquals(seq.next('h2'), 1) |
600b2453d5a3
added test of chaining multi-level sequencers
Andy Robinson <andy@reportlab.com>
parents:
3822
diff
changeset
|
105 |
|
2963 | 106 |
|
107 |
## def testRandom(self): |
|
108 |
## "Test randomly manipulating multiple dedicated counters." |
|
109 |
## |
|
110 |
## seq = Sequencer() |
|
111 |
## counterNames = ['c0', 'c1', 'c2', 'c3'] |
|
112 |
## |
|
113 |
## # Init. |
|
114 |
## for cn in counterNames: |
|
115 |
## setattr(self, cn, seq._this(cn)) |
|
116 |
## msg = 'Counter start value is not correct!' |
|
117 |
## assert seq._this(cn) == 0, msg |
|
118 |
## |
|
119 |
## # Increment/decrement. |
|
120 |
## for i in range(1, 101): |
|
121 |
## n = seq.next('myCounter0') |
|
122 |
## msg = 'Sequence value is not correct!' |
|
123 |
## assert seq._this('myCounter0') == n, msg |
|
124 |
## m = seq.next('myCounter1') |
|
125 |
## msg = 'Sequence value is not correct!' |
|
126 |
## assert seq._this('myCounter1') == m, msg |
|
127 |
||
128 |
||
129 |
def makeSuite(): |
|
130 |
return makeSuiteForClasses(SequencerTestCase) |
|
131 |
||
132 |
||
133 |
#noruntests |
|
134 |
if __name__ == "__main__": |
|
135 |
unittest.TextTestRunner().run(makeSuite()) |
|
136 |
printLocation() |