#!/usr/bin/env python # -*- coding: utf-8 -*- import mapnik mapnik.logger.set_severity(mapnik.severity_type.None) import shutil import sys import os.path from compare import compare, compare_grids try: import json except ImportError: import simplejson as json visual_output_dir = "/tmp/mapnik-visual-images" defaults = { 'sizes': [(500, 100)], 'scales':[1.0,2.0], 'agg': True, 'cairo': mapnik.has_cairo(), 'grid': True } cairo_threshold = 10 if 'Linux' == os.uname()[0]: # 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 cairo_threshold = 120 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) mapnik.render_layer(m, grid, layer=0) utf1 = grid.encode('utf', resolution=4) open(output,'wb').write(json.dumps(utf1, indent=1)) renderers = [ { 'name': 'agg', 'render': lambda m, output, scale_factor: mapnik.render_to_file(m, output, 'png8:m=h', scale_factor), 'compare': lambda actual, reference: compare(actual, reference, alpha=True), 'threshold': 0, '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), 'threshold': 0, 'filetype': 'json', 'dir': 'grids' } ] 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)] default_text_box = mapnik.Box2d(-0.05, -0.01, 0.95, 0.01) dirname = os.path.dirname(__file__) 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}, # https://github.com/mapnik/mapnik/issues/1696 # https://github.com/mapnik/mapnik/issues/1521 # fails with clang++ on os x '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)]}, 'marker-svg-opacity':{}, 'marker-multi-policy': {'sizes':[(600,400)]}, 'marker-on-line': {'sizes':[(600,400)], 'bbox': mapnik.Box2d(-10, 0, 15, 20)}, 'marker-on-line-spacing-eq-width': {'sizes':[(600,400)]}, 'marker-on-line-spacing-eq-width-overlap': {'sizes':[(600,400)]}, 'marker_line_placement_on_points':{}, 'marker-with-background-image': {'sizes':[(600,400),(400,600),(257,256)]}, #'marker-with-background-image-and-hsla-transform': {'sizes':[(600,400),(400,600),(257,256)]}, 'marker-on-hex-grid': {'sizes':[(600,400),(400,600),(257,256)]}, 'whole-centroid': {'sizes':[(600,400)], 'bbox': mapnik.Box2d(736908, 4390316, 2060771, 5942346)}, 'text-halo-rasterizer': {'sizes':[(600,400)]}, '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}, 'expressionformat': {'bbox':default_text_box}, 'shieldsymbolizer-1': {'sizes': sizes_many_in_small_range,'bbox':default_text_box}, '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)}, '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)]}, # https://github.com/mapnik/mapnik/issues/1622 'tiff-edge-alignment-gdal1': {'sizes':[(256,256),(255,257)], 'bbox':mapnik.Box2d(-13267022.12540147,4618019.500877209,-13247454.246160466,4637587.380118214) }, 'tiff-edge-alignment-gdal2': {'sizes':[(256,256),(255,257)], 'bbox':mapnik.Box2d(-13267022.12540147,4598451.621636203,-13247454.246160466,4618019.500877209) }, 'tiff-reprojection-1': {'sizes':[(250,250)]}, 'tiff-reprojection-2': {'sizes':[(250,250)]}, # https://github.com/mapnik/mapnik/issues/1520 # commented because these are not critical failures #'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)]}, } class Reporting: DIFF = 1 NOT_FOUND = 2 OTHER = 3 REPLACE = 4 def __init__(self, quiet, overwrite_failures = False): self.quiet = quiet self.passed = 0 self.failed = 0 self.overwrite_failures = overwrite_failures self.errors = [ #(type, actual, expected, diff, message) ] def result_fail(self, actual, expected, diff): self.failed += 1 if self.quiet: 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)) def result_pass(self, actual, expected, diff): self.passed += 1 if self.quiet: sys.stderr.write('\x1b[32m.\x1b[0m') else: print '\x1b[32m✓\x1b[0m' def not_found(self, actual, expected): 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) def other_error(self, expected, message): 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 def make_html_item(self,actual,expected,diff): item = '''
''' % (expected,expected,'%') item += '