@@ -20,29 +20,34 @@ def make_map_from_xml(source_xml):
2020 return m
2121
2222def make_pdf (m , output_pdf , esri_wkt ):
23+ # renders a PDF with a grid and a legend
2324 page = printing .PDFPrinter (use_ocg_layers = True )
25+
2426 page .render_map (m , output_pdf )
25- page .render_on_map_scale (m )
26- # page.render_on_map_lat_lon_grid(m) # FIXME. to be tested has a few problems
27+ page .render_grid_on_map (m )
2728 page .render_legend (m )
28- ctx = page .get_cairo_context ()
29- page .render_scale (m , ctx )
29+
3030 page .finish ()
3131 page .add_geospatial_pdf_header (m , output_pdf , wkt = esri_wkt )
3232
3333def test_pdf_printing ():
34- # TODO: make this a proper test once refactoring is over
35- # source_xml = '../data/good_maps/marker-text-line.xml'.encode('utf-8')
36- source_xml = "../data/good_maps/agg_poly_gamma_map.xml" .encode ("utf-8" )
34+ source_xml = '../data/good_maps/marker-text-line.xml' .encode ('utf-8' )
3735 m = make_map_from_xml (source_xml )
3836
39- output_pdf = "/tmp/pdf_printing_test-test_pdf_printing .pdf"
37+ actual_pdf = "/tmp/pdf-printing-actual .pdf"
4038 esri_wkt = 'GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]'
41- make_pdf (m , output_pdf , esri_wkt )
39+ make_pdf (m , actual_pdf , esri_wkt )
40+
41+ expected_pdf = 'images/pycairo/pdf-printing-expected.pdf'
42+
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 )
4246
43- # TODO: compare against expected PDF once finished
44- # TODO: test with and without pangocairo
45- # TODO: test legend with attibution
47+ # TODO: ideas for further testing on printing module
48+ # - test with and without pangocairo
49+ # - test legend with attribution
50+ # - test graticule (bug at the moment)
4651
4752if __name__ == "__main__" :
4853 setup ()
0 commit comments