File: test_pdfgen_pagemodes.py

package info (click to toggle)
python-reportlab 3.1.8-3%2Bdeb8u1
  • links: PTS
  • area: main
  • in suites: jessie
  • size: 6,996 kB
  • ctags: 9,483
  • sloc: python: 69,727; ansic: 19,108; xml: 1,494; makefile: 416; java: 193; sh: 100
file content (65 lines) | stat: -rw-r--r-- 1,853 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#Copyright ReportLab Europe Ltd. 2000-2012
#see license.txt for license details
# full screen test
"""Tests for PDF page modes support in reportlab.pdfgen.
"""
__version__='''$Id$'''
from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, outputfile, printLocation
setOutDir(__name__)
import os
import unittest
from reportlab.pdfgen.canvas import Canvas

def fileDoesExist(path):
    "Check if a file does exist."
    return os.path.exists(path)


class PdfPageModeTestCase(unittest.TestCase):
    "Testing different page modes for opening a file in Acrobat Reader."

    baseFileName = 'test_pagemodes_'

    def _doTest(self, filename, mode, desc):
        "A generic method called by all test real methods."

        filename = outputfile(self.baseFileName + filename)
        c = Canvas(filename)

        # Handle different modes.
        if mode == 'FullScreen':
            c.showFullScreen0()
        elif mode == 'Outline':
            c.bookmarkPage('page1')
            c.addOutlineEntry('Token Outline Entry', 'page1')
            c.showOutline()
        elif mode == 'UseNone':
            pass

        c.setFont('Helvetica', 20)
        c.drawString(100, 700, desc)
        c.save()

        assert fileDoesExist(filename)


    def test0(self):
        "This should open in full screen mode."
        self._doTest('FullScreen.pdf', 'FullScreen', self.test0.__doc__)

    def test1(self):
        "This should open with outline visible."
        self._doTest('Outline.pdf', 'Outline', self.test1.__doc__)

    def test2(self):
        "This should open in the user's default mode."
        self._doTest('UseNone.pdf', 'UseNone', self.test2.__doc__)

def makeSuite():
    return makeSuiteForClasses(PdfPageModeTestCase)


#noruntests
if __name__ == "__main__":
    unittest.TextTestRunner().run(makeSuite())
    printLocation()