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
|
2963
|
9 |
|
|
10 |
class FmtTestCase(unittest.TestCase):
|
|
11 |
|
|
12 |
def testFmt(self):
|
|
13 |
from reportlab.lib.utils import FmtSelfDict
|
|
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 |
|
|
28 |
|
|
29 |
def makeSuite():
|
|
30 |
return makeSuiteForClasses(FmtTestCase)
|
|
31 |
|
|
32 |
|
|
33 |
#noruntests
|
|
34 |
if __name__ == "__main__":
|
|
35 |
unittest.TextTestRunner().run(makeSuite())
|
|
36 |
printLocation()
|