tests/test_platypus_pleaseturnover.py
author robin <robin@reportlab.com>
Tue, 07 Mar 2017 10:00:34 +0000
changeset 4330 617ffa6bbdc8
parent 4252 fe660f227cac
child 4630 604952d66599
permissions -rw-r--r--
changes for release 3.4.0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4330
617ffa6bbdc8 changes for release 3.4.0
robin <robin@reportlab.com>
parents: 4252
diff changeset
     1
#Copyright ReportLab Europe Ltd. 2000-2017
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
     2
#see license.txt for license details
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
     3
"""Tests pleaseTurnOver, pageBreakBefore, frameBreakBefore, keepWithNext...
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
     4
"""
4252
fe660f227cac changes for release 3.3.0
robin
parents: 3706
diff changeset
     5
__version__='3.3.0'
2984
c63f149d55aa tests.utils --> reportlab.lib.testutils
rgbecker
parents: 2967
diff changeset
     6
from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, outputfile, printLocation
c63f149d55aa tests.utils --> reportlab.lib.testutils
rgbecker
parents: 2967
diff changeset
     7
setOutDir(__name__)
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
     8
import sys
2966
c9df63ccabdf reportlab-2.2: major changes to make tests run
rgbecker
parents: 2963
diff changeset
     9
import unittest
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    10
from reportlab.platypus.flowables import Flowable, PTOContainer, KeepInFrame
3706
d468d1f4e8b7 platypus: change implementation of new FrameBG so it can be used in containers
robin
parents: 3617
diff changeset
    11
