fixup tests around parameters usage
This commit is contained in:
parent
ad41bca19a
commit
e991f3c94e
5 changed files with 93 additions and 6 deletions
|
@ -119,6 +119,8 @@ struct map_pickle_suite : boost::python::pickle_suite
|
|||
std::vector<layer>& (Map::*layers_nonconst)() = &Map::layers;
|
||||
std::vector<layer> const& (Map::*layers_const)() const = &Map::layers;
|
||||
|
||||
mapnik::parameters& (Map::*attr_nonconst)() = &Map::get_extra_attributes;
|
||||
mapnik::parameters& (Map::*params_nonconst)() = &Map::get_extra_parameters;
|
||||
|
||||
mapnik::feature_type_style find_style (mapnik::Map const& m, std::string const& name)
|
||||
{
|
||||
|
@ -173,6 +175,7 @@ mapnik::featureset_ptr query_map_point(mapnik::Map const& m, int index, double x
|
|||
return m.query_map_point(idx, x, y);
|
||||
}
|
||||
|
||||
|
||||
void export_map()
|
||||
{
|
||||
using namespace boost::python;
|
||||
|
@ -449,7 +452,8 @@ void export_map()
|
|||
"about the hit areas rendered on the map.\n"
|
||||
)
|
||||
|
||||
.def("extra_attributes",&Map::get_extra_attributes,return_value_policy<copy_const_reference>(),"TODO")
|
||||
.add_property("extra_attributes",make_function(attr_nonconst,return_value_policy<reference_existing_object>()),"TODO")
|
||||
.add_property("params",make_function(params_nonconst,return_value_policy<reference_existing_object>()),"TODO")
|
||||
|
||||
.add_property("aspect_fix_mode",
|
||||
&Map::get_aspect_fix_mode,
|
||||
|
|
20
tests/data/good_maps/extra_arbitary_map_parameters.xml
Normal file
20
tests/data/good_maps/extra_arbitary_map_parameters.xml
Normal file
|
@ -0,0 +1,20 @@
|
|||
<Map>
|
||||
|
||||
<!--
|
||||
totally arbirary Parameters can also be attached to the map
|
||||
which will be respected during serialization.
|
||||
|
||||
This makes it easier for calling applications that work with mapnik
|
||||
xml, and leverage its serialization, to pass through directives that
|
||||
the calling application needs which describe how to handle the map.
|
||||
-->
|
||||
|
||||
<Parameters>
|
||||
<Parameter name="key"><![CDATA[value]]></Parameter>
|
||||
<!-- this one will override previous key with same name -->
|
||||
<Parameter name="key"><![CDATA[value2]]></Parameter>
|
||||
<Parameter name="key3"><![CDATA[value3]]></Parameter>
|
||||
<Parameter name="unicode"><![CDATA[iván]]></Parameter>
|
||||
</Parameters>
|
||||
|
||||
</Map>
|
11
tests/data/good_maps/extra_known_map_attributes.xml
Normal file
11
tests/data/good_maps/extra_known_map_attributes.xml
Normal file
|
@ -0,0 +1,11 @@
|
|||
<Map font-directory="." minimum-version="0.0.0">
|
||||
|
||||
<!--
|
||||
font-directory and minimin-version are extra attributes known
|
||||
to load_map which are and attached to the map object in order to be
|
||||
carried through and respected by save map.
|
||||
|
||||
They are treated as 'extra' because they have no role during map rendering
|
||||
-->
|
||||
|
||||
</Map>
|
|
@ -28,11 +28,10 @@ def test_arbitrary_parameters_attached_to_map():
|
|||
attr = m.extra_attributes
|
||||
eq_(len(attr),0)
|
||||
|
||||
params = m.extra_parameters
|
||||
eq_(len(params),3)
|
||||
eq_(params['key'],'value2')
|
||||
eq_(params['key3'],'value3')
|
||||
eq_(params['unicode'],u'iván')
|
||||
eq_(len(m.params),3)
|
||||
eq_(m.params['key'],'value2')
|
||||
eq_(m.params['key3'],'value3')
|
||||
eq_(m.params['unicode'],u'iván')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
53
tests/python_tests/parameters_test.py
Normal file
53
tests/python_tests/parameters_test.py
Normal file
|
@ -0,0 +1,53 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
from nose.tools import *
|
||||
from utilities import execution_path
|
||||
|
||||
import mapnik
|
||||
import pickle
|
||||
|
||||
def setup():
|
||||
os.chdir(execution_path('.'))
|
||||
|
||||
def test_parameter():
|
||||
p = mapnik.Parameter('key','value')
|
||||
eq_(p[0],'key')
|
||||
eq_(p[1],'value')
|
||||
|
||||
p = mapnik.Parameter('int',1)
|
||||
eq_(p[0],'int')
|
||||
eq_(p[1],1)
|
||||
|
||||
p = mapnik.Parameter('float',1.0777)
|
||||
eq_(p[0],'float')
|
||||
eq_(p[1],1.0777)
|
||||
|
||||
|
||||
def test_parameters():
|
||||
params = mapnik.Parameters()
|
||||
p = mapnik.Parameter('float',1.0777)
|
||||
eq_(p[0],'float')
|
||||
eq_(p[1],1.0777)
|
||||
|
||||
params.append(p)
|
||||
|
||||
eq_(params[0][0],'float')
|
||||
eq_(params[0][1],1.0777)
|
||||
|
||||
eq_(params.get('float'),1.0777)
|
||||
|
||||
def test_parameters_pickling():
|
||||
params = mapnik.Parameters()
|
||||
params.append(mapnik.Parameter('oh',str('yeah')))
|
||||
|
||||
params2 = pickle.loads(pickle.dumps(params,pickle.HIGHEST_PROTOCOL))
|
||||
|
||||
eq_(params[0][0],params2[0][0])
|
||||
eq_(params[0][1],params2[0][1])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
setup()
|
||||
[eval(run)() for run in dir() if 'test_' in run]
|
Loading…
Add table
Reference in a new issue