author | rgbecker |
Fri, 21 Jul 2006 12:44:40 +0000 | |
changeset 2664 | c9faa3a99e93 |
parent 2663 | 927cc273c5a5 |
child 2724 | 3ddade273440 |
permissions | -rw-r--r-- |
2577 | 1 |
#!/bin/env python |
2 |
#Copyright ReportLab Europe Ltd. 2000-2004 |
|
3 |
#see license.txt for license details |
|
4 |
#history TBC |
|
5 |
#$Header$ |
|
6 |
__version__=''' $Id''' |
|
7 |
__doc__="""Tests of intra-paragraph parsing behaviour in Platypus.""" |
|
8 |
||
9 |
from types import TupleType, ListType, StringType, UnicodeType |
|
10 |
from pprint import pprint as pp |
|
11 |
||
12 |
from reportlab.test import unittest |
|
13 |
from reportlab.test.utils import makeSuiteForClasses, outputfile |
|
14 |
from reportlab.platypus import cleanBlockQuotedText |
|
15 |
from reportlab.platypus.paraparser import ParaParser, ParaFrag |
|
16 |
from reportlab.lib.colors import black |
|
17 |
||
18 |
class ParaParserTestCase(unittest.TestCase): |
|
19 |
"""Tests of data structures created by paragraph parser. Esp. ability |
|
20 |
to accept unicode and preserve it""" |
|
21 |
||
22 |
def setUp(self): |
|
23 |
style=ParaFrag() |
|
24 |
style.fontName='Times-Roman' |
|
25 |
style.fontSize = 12 |
|
26 |
style.textColor = black |
|
27 |
style.bulletFontName = black |
|
28 |
style.bulletFontName='Times-Roman' |
|
29 |
style.bulletFontSize=12 |
|
30 |
self.style = style |
|
31 |
||
32 |
def testPlain(self): |
|
33 |
txt = "Hello World" |
|
34 |
stuff = ParaParser().parse(txt, self.style) |
|
35 |
assert type(stuff) is TupleType |
|
36 |
assert len(stuff) == 3 |
|
37 |
assert stuff[1][0].text == 'Hello World' |
|
38 |
||
39 |
def testBold(self): |
|
40 |
txt = "Hello <b>Bold</b> World" |
|
41 |
fragList = ParaParser().parse(txt, self.style)[1] |
|
42 |
self.assertEquals(map(lambda x:x.text, fragList), ['Hello ','Bold',' World']) |
|
43 |
self.assertEquals(fragList[1].fontName, 'Times-Bold') |
|
44 |
||
45 |
def testEntity(self): |
|
46 |
"Numeric entities should be unescaped by parser" |
|
47 |
txt = "Hello © copyright" |
|
48 |
fragList = ParaParser().parse(txt, self.style)[1] |
|
49 |
self.assertEquals(map(lambda x:x.text, fragList), ['Hello ','\xc2\xa9',' copyright']) |
|
50 |
||
51 |
def testEscaped(self): |
|
52 |
"Escaped high-bit stuff should go straight through" |
|
53 |
txt = "Hello \xc2\xa9 copyright" |
|
54 |
fragList = ParaParser().parse(txt, self.style)[1] |
|
55 |
assert fragList[0].text == txt |
|
56 |
||
57 |
def testPlainUnicode(self): |
|
58 |
"See if simple unicode goes through" |
|
59 |
txt = u"Hello World" |
|
60 |
stuff = ParaParser().parse(txt, self.style) |
|
61 |
assert type(stuff) is TupleType |
|
62 |
assert len(stuff) == 3 |
|
63 |
assert stuff[1][0].text == u'Hello World' |
|
64 |
||
65 |
def testBoldUnicode(self): |
|
66 |
txt = u"Hello <b>Bold</b> World" |
|
67 |
fragList = ParaParser().parse(txt, self.style)[1] |
|
68 |
self.assertEquals(map(lambda x:x.text, fragList), [u'Hello ',u'Bold',u' World']) |
|
69 |
self.assertEquals(fragList[1].fontName, 'Times-Bold') |
|
70 |
||
71 |
def testEntityUnicode(self): |
|
72 |
"Numeric entities should be unescaped by parser" |
|
73 |
txt = u"Hello © copyright" |
|
74 |
fragList = ParaParser().parse(txt, self.style)[1] |
|
2647
eef0f4184eb6
reportlab/text: fix encoding busted paraparser test
rgbecker
parents:
2577
diff
changeset
|
75 |
self.assertEquals(map(lambda x:x.text, fragList), [u'Hello ',u'\xa9',u' copyright']) |
2577 | 76 |
|
77 |
def testEscapedUnicode(self): |
|
78 |
"Escaped high-bit stuff should go straight through" |
|
79 |
txt = u"Hello \xa9 copyright" |
|
80 |
fragList = ParaParser().parse(txt, self.style)[1] |
|
81 |
assert fragList[0].text == txt |
|
82 |
||
2663 | 83 |
def testBr(self): |
84 |
txt = u"Hello <br/> World" |
|
85 |
fragList = ParaParser().parse(txt, self.style)[1] |
|
2664 | 86 |
self.assertEquals(map(lambda x:x.text, fragList), [u'Hello ',u'',u' World']) |
87 |
self.assertEquals(fragList[1].lineBreak, True) |
|
2577 | 88 |
|
89 |
def makeSuite(): |
|
90 |
return makeSuiteForClasses(ParaParserTestCase) |
|
91 |
||
92 |
||
93 |
#noruntests |
|
94 |
if __name__ == "__main__": |
|
95 |
unittest.TextTestRunner().run(makeSuite()) |