author | robin |
Wed, 27 Nov 2013 16:36:22 +0000 | |
branch | py33 |
changeset 3852 | 8318d362cddf |
parent 3617 | ae5744e97c42 |
child 4252 | fe660f227cac |
permissions | -rw-r--r-- |
2963 | 1 |
#!/bin/env python |
3617 | 2 |
#Copyright ReportLab Europe Ltd. 2000-2012 |
2963 | 3 |
#see license.txt for license details |
4 |
__version__='''$Id$''' |
|
5 |
__doc__="""Test reportlab.lib.util module""" |
|
2984 | 6 |
from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, outputfile, printLocation |
7 |
setOutDir(__name__) |
|
2966 | 8 |
import unittest |
3852
8318d362cddf
test_utils.py: add test of encode/decode_label functions
robin
parents:
3617
diff
changeset
|
9 |
from reportlab.lib.utils import FmtSelfDict, encode_label, decode_label |
2963 | 10 |
|
11 |
class FmtTestCase(unittest.TestCase): |
|
12 |
||
13 |
def testFmt(self): |
|
14 |
class MixedIn(FmtSelfDict): |
|
15 |
def __init__(self): |
|
16 |
self.a = 'AA' |
|
17 |
self._b = '_BB' |
|
18 |
self.d = '(overridden)' |
|
19 |
obj = MixedIn() |
|
20 |
self.assertEqual('blah', obj._fmt('blah')) |
|
21 |
self.assertEqual('blah %', obj._fmt('blah %%')) |
|
22 |
self.assertRaises(ValueError, obj._fmt, 'blah %') |
|
23 |
self.assertEqual( |
|
24 |
'moon AA june_BB spoon %(a)sCC ni', |
|
25 |
obj._fmt('moon %(a)s june%(_b)s spoon %%(a)s%(c)s %(d)s', c='CC', C='boon', d='ni')) |
|
26 |
self.assertRaises(AttributeError, obj._fmt, '%(c)s') # XXX bit weird, can this be changed? |
|
27 |
||
3852
8318d362cddf
test_utils.py: add test of encode/decode_label functions
robin
parents:
3617
diff
changeset
|
28 |
def testLabelCoding(self): |
8318d362cddf
test_utils.py: add test of encode/decode_label functions
robin
parents:
3617
diff
changeset
|
29 |
a = (1,2,[3,4],"a"), [1,2,"4",b'4'] |
8318d362cddf
test_utils.py: add test of encode/decode_label functions
robin
parents:
3617
diff
changeset
|
30 |
assert a == decode_label(encode_label(a)) |
2963 | 31 |
|
32 |
def makeSuite(): |
|
33 |
return makeSuiteForClasses(FmtTestCase) |
|
34 |
||
35 |
||
36 |
#noruntests |
|
37 |
if __name__ == "__main__": |
|
38 |
unittest.TextTestRunner().run(makeSuite()) |
|
39 |
printLocation() |