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
|
#Copyright ReportLab Europe Ltd. 2000-2016
#see license.txt for license details
"""Tests for the reportlab.lib.sequencer module.
"""
__version__='3.3.0'
from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, printLocation
setOutDir(__name__)
import sys, random
import unittest
from reportlab.lib.sequencer import Sequencer
class SequencerTestCase(unittest.TestCase):
"Test Sequencer usage."
def test0(self):
"Test sequencer default counter."
seq = Sequencer()
msg = 'Initial value is not zero!'
assert seq._this() == 0, msg
def test1(self):
"Test incrementing default counter."
seq = Sequencer()
for i in range(1, 101):
n = seq.next()
msg = 'Sequence value is not correct!'
assert seq._this() == n, msg
def test2(self):
"Test resetting default counter."
seq = Sequencer()
start = seq._this()
for i in range(1, 101):
n = seq.next()
seq.reset()
msg = 'Sequence value not correctly reset!'
assert seq._this() == start, msg
def test3(self):
"Test incrementing dedicated counter."
seq = Sequencer()
for i in range(1, 101):
n = seq.next('myCounter1')
msg = 'Sequence value is not correct!'
assert seq._this('myCounter1') == n, msg
def test4(self):
"Test resetting dedicated counter."
seq = Sequencer()
start = seq._this('myCounter1')
for i in range(1, 101):
n = seq.next('myCounter1')
seq.reset('myCounter1')
msg = 'Sequence value not correctly reset!'
assert seq._this('myCounter1') == start, msg
def test5(self):
"Test incrementing multiple dedicated counters."
seq = Sequencer()
startMyCounter0 = seq._this('myCounter0')
startMyCounter1 = seq._this('myCounter1')
for i in range(1, 101):
n = seq.next('myCounter0')
msg = 'Sequence value is not correct!'
assert seq._this('myCounter0') == n, msg
m = seq.next('myCounter1')
msg = 'Sequence value is not correct!'
assert seq._this('myCounter1') == m, msg
def testChain(self):
"Test auto resetting of subsections"
seq = Sequencer()
seq.chain('h1', 'h2') #creates them and links
self.assertEquals(seq.next('h1'), 1)
self.assertEquals(seq.next('h1'), 2)
self.assertEquals(seq.next('h2'), 1)
self.assertEquals(seq.next('h2'), 2)
self.assertEquals(seq.next('h2'), 3)
#start chapter 3
self.assertEquals(seq.next('h1'), 3)
#...and the first section should be numbered 1, not 4
self.assertEquals(seq.next('h2'), 1)
## def testRandom(self):
## "Test randomly manipulating multiple dedicated counters."
##
## seq = Sequencer()
## counterNames = ['c0', 'c1', 'c2', 'c3']
##
## # Init.
## for cn in counterNames:
## setattr(self, cn, seq._this(cn))
## msg = 'Counter start value is not correct!'
## assert seq._this(cn) == 0, msg
##
## # Increment/decrement.
## for i in range(1, 101):
## n = seq.next('myCounter0')
## msg = 'Sequence value is not correct!'
## assert seq._this('myCounter0') == n, msg
## m = seq.next('myCounter1')
## msg = 'Sequence value is not correct!'
## assert seq._this('myCounter1') == m, msg
def makeSuite():
return makeSuiteForClasses(SequencerTestCase)
#noruntests
if __name__ == "__main__":
unittest.TextTestRunner().run(makeSuite())
printLocation()
|