Created
August 21, 2012 02:27
-
-
Save springmeyer/3410845 to your computer and use it in GitHub Desktop.
look for omissions or inconsistencies in mapnik's python bindings using mapnik-reference
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import mapnik | |
import json | |
reference = json.load(open('../mapnik-reference/2.1.0/reference.json', 'r')) | |
style = mapnik.Style() | |
for prop in reference['style'].items(): | |
key = prop[0].replace('-','_') | |
assert hasattr(style,key), "'%s' not a valid property of Style" % key | |
layer = mapnik.Layer('foo') | |
for prop in reference['layer'].items(): | |
key = prop[0].replace('-','_') | |
assert hasattr(layer,key), "'%s' not a valid property of Layer" % key | |
map_instance = mapnik.Map(256,256) | |
for prop in reference['symbolizers']['map'].items(): | |
key = prop[0].replace('-','_') | |
# https://github.com/mapnik/mapnik/issues/1419 | |
if not key in ['minimum_version','paths_from_xml','font_directory']: | |
assert hasattr(map_instance,key), "'%s' not a valid property of Map" % key | |
total_fails = 0 | |
before = 0 | |
for sym in reference['symbolizers'].items(): | |
if sym[0] not in ['map','*']: | |
sym_name = ''.join([s.title() for s in sym[0].split('-')]) | |
sym_object = getattr(mapnik,sym_name+'Symbolizer') | |
instance_var = None | |
if sym_name in ['PolygonPattern','LinePattern']: | |
instance_var = sym_object(mapnik.PathExpression('')) | |
elif sym_name == 'Shield': | |
instance_var = sym_object(mapnik.Expression('True'),'DejaVu Sans Book', 10, mapnik.Color('black'), mapnik.PathExpression('')) | |
else: | |
instance_var = sym_object() | |
fails = [] | |
for prop in sym[1]: | |
key = prop.replace('-','_') | |
if key == 'file': | |
key = 'filename' | |
if sym_name == 'Line' and 'stroke' in key: | |
stroke_instance = instance_var.stroke | |
if key == 'stroke': | |
key = 'color' | |
else: | |
key = key.replace('stroke_','') | |
if not hasattr(stroke_instance,key): | |
fails.append("'%s' not a valid property of %s" % (key,'Stroke')) | |
elif sym_name == 'Markers' and 'stroke' in key: | |
stroke_instance = instance_var.stroke | |
if not stroke_instance: # marker.stroke is boost::optional | |
stroke_instance = mapnik.Stroke() | |
if key == 'stroke': | |
key = 'color' | |
else: | |
key = key.replace('stroke_','') | |
if not hasattr(stroke_instance,key): | |
fails.append("'%s' not a valid property of %s" % (key,'Stroke')) | |
else: | |
if not hasattr(instance_var,key): | |
fails.append("'%s' not a valid property of %s" % (key,sym_name)) | |
if len(fails): | |
print '\n\n%s -->\n' % (sym_name) | |
for f in fails: | |
print f | |
print '(' + '|'.join([i for i in dir(instance_var) if not '__' in i]) + ')' | |
total_fails += len(fails); | |
print '\n\nTOTAL FAILS: %s' % total_fails |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment