Skip to content

Commit ca710d6

Browse files
author
mbonnefoy
committed
Add PyPDF2 as a dependency and check for pycairo before testing
1 parent 1fcfd11 commit ca710d6

2 files changed

Lines changed: 16 additions & 14 deletions

File tree

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ before_install:
7676
- pip install --upgrade --user wheel
7777
- pip install --upgrade --user twine
7878
- pip install --upgrade --user setuptools
79+
- pip install --upgrade --user PyPDF2
7980
- python --version
8081

8182
install:

test/python_tests/pdf_printing_test.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from nose.tools import eq_
66

7-
from mapnik import printing, Map, load_map
7+
import mapnik
88
from .utilities import execution_path, run_all
99

1010
def setup():
@@ -13,15 +13,15 @@ def setup():
1313
os.chdir(execution_path('.'))
1414

1515
def make_map_from_xml(source_xml):
16-
m = Map(100, 100)
17-
load_map(m, source_xml, True)
16+
m = mapnik.Map(100, 100)
17+
mapnik.load_map(m, source_xml, True)
1818
m.zoom_all()
1919

2020
return m
2121

2222
def make_pdf(m, output_pdf, esri_wkt):
2323
# renders a PDF with a grid and a legend
24-
page = printing.PDFPrinter(use_ocg_layers=True)
24+
page = mapnik.printing.PDFPrinter(use_ocg_layers=True)
2525

2626
page.render_map(m, output_pdf)
2727
page.render_grid_on_map(m)
@@ -30,19 +30,20 @@ def make_pdf(m, output_pdf, esri_wkt):
3030
page.finish()
3131
page.add_geospatial_pdf_header(m, output_pdf, wkt=esri_wkt)
3232

33-
def test_pdf_printing():
34-
source_xml = '../data/good_maps/marker-text-line.xml'.encode('utf-8')
35-
m = make_map_from_xml(source_xml)
33+
if mapnik.has_pycairo():
34+
def test_pdf_printing():
35+
source_xml = '../data/good_maps/marker-text-line.xml'.encode('utf-8')
36+
m = make_map_from_xml(source_xml)
3637

37-
actual_pdf = "/tmp/pdf-printing-actual.pdf"
38-
esri_wkt = 'GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]'
39-
make_pdf(m, actual_pdf, esri_wkt)
38+
actual_pdf = "/tmp/pdf-printing-actual.pdf"
39+
esri_wkt = 'GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]'
40+
make_pdf(m, actual_pdf, esri_wkt)
4041

41-
expected_pdf = 'images/pycairo/pdf-printing-expected.pdf'
42+
expected_pdf = 'images/pycairo/pdf-printing-expected.pdf'
4243

43-
diff = abs(os.stat(expected_pdf).st_size - os.stat(actual_pdf).st_size)
44-
msg = 'diff in size (%s) between actual (%s) and expected(%s)' % (diff, actual_pdf, 'tests/python_tests/' + expected_pdf)
45-
eq_(diff < 1500, True, msg)
44+
diff = abs(os.stat(expected_pdf).st_size - os.stat(actual_pdf).st_size)
45+
msg = 'diff in size (%s) between actual (%s) and expected(%s)' % (diff, actual_pdf, 'tests/python_tests/' + expected_pdf)
46+
eq_(diff < 1500, True, msg)
4647

4748
# TODO: ideas for further testing on printing module
4849
# - test with and without pangocairo

0 commit comments

Comments
 (0)