add tests for map 'base' parameter

This commit is contained in:
Dane Springmeyer 2011-05-25 23:51:08 +00:00
parent 7a17c7e597
commit b7a0204bf2
2 changed files with 20 additions and 7 deletions

View file

@ -14,6 +14,12 @@ For a complete change history, see the SVN log.
Mapnik Trunk Mapnik Trunk
------------ ------------
- Added map.base parameter that can be set to control where files with relative paths should be interpreted
from when a map is loaded from a string or saved to a string. It defaults to an empty string which means
that the base path will be the current working directory of the mapnik process. When a stylesheet is read
from a file that files directory is used. And a custom value can still be passed as an argument to
load_map_from_string().
- Added python function 'render_grid' to allow conversion of grid buffer to python object containing list of grid - Added python function 'render_grid' to allow conversion of grid buffer to python object containing list of grid
pixels, list of keys, and a and dictionary of feature attributes. pixels, list of keys, and a and dictionary of feature attributes.

View file

@ -344,16 +344,14 @@ def test_map_init():
eq_(m.width, 256) eq_(m.width, 256)
eq_(m.height, 256) eq_(m.height, 256)
eq_(m.srs, '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs') eq_(m.srs, '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs')
eq_(m.base, '')
m = mapnik2.Map(256, 256, '+proj=latlong') m = mapnik2.Map(256, 256, '+proj=latlong')
eq_(m.width, 256)
eq_(m.height, 256)
eq_(m.srs, '+proj=latlong') eq_(m.srs, '+proj=latlong')
# Map initialization from string # Map initialization from string
def test_map_init_from_string(): def test_map_init_from_string():
map_string = '''<Map background-color="steelblue" srs="+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"> map_string = '''<Map background-color="steelblue" base="./" srs="+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs">
<Style name="My Style"> <Style name="My Style">
<Rule> <Rule>
<PolygonSymbolizer> <PolygonSymbolizer>
@ -375,10 +373,19 @@ def test_map_init_from_string():
</Map>''' </Map>'''
m = mapnik2.Map(600, 300) m = mapnik2.Map(600, 300)
eq_(m.base, '')
mapnik2.load_map_from_string(m, map_string) mapnik2.load_map_from_string(m, map_string)
mapnik2.load_map_from_string(m, map_string, False, "") eq_(m.base, './')
mapnik2.load_map_from_string(m, map_string, True, "") mapnik2.load_map_from_string(m, map_string, False, "") # this "" will have no effect
eq_(m.base, './')
try:
mapnik2.load_map_from_string(m, map_string, False, "/tmp")
except RuntimeError:
pass # runtime error expected because shapefile path should be wrong and datasource will throw
eq_(m.base, '/tmp') # /tmp will be set despite the exception because load_map mostly worked
m.base = 'foo'
mapnik2.load_map_from_string(m, map_string, True, ".")
eq_(m.base, '.')
raise(Todo("Need to write more map property tests in 'object_test.py'...")) raise(Todo("Need to write more map property tests in 'object_test.py'..."))
# Map pickling # Map pickling