~ubuntu-branches/ubuntu/vivid/python-reportlab/vivid-proposed

« back to all changes in this revision

Viewing changes to tests/test_platypus_paragraphs.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2014-01-12 02:16:21 UTC
  • mfrom: (1.2.9) (4.1.9 sid)
  • Revision ID: package-import@ubuntu.com-20140112021621-f4mpp5qaj1dkq2yb
Tags: 2.8~20140112-1
* New upstream snapshot.
* Build python3 packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
#see license.txt for license details
3
3
"""Tests for the reportlab.platypus.paragraphs module.
4
4
"""
5
 
__version__=''' $Id: test_platypus_paragraphs.py 3959 2012-09-27 14:39:39Z robin $ '''
 
5
__version__=''' $Id$ '''
6
6
from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, outputfile, printLocation
7
7
setOutDir(__name__)
8
8
import sys, os, unittest
9
 
from string import split, strip, join, whitespace
10
9
from operator import truth
11
 
from types import StringType, ListType
12
10
from reportlab.pdfbase.pdfmetrics import stringWidth, registerFont, registerFontFamily
13
11
from reportlab.pdfbase.ttfonts import TTFont
14
12
from reportlab.platypus.paraparser import ParaParser
171
169
        gif = os.path.join(testsFolder,'pythonpowered.gif')
172
170
        story.append(ParagraphAndImage(Paragraph(text,bt),Image(gif)))
173
171
        phrase = 'This should be a paragraph spanning at least three pages. '
174
 
        description = ''.join([('%d: '%i)+phrase for i in xrange(250)])
 
172
        description = ''.join([('%d: '%i)+phrase for i in range(250)])
175
173
        story.append(ParagraphAndImage(Paragraph(description, bt),Image(gif),side='left'))
176
174
 
177
175
        doc = MyDocTemplate(outputfile('test_platypus_paragraphandimage.pdf'))
201
199
u with a dieresis on top &lt;unichar code=0xfc/&gt;="<unichar code="0xfc"/>" and this &amp;#xfc;="&#xfc;" and this \\xc3\\xbc="\xc3\xbc". On the other hand this
202
200
should be a pound sign &amp;pound;="&pound;" and this an alpha &amp;alpha;="&alpha;". You can have links in the page <link href="http://www.reportlab.com" color="blue">ReportLab</link> &amp; <a href="http://www.reportlab.org" color="green">ReportLab.org</a>.
203
201
Use scheme "pdf:" to indicate an external PDF link, "http:", "https:" to indicate an external link eg something to open in
204
 
your browser. If an internal link begins with something that looks like a scheme, precede with "document:". <strike>This text should have a strike through it.</strike>
 
202
your browser. If an internal link begins with something that looks like a scheme, precede with "document:". Empty hrefs should be allowed ie <a href="">&lt;a href=""&gt;test&lt;/a&gt;</a> should be allowed. <strike>This text should have a strike through it.</strike>
205
203
'''
206
204
        from reportlab.platypus.flowables import ImageAndFlowables, Image
207
205
        from reportlab.lib.testutils import testsFolder
209
207
        heading = Paragraph('This is a heading',h3)
210
208
        story.append(ImageAndFlowables(Image(gif),[heading,Paragraph(text,bt)]))
211
209
        phrase = 'This should be a paragraph spanning at least three pages. '
212
 
        description = ''.join([('%d: '%i)+phrase for i in xrange(250)])
 
210
        description = ''.join([('%d: '%i)+phrase for i in range(250)])
213
211
        story.append(ImageAndFlowables(Image(gif),[heading,Paragraph(description, bt)],imageSide='left'))
214
212
        story.append(NextPageTemplate('special'))
215
213
        story.append(PageBreak())
350
348
        B = styleSheet['BodyText']
351
349
        text = ''
352
350
        P = Paragraph(text, B)
353
 
        frags = map(lambda f:f.text, P.frags)
 
351
        frags = [f.text for f in P.frags]
354
352
        assert frags == []
355
353
 
356
354
    def test1(self):
360
358
        B = styleSheet['BodyText']
361
359
        text = "X<font name=Courier>Y</font>Z"
362
360
        P = Paragraph(text, B)
363
 
        frags = map(lambda f:f.text, P.frags)
 
361
        frags = [f.text for f in P.frags]
364
362
        assert frags == ['X', 'Y', 'Z']
365
363
 
366
364
class ULTestCase(unittest.TestCase):
414
412
                text0 = text0.replace('English sentences','<b>English sentences</b>').replace('quite equivalent','<i>quite equivalent</i>')
415
413
                text1 = text1.replace('the methodological work','<b>the methodological work</b>').replace('to impose problems','<i>to impose problems</i>')
416
414
            for t in ('u','strike'):
417
 
                for n in xrange(6):
 
415
                for n in range(6):
418
416
                    for s in (normal,normal_center,normal_right,normal_just,normal_indent, normal_indent_lv_2):
419
417
                        for autoLeading in ('','min','max'):
420
418
                            if n==4 and s==normal_center and t=='strike' and mode==1:
579
577
            elif mode==4:
580
578
                text = text.replace('English ','English&nbsp;').replace('quite ','quite&nbsp;')
581
579
                text = text.replace(' methodological','&nbsp;methodological').replace(' impose','&nbsp;impose')
582
 
                a(Paragraph('Justified paragraph in normal font & some hard spaces',style=normal))
 
580
                a(Paragraph('Justified paragraph in normal font &amp; some hard spaces',style=normal))
583
581
            else:
584
582
                a(Paragraph('Justified paragraph in normal font',style=normal))
585
583