2012-01-08 15:01:54 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2014-07-25 03:58:03 +02:00
|
|
|
import sys
|
2014-07-25 20:49:05 +02:00
|
|
|
import mapnik
|
2014-08-05 04:18:38 +02:00
|
|
|
#mapnik.logger.set_severity(mapnik.severity_type.None)
|
2014-08-03 21:27:55 +02:00
|
|
|
#mapnik.logger.set_severity(mapnik.severity_type.Debug)
|
2013-05-21 00:07:20 +02:00
|
|
|
import shutil
|
2012-01-08 15:01:54 +01:00
|
|
|
import os.path
|
2013-03-25 03:56:14 +01:00
|
|
|
from compare import compare, compare_grids
|
2014-09-07 01:04:01 +02:00
|
|
|
import platform
|
2012-11-21 00:08:53 +01:00
|
|
|
|
|
|
|
try:
|
|
|
|
import json
|
|
|
|
except ImportError:
|
|
|
|
import simplejson as json
|
2012-01-08 15:01:54 +01:00
|
|
|
|
2012-10-03 06:18:45 +02:00
|
|
|
visual_output_dir = "/tmp/mapnik-visual-images"
|
|
|
|
|
2012-03-20 22:06:22 +01:00
|
|
|
defaults = {
|
2013-03-11 21:36:31 +01:00
|
|
|
'sizes': [(500, 100)],
|
2013-03-25 03:56:14 +01:00
|
|
|
'scales':[1.0,2.0],
|
2013-05-20 21:45:06 +02:00
|
|
|
'agg': True,
|
2013-05-23 00:42:28 +02:00
|
|
|
'cairo': mapnik.has_cairo(),
|
2013-07-24 01:37:25 +02:00
|
|
|
'grid': mapnik.has_grid_renderer()
|
2012-03-20 22:06:22 +01:00
|
|
|
}
|
|
|
|
|
2013-05-31 23:03:53 +02:00
|
|
|
cairo_threshold = 10
|
2014-07-22 23:55:06 +02:00
|
|
|
agg_threshold = 0
|
2014-09-07 01:04:01 +02:00
|
|
|
if 'Linux' == platform.uname()[0]:
|
2013-05-31 23:03:53 +02:00
|
|
|
# we assume if linux then you are running packaged cairo
|
|
|
|
# which is older than the 1.12.14 version we used on OS X
|
|
|
|
# to generate the expected images, so we'll rachet back the threshold
|
|
|
|
# https://github.com/mapnik/mapnik/issues/1868
|
2014-07-22 23:55:06 +02:00
|
|
|
cairo_threshold = 230
|
|
|
|
agg_threshold = 12
|
2013-05-31 23:03:53 +02:00
|
|
|
|
|
|
|
def render_cairo(m, output, scale_factor):
|
|
|
|
mapnik.render_to_file(m, output, 'ARGB32', scale_factor)
|
|
|
|
# open and re-save as png8 to save space
|
|
|
|
new_im = mapnik.Image.open(output)
|
|
|
|
new_im.save(output, 'png8:m=h')
|
|
|
|
|
|
|
|
def render_grid(m, output, scale_factor):
|
|
|
|
grid = mapnik.Grid(m.width, m.height)
|
2014-09-19 00:26:50 +02:00
|
|
|
mapnik.render_layer(m, grid, layer=0, scale_factor=scale_factor)
|
2013-05-31 23:03:53 +02:00
|
|
|
utf1 = grid.encode('utf', resolution=4)
|
|
|
|
open(output,'wb').write(json.dumps(utf1, indent=1))
|
|
|
|
|
2014-09-19 00:26:50 +02:00
|
|
|
def render_agg(m, output, scale_factor):
|
|
|
|
mapnik.render_to_file(m, output, 'png8:m=h', scale_factor),
|
|
|
|
|
2013-05-31 23:03:53 +02:00
|
|
|
renderers = [
|
|
|
|
{ 'name': 'agg',
|
2014-09-19 00:26:50 +02:00
|
|
|
'render': render_agg,
|
2013-05-31 23:03:53 +02:00
|
|
|
'compare': lambda actual, reference: compare(actual, reference, alpha=True),
|
2014-07-22 23:55:06 +02:00
|
|
|
'threshold': agg_threshold,
|
2013-05-31 23:03:53 +02:00
|
|
|
'filetype': 'png',
|
|
|
|
'dir': 'images'
|
|
|
|
},
|
|
|
|
{ 'name': 'cairo',
|
|
|
|
'render': render_cairo,
|
|
|
|
'compare': lambda actual, reference: compare(actual, reference, alpha=False),
|
|
|
|
'threshold': cairo_threshold,
|
|
|
|
'filetype': 'png',
|
|
|
|
'dir': 'images'
|
|
|
|
},
|
|
|
|
{ 'name': 'grid',
|
|
|
|
'render': render_grid,
|
|
|
|
'compare': lambda actual, reference: compare_grids(actual, reference, alpha=False),
|
2014-07-22 23:55:06 +02:00
|
|
|
'threshold': agg_threshold,
|
2013-05-31 23:03:53 +02:00
|
|
|
'filetype': 'json',
|
|
|
|
'dir': 'grids'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2012-03-20 22:06:22 +01:00
|
|
|
sizes_many_in_big_range = [(800, 100), (600, 100), (400, 100),
|
|
|
|
(300, 100), (250, 100), (150, 100), (100, 100)]
|
|
|
|
|
|
|
|
sizes_few_square = [(800, 800), (600, 600), (400, 400), (200, 200)]
|
|
|
|
sizes_many_in_small_range = [(490, 100), (495, 100), (497, 100), (498, 100),
|
|
|
|
(499, 100), (500, 100), (501, 100), (502, 100), (505, 100), (510, 100)]
|
|
|
|
|
2012-09-26 20:28:23 +02:00
|
|
|
default_text_box = mapnik.Box2d(-0.05, -0.01, 0.95, 0.01)
|
2014-08-01 13:19:32 +02:00
|
|
|
large_text_box = mapnik.Box2d(-0.5, -0.5, 0.5, 0.5)
|
2012-09-26 20:28:23 +02:00
|
|
|
|
2013-07-19 22:07:12 +02:00
|
|
|
merc_z1_bboxes = {
|
|
|
|
'0,0':mapnik.Box2d(-20037508.342,0,0,20037508.342), # upper left
|
|
|
|
'1,0':mapnik.Box2d(0,0,20037508.342,20037508.342), # upper right
|
|
|
|
'0,1':mapnik.Box2d(-20037508.342,-20037508.342,0,0), # lower left
|
|
|
|
'1,1':mapnik.Box2d(0,-20037508.342,20037508.342,0) # lower right
|
|
|
|
}
|
|
|
|
|
2012-03-09 02:01:51 +01:00
|
|
|
dirname = os.path.dirname(__file__)
|
2012-03-23 20:42:11 +01:00
|
|
|
|
2013-05-20 21:45:06 +02:00
|
|
|
files = {
|
|
|
|
'list': {'sizes': sizes_many_in_big_range,'bbox':default_text_box},
|
|
|
|
'simple': {'sizes': sizes_many_in_big_range,'bbox':default_text_box},
|
|
|
|
'lines-1': {'sizes': sizes_few_square,'bbox':default_text_box},
|
|
|
|
'lines-2': {'sizes': sizes_few_square,'bbox':default_text_box},
|
|
|
|
'lines-3': {'sizes': sizes_few_square,'bbox':default_text_box},
|
2013-10-24 08:59:14 +02:00
|
|
|
'lines-4': {'sizes': sizes_few_square,'bbox':default_text_box},
|
|
|
|
'lines-5': {'sizes': sizes_few_square,'bbox':default_text_box},
|
|
|
|
'lines-6': {'sizes': sizes_few_square,'bbox':default_text_box},
|
2014-01-28 20:10:04 +01:00
|
|
|
'lines-7': {'sizes': sizes_few_square,'bbox':mapnik.Box2d(-1.2, -1.2, 1.2, 1.2)},
|
2014-02-10 15:03:50 +01:00
|
|
|
'lines-multi-layout-1': {'sizes': [(800,800)],'bbox':default_text_box},
|
|
|
|
'lines-multi-layout-2': {'sizes': [(800,800)],'bbox':mapnik.Box2d(-1.2, -1.2, 1.2, 1.2)},
|
|
|
|
'lines-multi-layout-shield': {'sizes': [(800,800)],'bbox':default_text_box},
|
2013-05-20 21:45:06 +02:00
|
|
|
'lines-shield': {'sizes': sizes_few_square,'bbox':default_text_box},
|
|
|
|
'collision': {'sizes':[(600,400)]},
|
|
|
|
'shield-on-polygon': {'sizes':[(600,400)]},
|
|
|
|
'shield-on-line-spacing-eq-width': {'sizes':[(600,400)]},
|
2013-06-28 23:22:31 +02:00
|
|
|
'geometry-transform-translate': {'sizes':[(200,200)]},
|
2013-11-06 01:40:09 +01:00
|
|
|
'geometry-transform-translate-patterns': {'sizes':[(200,200)]},
|
2014-08-05 23:02:57 +02:00
|
|
|
'geometry-transform-translate-patterns-svg': {'sizes':[(200,200)]},
|
2014-08-12 23:42:51 +02:00
|
|
|
'marker-interior-position': {'sizes':[(600,400)]},
|
2013-05-20 21:45:06 +02:00
|
|
|
'marker-svg-opacity':{},
|
2013-07-10 22:19:28 +02:00
|
|
|
'marker-svg-opacity2':{},
|
2013-07-10 23:23:17 +02:00
|
|
|
'marker-svg-empty-g-element':{},
|
2013-05-20 21:45:06 +02:00
|
|
|
'marker-multi-policy': {'sizes':[(600,400)]},
|
|
|
|
'marker-on-line': {'sizes':[(600,400)],
|
2014-09-25 02:48:25 +02:00
|
|
|
'bbox': mapnik.Box2d(-10, 0, 15, 20)},
|
2013-06-28 21:03:55 +02:00
|
|
|
'marker-on-line-and-line-placement': {'sizes':[(600,400)],
|
2014-09-25 02:48:25 +02:00
|
|
|
'bbox': mapnik.Box2d(-10, 0, 15, 20)},
|
2013-05-20 21:45:06 +02:00
|
|
|
'marker-on-line-spacing-eq-width': {'sizes':[(600,400)]},
|
|
|
|
'marker-on-line-spacing-eq-width-overlap': {'sizes':[(600,400)]},
|
|
|
|
'marker_line_placement_on_points':{},
|
2014-08-07 07:37:16 +02:00
|
|
|
'marker-on-line-and-vertex-first-placement':{'sizes':[(600,400)],
|
2014-09-25 02:48:25 +02:00
|
|
|
'bbox': mapnik.Box2d(-1, -1, 11, 4)},
|
2014-08-07 07:37:16 +02:00
|
|
|
'marker-on-line-and-vertex-last-placement':{'sizes':[(600,400)],
|
2014-09-25 02:48:25 +02:00
|
|
|
'bbox': mapnik.Box2d(-1, -1, 11, 4)},
|
2014-08-04 21:10:26 +02:00
|
|
|
'marker-with-background-image-linear-comp-op': {},
|
2013-05-20 21:45:06 +02:00
|
|
|
'marker-with-background-image': {'sizes':[(600,400),(400,600),(257,256)]},
|
2013-07-19 06:37:51 +02:00
|
|
|
'marker-with-background-image-and-hsla-transform': {'sizes':[(600,400),(400,600),(257,256)]},
|
2013-05-20 21:45:06 +02:00
|
|
|
'marker-on-hex-grid': {'sizes':[(600,400),(400,600),(257,256)]},
|
|
|
|
'whole-centroid': {'sizes':[(600,400)],
|
2014-09-25 02:48:25 +02:00
|
|
|
'bbox': mapnik.Box2d(736908, 4390316, 2060771, 5942346)},
|
2013-05-20 21:45:06 +02:00
|
|
|
'text-halo-rasterizer': {'sizes':[(600,400)]},
|
2014-07-29 03:56:57 +02:00
|
|
|
'text-halo-transform': {'sizes':[(600,400)]},
|
2014-08-12 20:34:48 +02:00
|
|
|
'text-ttc-font': {'sizes':[(600,400)]},
|
2013-05-20 21:45:06 +02:00
|
|
|
'simple-E': {'bbox':mapnik.Box2d(-0.05, -0.01, 0.95, 0.01)},
|
|
|
|
'simple-NE': {'bbox':default_text_box},
|
|
|
|
'simple-NW': {'bbox':default_text_box},
|
|
|
|
'simple-N': {'bbox':default_text_box},
|
|
|
|
'simple-SE': {'bbox':default_text_box},
|
|
|
|
'simple-SW': {'bbox':default_text_box},
|
|
|
|
'simple-S': {'bbox':default_text_box},
|
|
|
|
'simple-W': {'bbox':default_text_box},
|
|
|
|
'formatting-1': {'bbox':default_text_box},
|
|
|
|
'formatting-2': {'bbox':default_text_box},
|
|
|
|
'formatting-3': {'bbox':default_text_box},
|
|
|
|
'formatting-4': {'bbox':default_text_box},
|
2013-06-04 09:06:26 +02:00
|
|
|
'formatting-5': {'bbox':default_text_box},
|
|
|
|
'formatting-6': {'bbox':default_text_box},
|
2014-07-30 23:16:32 +02:00
|
|
|
'formatting-7': {'bbox':default_text_box},
|
|
|
|
'formatting-8': {'bbox':default_text_box},
|
2014-08-01 13:19:32 +02:00
|
|
|
'formatting-expr-alignment': {'bbox':large_text_box, 'sizes': [(500, 500)]},
|
2013-05-20 21:45:06 +02:00
|
|
|
'expressionformat': {'bbox':default_text_box},
|
|
|
|
'shieldsymbolizer-1': {'sizes': sizes_many_in_small_range,'bbox':default_text_box},
|
2013-10-24 08:59:14 +02:00
|
|
|
'shieldsymbolizer-2': {'sizes': sizes_many_in_small_range,'bbox':default_text_box},
|
|
|
|
'shieldsymbolizer-3': {'sizes': sizes_many_in_small_range,'bbox':default_text_box},
|
|
|
|
'shieldsymbolizer-4': {'sizes': sizes_many_in_small_range,'bbox':default_text_box},
|
|
|
|
'orientation': {'sizes': [(800, 200)], 'bbox': default_text_box},
|
|
|
|
'harfbuzz': {'sizes': [(800, 200)], 'bbox': default_text_box},
|
|
|
|
'hb-fontsets': {'sizes': [(800, 200)], 'bbox': default_text_box},
|
|
|
|
'khmer': {'sizes': [(800, 200)], 'bbox': default_text_box},
|
|
|
|
'charspacing': {'sizes': [(200, 400)], 'bbox': default_text_box},
|
|
|
|
'charspacing-lines': {'sizes': [(300, 300)], 'bbox': default_text_box},
|
|
|
|
'line_break': {'sizes': [(800, 800)], 'bbox': default_text_box},
|
2013-05-20 21:45:06 +02:00
|
|
|
'rtl-point': {'sizes': [(200, 200)],'bbox':default_text_box},
|
|
|
|
'jalign-auto': {'sizes': [(200, 200)],'bbox':default_text_box},
|
|
|
|
'line-offset': {'sizes':[(900, 250)],'bbox': mapnik.Box2d(-5.192, 50.189, -5.174, 50.195)},
|
2014-08-03 13:32:41 +02:00
|
|
|
'repeat-labels-1': {'sizes': [(750,250)],'bbox':mapnik.Box2d(-12, -4, 12, 4)},
|
|
|
|
'repeat-labels-2': {'sizes': [(750,250)],'bbox':mapnik.Box2d(-12, -4, 12, 4)},
|
2014-08-03 19:03:42 +02:00
|
|
|
'repeat-labels-3': {'sizes': [(750,250)],'bbox':mapnik.Box2d(-12, -4, 12, 4)},
|
|
|
|
'repeat-labels-4': {'sizes': [(750,250)],'bbox':mapnik.Box2d(-12, -4, 12, 4)},
|
2013-10-24 08:59:14 +02:00
|
|
|
'text-bug1532': {'sizes': [(600, 165)]},
|
|
|
|
'text-bug1533': {'sizes': [(600, 600)]},
|
|
|
|
'text-bug1820-1': {'sizes': [(600, 300)], 'bbox': default_text_box},
|
|
|
|
'text-bug1820+0': {'sizes': [(600, 300)], 'bbox': default_text_box},
|
|
|
|
'text-bug1820+1': {'sizes': [(600, 300)], 'bbox': default_text_box},
|
|
|
|
'text-bug2037': {'sizes': [(800, 300)], 'bbox': default_text_box},
|
|
|
|
'text-expressionformat-color': {'sizes': [(800, 100)], 'bbox': default_text_box},
|
|
|
|
'text-halign': {'sizes': [(800,800)], 'bbox': default_text_box},
|
2014-09-22 16:36:28 +02:00
|
|
|
'text-halign-adjust': {'sizes': [(800,800)], 'bbox': default_text_box},
|
|
|
|
'text-halign-adjust-multiline': {'sizes': [(800,800)], 'bbox': default_text_box},
|
2014-09-26 21:13:54 +02:00
|
|
|
'text-vertical-alignment': {'sizes': [(800,800)], 'bbox': default_text_box},
|
2013-12-03 07:35:11 +01:00
|
|
|
'text-malayalam': {'sizes': [(800, 100)], 'bbox': default_text_box},
|
|
|
|
'text-bengali': {'sizes': [(800, 100)], 'bbox': default_text_box},
|
2014-09-12 21:08:49 +02:00
|
|
|
'text-font-features': {'sizes': [(500, 500)]},
|
2014-02-11 02:01:35 +01:00
|
|
|
'text-multi-layout-1': {'sizes': [(512,512)], 'bbox':mapnik.Box2d(-1, -1, 1, 1)},
|
|
|
|
'text-multi-layout-2': {'sizes': [(512,512)], 'bbox':mapnik.Box2d(-1, -1, 1, 1)},
|
2013-08-21 17:33:24 +02:00
|
|
|
'line-pattern-symbolizer': {'sizes':[(900, 250)],'bbox': mapnik.Box2d(-5.192, 50.189, -5.174, 50.195)},
|
2013-05-20 21:45:06 +02:00
|
|
|
'tiff-alpha-gdal': {'sizes':[(600,400)]},
|
|
|
|
'tiff-alpha-broken-assoc-alpha-gdal': {'sizes':[(600,400)]},
|
|
|
|
'tiff-alpha-gradient-gdal': {'sizes':[(600,400)]},
|
|
|
|
'tiff-nodata-edge-gdal': {'sizes':[(600,400),(969,793)]},
|
|
|
|
'tiff-opaque-edge-gdal': {'sizes':[(256,256),(969,793)]},
|
|
|
|
'tiff-opaque-edge-gdal2': {'sizes':[(600,400),(969,793)]},
|
|
|
|
'tiff-opaque-edge-raster2': {'sizes':[(600,400),(969,793)]},
|
|
|
|
'tiff-resampling': {'sizes':[(600,400)]},
|
2013-07-20 00:56:50 +02:00
|
|
|
'gdal-filter-factor': {'sizes':[(600,400)]},
|
2013-03-07 02:41:20 +01:00
|
|
|
# https://github.com/mapnik/mapnik/issues/1622
|
2013-05-20 21:45:06 +02:00
|
|
|
'tiff-edge-alignment-gdal1': {'sizes':[(256,256),(255,257)],
|
2014-09-25 02:48:25 +02:00
|
|
|
'bbox':mapnik.Box2d(-13267022.12540147,4618019.500877209,-13247454.246160466,4637587.380118214)
|
2013-03-07 02:41:20 +01:00
|
|
|
},
|
2013-05-20 21:45:06 +02:00
|
|
|
'tiff-edge-alignment-gdal2': {'sizes':[(256,256),(255,257)],
|
2014-09-25 02:48:25 +02:00
|
|
|
'bbox':mapnik.Box2d(-13267022.12540147,4598451.621636203,-13247454.246160466,4618019.500877209)
|
2013-03-07 02:41:20 +01:00
|
|
|
},
|
2013-06-14 05:09:24 +02:00
|
|
|
'tiff-reprojection-1': {'sizes':[(250,250)]},
|
2013-07-19 06:39:22 +02:00
|
|
|
|
2014-09-11 19:22:19 +02:00
|
|
|
'tiff-reprojection-2': {'sizes':[(250,250)]},
|
2013-07-19 06:39:22 +02:00
|
|
|
|
2012-11-21 00:08:53 +01:00
|
|
|
# https://github.com/mapnik/mapnik/issues/1520
|
|
|
|
# commented because these are not critical failures
|
2013-05-20 21:45:06 +02:00
|
|
|
#'tiff-alpha-raster': {'sizes':[(600,400)]},
|
|
|
|
#'tiff-alpha-broken-assoc-alpha-raster': {'sizes':[(600,400)]},
|
|
|
|
#'tiff-nodata-edge-raster': {'sizes':[(600,400)]},
|
|
|
|
#'tiff-opaque-edge-raster': {'sizes':[(256,256)]},
|
2013-07-19 00:35:14 +02:00
|
|
|
'road-casings-grouped-rendering': {'sizes':[(600,600)],
|
2014-09-25 02:48:25 +02:00
|
|
|
'bbox':mapnik.Box2d(1477001.12245,6890242.37746,1480004.49012,6892244.62256)
|
2013-07-19 00:35:14 +02:00
|
|
|
},
|
|
|
|
'road-casings-non-grouped-rendering': {'sizes':[(600,600)],
|
2014-09-25 02:48:25 +02:00
|
|
|
'bbox':mapnik.Box2d(1477001.12245,6890242.37746,1480004.49012,6892244.62256)
|
2013-07-19 22:07:12 +02:00
|
|
|
},
|
|
|
|
'style-level-compositing-tiled-0,0':{'sizes':[(512,512)],'bbox':merc_z1_bboxes['0,0']},
|
|
|
|
'style-level-compositing-tiled-1,0':{'sizes':[(512,512)],'bbox':merc_z1_bboxes['1,0']},
|
|
|
|
'style-level-compositing-tiled-0,1':{'sizes':[(512,512)],'bbox':merc_z1_bboxes['0,1']},
|
2013-07-24 02:00:42 +02:00
|
|
|
'style-level-compositing-tiled-1,1':{'sizes':[(512,512)],'bbox':merc_z1_bboxes['1,1']},
|
2013-07-25 07:00:38 +02:00
|
|
|
'marker-path-expression':{},
|
2013-09-20 04:15:32 +02:00
|
|
|
'map-background-image-compositing':{'sizes':[(512,512)]},
|
|
|
|
'building-symbolizer-opacity':{'sizes':[(512,512)]},
|
2013-09-20 22:31:11 +02:00
|
|
|
'line-pattern-symbolizer-opacity':{'sizes':[(512,512)]},
|
|
|
|
'dst-over-compositing':{'sizes':[(512,512)]},
|
2013-09-25 22:13:18 +02:00
|
|
|
'tiff_colortable':{'sizes':[(256,256)]},
|
|
|
|
'tiff_colortable_custom_nodata':{'sizes':[(256,256)]},
|
2013-09-25 23:02:52 +02:00
|
|
|
'vrt_colortable':{'sizes':[(256,256)]},
|
2013-09-25 23:08:47 +02:00
|
|
|
'raster_colorizer':{'sizes':[(512,512)]},
|
|
|
|
'raster_symbolizer':{'sizes':[(512,512)]},
|
2013-09-27 01:14:40 +02:00
|
|
|
'raster-color-to-alpha1':{'sizes':[(512,512)]},
|
|
|
|
'raster-color-to-alpha2':{'sizes':[(512,512)]},
|
|
|
|
'raster-color-to-alpha3':{'sizes':[(512,512)]},
|
|
|
|
'raster-color-to-alpha4':{'sizes':[(512,512)]},
|
2013-09-27 23:49:24 +02:00
|
|
|
'raster-color-to-alpha5':{'sizes':[(512,512)]},
|
|
|
|
'colorize-alpha1':{'sizes':[(512,512)]},
|
|
|
|
'colorize-alpha2':{'sizes':[(512,512)]},
|
2013-10-04 01:32:38 +02:00
|
|
|
'colorize-alpha3':{'sizes':[(512,512)]},
|
|
|
|
'image-filters-galore':{'sizes':[(512,512)]},
|
2013-10-04 02:52:52 +02:00
|
|
|
'image-filters-multi-blur':{'sizes':[(512,512)]},
|
2014-02-27 19:11:17 +01:00
|
|
|
'image-filters-multi-blur-inflate':{'sizes':[(512,512)]},
|
2014-01-02 19:51:01 +01:00
|
|
|
'line-opacity-multi-render':{'sizes':[(512,512)]},
|
2014-01-18 04:41:17 +01:00
|
|
|
'tiff-nodata-rgb':{'sizes':[(512,512)]},
|
|
|
|
'tiff-nodata-rgba':{'sizes':[(512,512)]},
|
2014-01-18 05:04:09 +01:00
|
|
|
'tiff-nodata-tolerance':{'sizes':[(512,512)]},
|
2014-01-18 05:04:30 +01:00
|
|
|
'tiff-nodata-edge-rgba':{'sizes':[(512,512)]},
|
2014-02-10 20:02:08 +01:00
|
|
|
'marker-vs-point':{'sizes':[(512,512)]},
|
|
|
|
'line-symbolizer-expressions':{'sizes':[(256,256)]},
|
2014-02-11 03:50:50 +01:00
|
|
|
'line-symbolizer-expressions-all':{'sizes':[(256,256)]},
|
2014-02-11 04:19:53 +01:00
|
|
|
'point-symbolizer-expressions':{'sizes':[(256,256)]},
|
|
|
|
'point-symbolizer-expressions-all':{'sizes':[(256,256)]},
|
2014-08-11 15:55:38 +02:00
|
|
|
'point-symbolizer-overlap-placement-expr': {'bbox':large_text_box, 'sizes': [(500, 500)]},
|
2014-08-12 08:08:17 +02:00
|
|
|
'text-allow-overlap-expr': {'bbox':large_text_box, 'sizes': [(500, 500)]},
|
2014-07-31 06:30:54 +02:00
|
|
|
'marker-symbolizer-expressions-all':{'sizes':[(256,256)]},
|
2014-02-11 03:50:50 +01:00
|
|
|
'polygon-symbolizer-expressions':{'sizes':[(256,256)]},
|
|
|
|
'polygon-symbolizer-expressions-all':{'sizes':[(256,256)]},
|
2014-08-22 16:26:02 +02:00
|
|
|
'polygon-winding-order': {'sizes':[(300,300)]},
|
2014-01-10 15:48:25 +01:00
|
|
|
'group-symbolizer-1':{'sizes':[(512,512)]},
|
|
|
|
'group-symbolizer-2':{'sizes':[(512,512)]},
|
|
|
|
'group-symbolizer-line-1':{'sizes':[(512,512)]},
|
2014-04-25 06:44:28 +02:00
|
|
|
'group-symbolizer-line-2':{'sizes':[(512,512)]},
|
2014-04-25 05:48:19 +02:00
|
|
|
'text-charplacement':{'sizes':[(512,512)]},
|
|
|
|
'text-displacement':{'sizes':[(512,512)]},
|
|
|
|
'text-overlap':{'sizes':[(512,512)]},
|
|
|
|
'text-spacing':{'sizes':[(512,512)]},
|
2014-06-17 18:22:05 +02:00
|
|
|
'text-halo-opacity':{'sizes':[(512,512)]},
|
2014-04-04 01:57:11 +02:00
|
|
|
# https://github.com/mapnik/mapnik/issues/2202
|
2014-06-20 01:28:28 +02:00
|
|
|
'line-smooth-and-offset':{'sizes':[(512,512)]},
|
2014-08-05 22:48:40 +02:00
|
|
|
'line-pattern-smooth-and-offset':{'sizes':[(512,512)]},
|
2014-07-22 21:17:40 +02:00
|
|
|
'halo-comp-op-on-satellite':{'sizes':[(450,450)]},
|
2014-08-22 07:42:42 +02:00
|
|
|
'marker-whole-multi-polygon':{'sizes':[(512,512)]},
|
|
|
|
'shield-on-line-and-avoid-edges':{'sizes':[(512,512)]},
|
2014-09-05 18:25:34 +02:00
|
|
|
'marker-on-line-and-avoid-edges':{'sizes':[(512,512)]},
|
2014-08-22 22:52:52 +02:00
|
|
|
'text-typographic':{'sizes':[(512,512)]},
|
2014-08-26 02:36:22 +02:00
|
|
|
'functional-expressions':{'sizes':[(256,256)], 'bbox':mapnik.Box2d(-10,-10,10,10)},
|
2014-09-24 14:16:29 +02:00
|
|
|
'functional-expressions-length':{'sizes':[(512,512)], 'bbox':mapnik.Box2d(-15,-15,15,15)},
|
2014-09-05 05:35:14 +02:00
|
|
|
'marker-collide':{'sizes':[(512,512)]},
|
2014-09-20 00:26:07 +02:00
|
|
|
'postgis-inline':{'sizes':[(512,512)]},
|
2014-09-20 01:55:34 +02:00
|
|
|
'text-line-wrap':{'sizes':[(512,512)]},
|
2013-05-20 21:45:06 +02:00
|
|
|
}
|
2012-02-17 23:19:07 +01:00
|
|
|
|
2013-03-25 03:56:14 +01:00
|
|
|
class Reporting:
|
|
|
|
DIFF = 1
|
|
|
|
NOT_FOUND = 2
|
|
|
|
OTHER = 3
|
|
|
|
REPLACE = 4
|
2013-05-16 22:17:48 +02:00
|
|
|
def __init__(self, quiet, overwrite_failures = False):
|
2014-09-25 02:48:25 +02:00
|
|
|
self.quiet = quiet
|
|
|
|
self.passed = 0
|
|
|
|
self.failed = 0
|
|
|
|
self.overwrite_failures = overwrite_failures
|
|
|
|
self.errors = [ #(type, actual, expected, diff, message)
|
|
|
|
]
|
2013-09-19 04:55:02 +02:00
|
|
|
|
2013-03-25 03:56:14 +01:00
|
|
|
def result_fail(self, actual, expected, diff):
|
2014-09-25 02:48:25 +02:00
|
|
|
self.failed += 1
|
|
|
|
if self.quiet:
|
|
|
|
if platform.uname()[0] == 'Windows':
|
|
|
|
sys.stderr.write('.')
|
|
|
|
else:
|
|
|
|
sys.stderr.write('\x1b[31m.\x1b[0m')
|
|
|
|
else:
|
|
|
|
print '\x1b[31m✘\x1b[0m (\x1b[34m%u different pixels\x1b[0m)' % diff
|
|
|
|
|
|
|
|
if self.overwrite_failures:
|
|
|
|
self.errors.append((self.REPLACE, actual, expected, diff, None))
|
|
|
|
contents = open(actual, 'r').read()
|
|
|
|
open(expected, 'wb').write(contents)
|
|
|
|
else:
|
|
|
|
self.errors.append((self.DIFF, actual, expected, diff, None))
|
2013-09-19 04:55:02 +02:00
|
|
|
|
2013-03-25 03:56:14 +01:00
|
|
|
def result_pass(self, actual, expected, diff):
|
2014-09-25 02:48:25 +02:00
|
|
|
self.passed += 1
|
|
|
|
if self.quiet:
|
|
|
|
if platform.uname()[0] == 'Windows':
|
|
|
|
sys.stderr.write('.')
|
|
|
|
else:
|
|
|
|
sys.stderr.write('\x1b[32m.\x1b[0m')
|
|
|
|
else:
|
|
|
|
if platform.uname()[0] == 'Windows':
|
|
|
|
print '\x1b[32m✓\x1b[0m'
|
|
|
|
else:
|
|
|
|
print '✓'
|
2012-12-07 05:14:14 +01:00
|
|
|
|
2013-03-25 03:56:14 +01:00
|
|
|
def not_found(self, actual, expected):
|
2014-09-25 02:48:25 +02:00
|
|
|
self.failed += 1
|
|
|
|
self.errors.append((self.NOT_FOUND, actual, expected, 0, None))
|
|
|
|
if self.quiet:
|
|
|
|
sys.stderr.write('\x1b[33m.\x1b[0m')
|
|
|
|
else:
|
|
|
|
print '\x1b[33m?\x1b[0m (\x1b[34mReference file not found, creating\x1b[0m)'
|
|
|
|
contents = open(actual, 'r').read()
|
|
|
|
open(expected, 'wb').write(contents)
|
2013-03-25 03:56:14 +01:00
|
|
|
|
|
|
|
def other_error(self, expected, message):
|
2014-09-25 02:48:25 +02:00
|
|
|
self.failed += 1
|
|
|
|
self.errors.append((self.OTHER, None, expected, 0, message))
|
|
|
|
if self.quiet:
|
|
|
|
sys.stderr.write('\x1b[31m.\x1b[0m')
|
|
|
|
else:
|
|
|
|
print '\x1b[31m✘\x1b[0m (\x1b[34m%s\x1b[0m)' % message
|
2013-03-25 03:56:14 +01:00
|
|
|
|
2013-05-21 00:07:20 +02:00
|
|
|
def make_html_item(self,actual,expected,diff):
|
2014-09-25 02:48:25 +02:00
|
|
|
item = '''
|
|
|
|
<div class="expected">
|
|
|
|
<a href="%s">
|
|
|
|
<img src="%s" width="100%s">
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
''' % (expected,expected,'%')
|
|
|
|
item += '<div class="text">%s</div>' % (diff)
|
|
|
|
item += '''
|
|
|
|
<div class="actual">
|
|
|
|
<a href="%s">
|
|
|
|
<img src="%s" width="100%s">
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
''' % (actual,actual,'%')
|
|
|
|
return item
|
2013-05-18 01:46:42 +02:00
|
|
|
|
2013-05-16 22:17:48 +02:00
|
|
|
def summary(self):
|
2014-09-25 02:48:25 +02:00
|
|
|
if len(self.errors) == 0:
|
|
|
|
print '\nAll %s visual tests passed: \x1b[1;32m✓ \x1b[0m' % self.passed
|
|
|
|
return 0
|
|
|
|
sortable_errors = []
|
|
|
|
print "\nVisual rendering: %s failed / %s passed" % (len(self.errors), self.passed)
|
|
|
|
for idx, error in enumerate(self.errors):
|
|
|
|
if error[0] == self.OTHER:
|
|
|
|
print str(idx+1) + ") \x1b[31mfailure to run test:\x1b[0m %s (\x1b[34m%s\x1b[0m)" % (error[2],error[4])
|
|
|
|
elif error[0] == self.NOT_FOUND:
|
|
|
|
print str(idx+1) + ") Generating reference image: '%s'" % error[2]
|
|
|
|
continue
|
|
|
|
elif error[0] == self.DIFF:
|
|
|
|
print str(idx+1) + ") \x1b[34m%s different pixels\x1b[0m:\n\t%s (\x1b[31mactual\x1b[0m)\n\t%s (\x1b[32mexpected\x1b[0m)" % (error[3], error[1], error[2])
|
|
|
|
if '.png' in error[1]: # ignore grids
|
|
|
|
sortable_errors.append((error[3],error))
|
|
|
|
elif error[0] == self.REPLACE:
|
|
|
|
print str(idx+1) + ") \x1b[31mreplaced reference with new version:\x1b[0m %s" % error[2]
|
|
|
|
if len(sortable_errors):
|
|
|
|
# drop failure results in folder
|
|
|
|
vdir = os.path.join(visual_output_dir,'visual-test-results')
|
|
|
|
if not os.path.exists(vdir):
|
|
|
|
os.makedirs(vdir)
|
|
|
|
html_template = open(os.path.join(dirname,'html_report_template.html'),'r').read()
|
|
|
|
name = 'comparison.html'
|
|
|
|
failures_realpath = os.path.join(vdir,name)
|
|
|
|
html_out = open(failures_realpath,'w+')
|
|
|
|
sortable_errors.sort(reverse=True)
|
|
|
|
html_body = ''
|
|
|
|
for item in sortable_errors:
|
|
|
|
# copy images into single directory
|
|
|
|
actual = item[1][1]
|
|
|
|
expected = item[1][2]
|
|
|
|
diff = item[0]
|
|
|
|
actual_new = os.path.join(vdir,os.path.basename(actual))
|
|
|
|
shutil.copy(actual,actual_new)
|
|
|
|
expected_new = os.path.join(vdir,os.path.basename(expected))
|
|
|
|
shutil.copy(expected,expected_new)
|
|
|
|
html_body += self.make_html_item(os.path.relpath(actual_new,vdir),os.path.relpath(expected_new,vdir),diff)
|
|
|
|
html_out.write(html_template.replace('{{RESULTS}}',html_body))
|
|
|
|
print 'View failures by opening %s' % failures_realpath
|
|
|
|
return 1
|
2013-03-25 03:56:14 +01:00
|
|
|
|
2013-05-20 21:45:06 +02:00
|
|
|
def render(filename,config, width, height, bbox, scale_factor, reporting):
|
2012-03-02 01:45:44 +01:00
|
|
|
m = mapnik.Map(width, height)
|
2013-03-25 03:56:14 +01:00
|
|
|
postfix = "%s-%d-%d-%s" % (filename, width, height, scale_factor)
|
2013-03-25 02:28:54 +01:00
|
|
|
|
|
|
|
try:
|
2014-09-25 02:48:25 +02:00
|
|
|
mapnik.load_map(m, os.path.join(dirname, "styles", "%s.xml" % filename), True)
|
|
|
|
if bbox is not None:
|
|
|
|
m.zoom_to_box(bbox)
|
|
|
|
else:
|
|
|
|
m.zoom_all()
|
2013-03-25 02:28:54 +01:00
|
|
|
except Exception, e:
|
2014-09-25 02:43:48 +02:00
|
|
|
if 'Could not create datasource' in str(e) \
|
|
|
|
or 'Bad connection' in str(e):
|
|
|
|
return m
|
2014-09-25 02:48:25 +02:00
|
|
|
reporting.other_error(filename, repr(e))
|
|
|
|
return m
|
2013-09-19 04:55:02 +02:00
|
|
|
|
2013-03-25 03:56:14 +01:00
|
|
|
for renderer in renderers:
|
2014-09-25 02:48:25 +02:00
|
|
|
if config.get(renderer['name'], True):
|
|
|
|
expected = os.path.join(dirname, renderer['dir'], '%s-%s-reference.%s' %
|
|
|
|
(postfix, renderer['name'], renderer['filetype']))
|
|
|
|
actual = os.path.join(visual_output_dir, '%s-%s.%s' %
|
|
|
|
(postfix, renderer['name'], renderer['filetype']))
|
|
|
|
if not quiet:
|
|
|
|
print "\"%s\" with %s..." % (postfix, renderer['name']),
|
|
|
|
try:
|
|
|
|
renderer['render'](m, actual, scale_factor)
|
|
|
|
if not os.path.exists(expected):
|
|
|
|
reporting.not_found(actual, expected)
|
|
|
|
else:
|
|
|
|
diff = renderer['compare'](actual, expected)
|
|
|
|
if diff > renderer['threshold']:
|
|
|
|
reporting.result_fail(actual, expected, diff)
|
|
|
|
else:
|
|
|
|
reporting.result_pass(actual, expected, diff)
|
|
|
|
except Exception, e:
|
|
|
|
reporting.other_error(expected, repr(e))
|
2012-01-08 15:01:54 +01:00
|
|
|
return m
|
2012-02-24 22:13:56 +01:00
|
|
|
|
2012-04-04 23:54:07 +02:00
|
|
|
if __name__ == "__main__":
|
|
|
|
if '-q' in sys.argv:
|
|
|
|
quiet = True
|
|
|
|
sys.argv.remove('-q')
|
|
|
|
else:
|
|
|
|
quiet = False
|
|
|
|
|
2013-03-08 02:19:00 +01:00
|
|
|
if '--overwrite' in sys.argv:
|
|
|
|
overwrite_failures = True
|
|
|
|
sys.argv.remove('--overwrite')
|
|
|
|
else:
|
|
|
|
overwrite_failures = False
|
|
|
|
|
2013-05-20 21:45:06 +02:00
|
|
|
select_files = {}
|
|
|
|
if len(sys.argv) > 1:
|
2014-09-25 02:48:25 +02:00
|
|
|
for name in sys.argv[1:]:
|
|
|
|
if name in files:
|
|
|
|
select_files[name]=files[name]
|
|
|
|
else:
|
|
|
|
select_files[name]={}
|
2013-05-20 21:45:06 +02:00
|
|
|
if len(select_files) > 0:
|
2014-09-25 02:48:25 +02:00
|
|
|
files = select_files
|
2012-02-24 22:13:56 +01:00
|
|
|
|
2012-10-03 06:18:45 +02:00
|
|
|
if not os.path.exists(visual_output_dir):
|
2014-09-25 02:48:25 +02:00
|
|
|
os.makedirs(visual_output_dir)
|
2012-10-03 06:18:45 +02:00
|
|
|
|
2013-05-21 07:23:04 +02:00
|
|
|
reporting = Reporting(quiet, overwrite_failures)
|
2014-07-30 02:23:09 +02:00
|
|
|
try:
|
2014-09-25 02:48:25 +02:00
|
|
|
for filename in files:
|
|
|
|
config = dict(defaults)
|
|
|
|
config.update(files[filename])
|
|
|
|
for size in config['sizes']:
|
|
|
|
for scale_factor in config['scales']:
|
|
|
|
m = render(filename,
|
|
|
|
config,
|
|
|
|
size[0],
|
|
|
|
size[1],
|
|
|
|
config.get('bbox'),
|
|
|
|
scale_factor,
|
|
|
|
reporting)
|
|
|
|
#mapnik.save_map(m, os.path.join(dirname, 'xml_output', "%s-out.xml" % filename))
|
2014-07-30 02:23:09 +02:00
|
|
|
except KeyboardInterrupt:
|
2014-09-25 02:48:25 +02:00
|
|
|
pass
|
2013-05-21 07:23:04 +02:00
|
|
|
sys.exit(reporting.summary())
|