Skip to content

Commit 3badb4d

Browse files
committed
Merge pull request #26 from pmaupin/tests
Make all tests run on TravisCI:
2 parents bb62767 + 0e37850 commit 3badb4d

10 files changed

+53
-32
lines changed

.travis.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@ before_install:
1010
- "git clone https://github.com/pmaupin/static_pdfs tests/static_pdfs"
1111
install:
1212
- "pip install ."
13+
- "pip install reportlab || true"
14+
- "pip install zlib || true"
15+
- "pip install unittest2 || true"
1316
# command to run tests
14-
script: "cd tests; py.test"
17+
script: "cd tests; /usr/bin/env PYTHONPATH=. py.test"

examples/rl1/4up.py

-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
import sys
1414
import os
1515

16-
import invariant
17-
1816
from reportlab.pdfgen.canvas import Canvas
1917

2018
from pdfrw import PdfReader

examples/rl1/booklet.py

-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
import sys
1414
import os
1515

16-
import invariant
17-
1816
from reportlab.pdfgen.canvas import Canvas
1917

2018
from pdfrw import PdfReader

examples/rl1/invariant.py

-6
This file was deleted.

examples/rl1/platypus_pdf_template.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
import sys
1515
import os
1616

17-
import invariant
18-
1917
from reportlab.platypus import PageTemplate, BaseDocTemplate, Frame
2018
from reportlab.platypus import NextPageTemplate, Paragraph, PageBreak
2119
from reportlab.platypus.tableofcontents import TableOfContents
@@ -87,7 +85,7 @@ def create_toc():
8785

8886
def create_pdf(filename, pdf_template_filename):
8987
"""Create the pdf, with all the contents"""
90-
pdf_report = open(filename, "w")
88+
pdf_report = open(filename, "wb")
9189
document = MyDocTemplate(pdf_report)
9290
templates = [MyTemplate(pdf_template_filename, name='background')]
9391
document.addPageTemplates(templates)

examples/rl1/subset.py

-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
import sys
1616
import os
1717

18-
import invariant
19-
2018
from reportlab.pdfgen.canvas import Canvas
2119

2220
from pdfrw import PdfReader

pdfrw/objects/pdfstring.py

-4
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ def decode(self, remap=chr, twobytes=False):
6767

6868
def encode(cls, source, usehex=False):
6969
assert not usehex, "Not supported yet"
70-
if isinstance(source, unicode):
71-
source = source.encode('utf-8')
72-
else:
73-
source = str(source)
7470
source = source.replace('\\', '\\\\')
7571
source = source.replace('(', '\\(')
7672
source = source.replace(')', '\\)')

tests/expected.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ examples/subset_1975ef8db7355b1d691bc79d0749574b_21 5057f345f1a1109a0e54276a
2020
examples/rotate_5057f345f1a1109a0e54276a68e8f8df_90_1 881f4dc8dcf069e707bf61af95492d86
2121
examples/poster_881f4dc8dcf069e707bf61af95492d86 a34be06d22105b6c02394a9f278fec0d
2222

23-
examples/rl1/platypus_pdf_template_b1c400de699af29ea3f1983bb26870ab ec98c37e11441ee3b24e79006f6327c4
24-
examples/rl1/4up_b1c400de699af29ea3f1983bb26870ab 3fbc6062ddd008a61f11ade2434336f1
25-
examples/rl1/booklet_b1c400de699af29ea3f1983bb26870ab 997130df3da157a19be0024143402bc5
26-
examples/rl1/subset_b1c400de699af29ea3f1983bb26870ab_3_5 7bbea500c5af6f19f468efb12c375c47
23+
examples/rl1/4up_b1c400de699af29ea3f1983bb26870ab 959d6246ad8bda72bd023e8681216d17
24+
examples/rl1/booklet_b1c400de699af29ea3f1983bb26870ab 45b4ae29a038271896b7264bbed63bdf
25+
examples/rl1/subset_b1c400de699af29ea3f1983bb26870ab_3_5 822bce1cb9e053f1f3f6b922bf27fab8
26+
examples/rl1/platypus_pdf_template_b1c400de699af29ea3f1983bb26870ab 97ad6a8ca3fe7cc4e1f0ffb8475355e9
2727

2828
# List things that need work here (typically cause exceptions)
2929