from reportlab.platypus import FrameBG
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    12
from reportlab.lib.units import cm
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    13
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    14
from reportlab.lib.colors import toColor, black
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    15
from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    16
from reportlab.platypus.paragraph import Paragraph
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    17
from reportlab.platypus.tables import Table
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    18
from reportlab.platypus.frames import Frame
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    19
from reportlab.lib.randomtext import randomText
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    20
from reportlab.platypus.doctemplate import PageTemplate, BaseDocTemplate, FrameBreak
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    21
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    22
def myMainPageFrame(canvas, doc):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    23
    "The page frame used for all PDF documents."
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    24
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    25
    canvas.saveState()
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    26
    canvas.setFont('Times-Roman', 12)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    27
    pageNumber = canvas.getPageNumber()
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    28
    canvas.drawString(10*cm, cm, str(pageNumber))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    29
    canvas.restoreState()
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    30
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    31
def _showDoc(fn,story):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    32
    pageTemplate = PageTemplate('normal', [Frame(72, 440, 170, 284, id='F1'),
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    33
                            Frame(326, 440, 170, 284, id='F2'),
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    34
                            Frame(72, 72, 170, 284, id='F3'),
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    35
                            Frame(326, 72, 170, 284, id='F4'),
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    36
                            ], myMainPageFrame)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    37
    doc = BaseDocTemplate(outputfile(fn),
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    38
            pageTemplates = pageTemplate,
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    39
            showBoundary = 1,
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    40
            )
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    41
    doc.multiBuild(story)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    42
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    43
text2 ='''We have already seen that the natural general principle that will
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    44
subsume this case cannot be arbitrary in the requirement that branching
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    45
is not tolerated within the dominance scope of a complex symbol.
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    46
Notice, incidentally, that the speaker-hearer's linguistic intuition is
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    47
to be regarded as the strong generative capacity of the theory.  A
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    48
consequence of the approach just outlined is that the descriptive power
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    49
of the base component does not affect the structure of the levels of
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    50
acceptability from fairly high (e.g. (99a)) to virtual gibberish (e.g.
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    51
(98d)).  By combining adjunctions and certain deformations, a
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    52
descriptively adequate grammar cannot be arbitrary in the strong
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    53
generative capacity of the theory.'''
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    54
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    55
text1='''
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    56
On our assumptions, a descriptively adequate grammar delimits the strong
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    57
generative capacity of the theory.  For one thing, the fundamental error
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    58
of regarding functional notions as categorial is to be regarded as a
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    59
corpus of utterance tokens upon which conformity has been defined by the
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    60
paired utterance test.  A majority  of informed linguistic specialists
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    61
agree that the appearance of parasitic gaps in domains relatively
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    62
inaccessible to ordinary extraction is necessary to impose an
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    63
interpretation on the requirement that branching is not tolerated within
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    64
the dominance scope of a complex symbol.  It may be, then, that the
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    65
speaker-hearer's linguistic intuition appears to correlate rather
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    66
closely with the ultimate standard that determines the accuracy of any
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    67
proposed grammar.  Analogously, the notion of level of grammaticalness
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    68
may remedy and, at the same time, eliminate a general convention
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    69
regarding the forms of the grammar.'''
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    70
    
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    71
text0 = '''To characterize a linguistic level L,
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    72
this selectionally introduced contextual
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    73
feature delimits the requirement that
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    74
branching is not tolerated within the
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    75
dominance scope of a complex
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    76
symbol. Notice, incidentally, that the
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    77
notion of level of grammaticalness
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    78
does not affect the structure of the
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    79
levels of acceptability from fairly high
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    80
(e.g. (99a)) to virtual gibberish (e.g.
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    81
(98d)). Suppose, for instance, that a
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    82
subset of English sentences interesting
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    83
on quite independent grounds appears
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    84
to correlate rather closely with an
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    85
important distinction in language use.
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    86
Presumably, this analysis of a
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    87
formative as a pair of sets of features is
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    88
not quite equivalent to the system of
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    89
base rules exclusive of the lexicon. We
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    90
have already seen that the appearance
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    91
of parasitic gaps in domains relatively
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    92
inaccessible to ordinary extraction
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    93
does not readily tolerate the strong
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    94
generative capacity of the theory.'''
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    95
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    96
def _ptoTestCase(self):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    97
    """PTO stands for Please Turn Over and is a means for
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    98
    specifying content to be inserted when stuff goes over a page.
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    99
    This makes one long multi-page paragraph."""
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   100
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   101
    # Build story.
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   102
    story = []
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   103
    def fbreak(story=story):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   104
        story.append(FrameBreak())
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   105
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   106
    styleSheet = getSampleStyleSheet()
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   107
    H1 = styleSheet['Heading1']
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   108
    H1.pageBreakBefore = 0
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   109
    H1.keepWithNext = 0
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   110
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   111
    bt = styleSheet['BodyText']
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   112
    pto = ParagraphStyle('pto',parent=bt)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   113
    pto.alignment = TA_RIGHT
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   114
    pto.fontSize -= 1
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   115
    def ColorParagraph(c,text,style):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   116
        return Paragraph('<para color="%s">%s</para>' % (c,text),style)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   117
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   118
    def ptoblob(blurb,content,trailer=None,header=None, story=story, H1=H1):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   119
        if type(content) not in (type([]),type(())): content = [content]
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   120
        story.append(PTOContainer([Paragraph(blurb,H1)]+list(content),trailer,header))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   121
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   122
    t0 = [ColorParagraph('blue','Please turn over', pto )]
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   123
    h0 = [ColorParagraph('blue','continued from previous page', pto )]
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   124
    t1 = [ColorParagraph('red','Please turn over(inner)', pto )]
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   125
    h1 = [ColorParagraph('red','continued from previous page(inner)', pto )]
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   126
    ptoblob('First Try at a PTO',[Paragraph(text0,bt)],t0,h0)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   127
    fbreak()
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   128
    c1 = Table([('alignment', 'align\012alignment'),
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   129
                ('bulletColor', 'bulletcolor\012bcolor'),
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   130
                ('bulletFontName', 'bfont\012bulletfontname'),
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   131
                ('bulletFontSize', 'bfontsize\012bulletfontsize'),
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   132
                ('bulletIndent', 'bindent\012bulletindent'),
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   133
                ('firstLineIndent', 'findent\012firstlineindent'),
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   134
                ('fontName', 'face\012fontname\012font'),
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   135
                ('fontSize', 'size\012fontsize'),
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   136
                ('leading', 'leading'),
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   137
                ('leftIndent', 'leftindent\012lindent'),
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   138
                ('rightIndent', 'rightindent\012rindent'),
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   139
                ('spaceAfter', 'spaceafter\012spacea'),
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   140
                ('spaceBefore', 'spacebefore\012spaceb'),
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   141
                ('textColor', 'fg\012textcolor\012color')],
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   142
            style = [
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   143
                ('VALIGN',(0,0),(-1,-1),'TOP'),
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   144
                ('INNERGRID', (0,0), (-1,-1), 0.25, black),
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   145
                ('BOX', (0,0), (-1,-1), 0.25, black),
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   146
                ],
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   147
            )
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   148
    ptoblob('PTO with a table inside',c1,t0,h0)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   149
    fbreak()
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   150
    ptoblob('A long PTO',[Paragraph(text0+' '+text1,bt)],t0,h0)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   151
    fbreak()
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   152
    ptoblob('2 PTO (inner split)',[ColorParagraph('pink',text0,bt),PTOContainer([ColorParagraph(black,'Inner Starts',H1),ColorParagraph('yellow',text2,bt),ColorParagraph('black','Inner Ends',H1)],t1,h1),ColorParagraph('magenta',text1,bt)],t0,h0)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   153
    _showDoc('test_platypus_pto.pdf',story)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   154
