44
55from nose .tools import eq_
66
7- from mapnik import printing , Map , load_map
7+ import mapnik
88from .utilities import execution_path , run_all
99
1010def setup ():
@@ -13,15 +13,15 @@ def setup():
1313 os .chdir (execution_path ('.' ))
1414
1515def 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
2222def 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