tests/test_examples.py

+39-7
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,21 @@
2727
2828
2929
'''
30+
import sys
3031
import os
31-
import unittest
3232
import hashlib
3333
import subprocess
3434
import static_pdfs
3535
import expected
3636

3737
from pdfrw.py23_diffs import convert_store
38+
from pdfrw import PdfReader, PdfWriter
39+
40+
try:
41+
import unittest2 as unittest
42+
except ImportError:
43+
import unittest
44+
3845

3946
prog_dir = os.path.join(expected.root_dir, '..', 'examples', '%s.py')
4047
prog_dir = os.path.abspath(prog_dir)
@@ -47,19 +54,22 @@
4754

4855
class TestOnePdf(unittest.TestCase):
4956

50-
def do_test(self, params, prev_results=['']):
57+
def do_test(self, params, prev_results=[''], scrub=False):
5158
params = params.split()
5259
hashkey = 'examples/%s' % '_'.join(params)
5360
params = [lookup.get(x, x) for x in params]
5461
progname = params[0]
5562
params[0] = prog_dir % progname
5663
srcf = params[1]
64+
params.insert(0, sys.executable)
5765
subdir, progname = os.path.split(progname)
5866
subdir = os.path.join(dstdir, subdir)
5967
if not os.path.exists(subdir):
6068
os.makedirs(subdir)
6169
os.chdir(subdir)
6270
dstf = '%s.%s' % (progname, os.path.basename(srcf))
71+
scrub = scrub and dstf
72+
dstf = dstf if not scrub else 'final.%s' % dstf
6373
hash = '------no-file-generated---------'
6474
expects = expected.results[hashkey]
6575

@@ -82,7 +92,11 @@ def do_test(self, params, prev_results=['']):
8292
if expects or not exists:
8393
if exists:
8494
os.remove(dstf)
95+
if scrub and os.path.exists(scrub):
96+
os.remove(scrub)
8597
subprocess.call(params)
98+
if scrub:
99+
PdfWriter().addpages(PdfReader(scrub).pages).write(dstf)
86100
with open(dstf, 'rb') as f:
87101
data = f.read()
88102
size = len(data)
@@ -150,11 +164,29 @@ def test_extract(self):
150164
self.do_test('extract 1975ef8db7355b1d691bc79d0749574b')
151165
self.do_test('extract c5c895deecf7a7565393587e0d61be2b')
152166

153-
def test_rl1(self):
154-
self.do_test('rl1/platypus_pdf_template b1c400de699af29ea3f1983bb26870ab')
155-
self.do_test('rl1/4up b1c400de699af29ea3f1983bb26870ab')
156-
self.do_test('rl1/booklet b1c400de699af29ea3f1983bb26870ab')
157-
self.do_test('rl1/subset b1c400de699af29ea3f1983bb26870ab 3 5')
167+
def test_rl1_4up(self):
168+
if sys.version_info < (2, 7):
169+
return
170+
self.do_test('rl1/4up b1c400de699af29ea3f1983bb26870ab',
171+
scrub=True)
172+
173+
def test_rl1_booklet(self):
174+
if sys.version_info < (2, 7):
175+
return
176+
self.do_test('rl1/booklet b1c400de699af29ea3f1983bb26870ab',
177+
scrub=True)
178+
179+
def test_rl1_subset(self):
180+
if sys.version_info < (2, 7):
181+
return
182+
self.do_test('rl1/subset b1c400de699af29ea3f1983bb26870ab 3 5',
183+
scrub=True)
184+
185+
def test_rl1_platypus(self):
186+
if sys.version_info < (2, 7):
187+
return
188+
self.do_test('rl1/platypus_pdf_template b1c400de699af29ea3f1983bb26870ab',
189+
scrub=True)
158190

159191
def main():
160192
unittest.main()

tests/test_roundtrip.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,18 @@
2828
2929
'''
3030
import os
31-
import unittest
3231
import hashlib
3332
import pdfrw
3433
import static_pdfs
3534
import expected
3635

3736
from pdfrw.py23_diffs import convert_store
3837

38+
try:
39+
import unittest2 as unittest
40+
except ImportError:
41+
import unittest
42+
3943

4044
class TestOnePdf(unittest.TestCase):
4145

0 commit comments

Comments
 (0)