3183
859ea04ea21a test_platypus_pleaseturnover.py: new tests for justifying KeepInFrame
rgbecker
parents: 2984
diff changeset
   155
def _KeepInFrameTestCase(self,mode,offset=0):
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   156
    story = []
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   157
    def fbreak(story=story):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   158
        story.append(FrameBreak())
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   159
    styleSheet = getSampleStyleSheet()
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   160
    H1 = styleSheet['Heading1']
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   161
    H1.pageBreakBefore = 0
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   162
    H1.keepWithNext = 0
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   163
    bt = styleSheet['BodyText']
3706
d468d1f4e8b7 platypus: change implementation of new FrameBG so it can be used in containers
robin
parents: 3617
diff changeset
   164
    def subStory(texts,fbg=0):
3183
859ea04ea21a test_platypus_pleaseturnover.py: new tests for justifying KeepInFrame
rgbecker
parents: 2984
diff changeset
   165
        style = [
859ea04ea21a test_platypus_pleaseturnover.py: new tests for justifying KeepInFrame
rgbecker
parents: 2984
diff changeset
   166
            ('VALIGN',(0,0),(-1,-1),'TOP'),
859ea04ea21a test_platypus_pleaseturnover.py: new tests for justifying KeepInFrame
rgbecker
parents: 2984
diff changeset
   167
            ('INNERGRID', (0,0), (-1,-1), 0.25, black),
859ea04ea21a test_platypus_pleaseturnover.py: new tests for justifying KeepInFrame
rgbecker
parents: 2984
diff changeset
   168
            ('BOX', (0,0), (-1,-1), 0.25, black),
859ea04ea21a test_platypus_pleaseturnover.py: new tests for justifying KeepInFrame
rgbecker
parents: 2984
diff changeset
   169
            ]
3706
d468d1f4e8b7 platypus: change implementation of new FrameBG so it can be used in containers
robin
parents: 3617
diff changeset
   170
        if fbg:
d468d1f4e8b7 platypus: change implementation of new FrameBG so it can be used in containers
robin
parents: 3617
diff changeset
   171
            fbg1 = [FrameBG(start=0,color=toColor('limegreen'))]
d468d1f4e8b7 platypus: change implementation of new FrameBG so it can be used in containers
robin
parents: 3617
diff changeset
   172
            fbg0 = [FrameBG(start=0)]
d468d1f4e8b7 platypus: change implementation of new FrameBG so it can be used in containers
robin
parents: 3617
diff changeset
   173
        else:
d468d1f4e8b7 platypus: change implementation of new FrameBG so it can be used in containers
robin
parents: 3617
diff changeset
   174
            fbg0 = fbg1 = []
3183
859ea04ea21a test_platypus_pleaseturnover.py: new tests for justifying KeepInFrame
rgbecker
parents: 2984
diff changeset
   175
        return ([Paragraph(t,bt) for t in texts]
3706
d468d1f4e8b7 platypus: change implementation of new FrameBG so it can be used in containers
robin
parents: 3617
diff changeset
   176
                +fbg1+[Table([('alignment', a.lower())],style = style,hAlign=a)
d468d1f4e8b7 platypus: change implementation of new FrameBG so it can be used in containers
robin
parents: 3617
diff changeset
   177
                    for a in ('LEFT','RIGHT','CENTER')]+fbg0)
