2012-11-12 06:35:50 +01:00
|
|
|
import os, mapnik
|
2015-02-02 19:31:16 +01:00
|
|
|
from nose.tools import eq_
|
2013-06-03 04:28:24 +02:00
|
|
|
from utilities import execution_path, run_all
|
2012-11-12 06:35:50 +01:00
|
|
|
|
|
|
|
def setup():
|
|
|
|
# All of the paths used are relative, if we run the tests
|
|
|
|
# from another directory we need to chdir()
|
|
|
|
os.chdir(execution_path('.'))
|
|
|
|
|
|
|
|
def test_clearing_image_data():
|
|
|
|
im = mapnik.Image(256,256)
|
|
|
|
# make sure it equals itself
|
|
|
|
bytes = im.tostring()
|
|
|
|
eq_(im.tostring(),bytes)
|
|
|
|
# set background, then clear
|
2015-01-29 21:27:42 +01:00
|
|
|
im.fill(mapnik.Color('green'))
|
2012-11-12 06:35:50 +01:00
|
|
|
eq_(im.tostring()!=bytes,True)
|
|
|
|
# clear image, should now equal original
|
|
|
|
im.clear()
|
|
|
|
eq_(im.tostring(),bytes)
|
|
|
|
|
|
|
|
def make_map():
|
|
|
|
ds = mapnik.MemoryDatasource()
|
|
|
|
context = mapnik.Context()
|
|
|
|
context.push('Name')
|
|
|
|
pixel_key = 1
|
|
|
|
f = mapnik.Feature(context,pixel_key)
|
|
|
|
f['Name'] = str(pixel_key)
|
|
|
|
f.add_geometries_from_wkt('POLYGON ((0 0, 0 256, 256 256, 256 0, 0 0))')
|
|
|
|
ds.add_feature(f)
|
|
|
|
s = mapnik.Style()
|
|
|
|
r = mapnik.Rule()
|
|
|
|
symb = mapnik.PolygonSymbolizer()
|
|
|
|
r.symbols.append(symb)
|
|
|
|
s.rules.append(r)
|
|
|
|
lyr = mapnik.Layer('Places')
|
|
|
|
lyr.datasource = ds
|
|
|
|
lyr.styles.append('places_labels')
|
|
|
|
width,height = 256,256
|
|
|
|
m = mapnik.Map(width,height)
|
|
|
|
m.append_style('places_labels',s)
|
|
|
|
m.layers.append(lyr)
|
|
|
|
m.zoom_all()
|
|
|
|
return m
|
|
|
|
|
2013-07-24 01:37:25 +02:00
|
|
|
if mapnik.has_grid_renderer():
|
|
|
|
def test_clearing_grid_data():
|
|
|
|
g = mapnik.Grid(256,256)
|
|
|
|
utf = g.encode()
|
|
|
|
# make sure it equals itself
|
|
|
|
eq_(g.encode(),utf)
|
|
|
|
m = make_map()
|
|
|
|
mapnik.render_layer(m,g,layer=0,fields=['__id__','Name'])
|
|
|
|
eq_(g.encode()!=utf,True)
|
|
|
|
# clear grid, should now match original
|
|
|
|
g.clear()
|
|
|
|
eq_(g.encode(),utf)
|
2012-11-12 06:35:50 +01:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
setup()
|
2014-07-14 18:34:20 +02:00
|
|
|
exit(run_all(eval(x) for x in dir() if x.startswith("test_")))
|