3183
859ea04ea21a test_platypus_pleaseturnover.py: new tests for justifying KeepInFrame
rgbecker
parents: 2984
diff changeset
   178
    def allModesKIF(just,ifb=True,width=170):
859ea04ea21a test_platypus_pleaseturnover.py: new tests for justifying KeepInFrame
rgbecker
parents: 2984
diff changeset
   179
        if ifb: fbreak()
859ea04ea21a test_platypus_pleaseturnover.py: new tests for justifying KeepInFrame
rgbecker
parents: 2984
diff changeset
   180
        story.append(KeepInFrame(width-offset,284-offset,subStory(texts=(text0,)),mode=mode,hAlign=just))
859ea04ea21a test_platypus_pleaseturnover.py: new tests for justifying KeepInFrame
rgbecker
parents: 2984
diff changeset
   181
        fbreak()
859ea04ea21a test_platypus_pleaseturnover.py: new tests for justifying KeepInFrame
rgbecker
parents: 2984
diff changeset
   182
        story.append(KeepInFrame(width-offset,284-offset,subStory(texts=(text0,text1)),mode=mode,hAlign=just))
859ea04ea21a test_platypus_pleaseturnover.py: new tests for justifying KeepInFrame
rgbecker
parents: 2984
diff changeset
   183
        fbreak()
859ea04ea21a test_platypus_pleaseturnover.py: new tests for justifying KeepInFrame
rgbecker
parents: 2984
diff changeset
   184
        story.append(KeepInFrame(width-offset,284-offset,subStory(texts=(text0,text1,text2)),mode=mode,hAlign=just))
3706
d468d1f4e8b7 platypus: change implementation of new FrameBG so it can be used in containers
robin
parents: 3617
diff changeset
   185
        fbreak()
d468d1f4e8b7 platypus: change implementation of new FrameBG so it can be used in containers
robin
parents: 3617
diff changeset
   186
        story.append(KeepInFrame(width-offset,284-offset,subStory(texts=(text0,text1,text2),fbg=1),mode=mode,hAlign=just))
3183
859ea04ea21a test_platypus_pleaseturnover.py: new tests for justifying KeepInFrame
rgbecker
parents: 2984
diff changeset
   187
    allModesKIF('LEFT',False)
859ea04ea21a test_platypus_pleaseturnover.py: new tests for justifying KeepInFrame
rgbecker
parents: 2984
diff changeset
   188
    allModesKIF('LEFT',width=100)
859ea04ea21a test_platypus_pleaseturnover.py: new tests for justifying KeepInFrame
rgbecker
parents: 2984
diff changeset
   189
    allModesKIF('CENTRE',width=100)
859ea04ea21a test_platypus_pleaseturnover.py: new tests for justifying KeepInFrame
rgbecker
parents: 2984
diff changeset
   190
    allModesKIF('RIGHT',width=100)
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   191
    _showDoc('test_platypus_KeepInFrame%s.pdf'%mode,story)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   192
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   193
class TestCases(unittest.TestCase):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   194
    "Test multi-page splitting of paragraphs (eyeball-test)."
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   195
    def test0(self):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   196
        _ptoTestCase(self)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   197
    def test1(self):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   198
        _KeepInFrameTestCase(self,mode="shrink")
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   199
    def test2(self):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   200
        _KeepInFrameTestCase(self,mode="overflow")
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   201
    def test3(self):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   202
        _KeepInFrameTestCase(self,mode="truncate")
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   203
    def test4(self):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   204
        from reportlab.platypus.doctemplate import LayoutError
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   205
        self.assertRaises(LayoutError, _KeepInFrameTestCase,*(self,"error"))
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   206
    def test5(self):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   207
        _KeepInFrameTestCase(self,"shrink",0)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   208
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   209
def makeSuite():
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   210
    return makeSuiteForClasses(TestCases)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   211
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   212
#noruntests
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   213
if __name__ == "__main__": #NORUNTESTS
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   214
    if 'debug' in sys.argv:
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   215
        _KeepInFrameTestCase(None)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   216
    else:
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   217
        unittest.TextTestRunner().run(makeSuite())
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   218
        printLocation()