fixup parameters conversion from python
This commit is contained in:
parent
866597c8c3
commit
e0622be27d
2 changed files with 21 additions and 24 deletions
|
@ -175,17 +175,7 @@ mapnik::value_holder get_param(mapnik::parameter const& p, int index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::shared_ptr<mapnik::parameter> create_parameter_from_string(std::string const& key, std::string const& value)
|
boost::shared_ptr<mapnik::parameter> create_parameter(std::string const& key, mapnik::value_holder const& value)
|
||||||
{
|
|
||||||
return boost::make_shared<mapnik::parameter>(key,mapnik::value_holder(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
boost::shared_ptr<mapnik::parameter> create_parameter_from_int(std::string const& key, mapnik::value_integer value)
|
|
||||||
{
|
|
||||||
return boost::make_shared<mapnik::parameter>(key,mapnik::value_holder(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
boost::shared_ptr<mapnik::parameter> create_parameter_from_float(std::string const& key, double value)
|
|
||||||
{
|
{
|
||||||
return boost::make_shared<mapnik::parameter>(key,mapnik::value_holder(value));
|
return boost::make_shared<mapnik::parameter>(key,mapnik::value_holder(value));
|
||||||
}
|
}
|
||||||
|
@ -194,14 +184,13 @@ boost::shared_ptr<mapnik::parameter> create_parameter_from_float(std::string con
|
||||||
void export_parameters()
|
void export_parameters()
|
||||||
{
|
{
|
||||||
using namespace boost::python;
|
using namespace boost::python;
|
||||||
|
implicitly_convertible<std::string,mapnik::value_holder>();
|
||||||
|
implicitly_convertible<mapnik::value_null,mapnik::value_holder>();
|
||||||
|
implicitly_convertible<mapnik::value_integer,mapnik::value_holder>();
|
||||||
|
implicitly_convertible<mapnik::value_double,mapnik::value_holder>();
|
||||||
|
|
||||||
class_<parameter,boost::shared_ptr<parameter> >("Parameter",no_init)
|
class_<parameter,boost::shared_ptr<parameter> >("Parameter",no_init)
|
||||||
.def("__init__", make_constructor(create_parameter_from_string),
|
.def("__init__", make_constructor(create_parameter),
|
||||||
"Create a mapnik.Parameter from a pair of values, the first being a string\n"
|
|
||||||
"and the second being either a string, and integer, or a float")
|
|
||||||
.def("__init__", make_constructor(create_parameter_from_float),
|
|
||||||
"Create a mapnik.Parameter from a pair of values, the first being a string\n"
|
|
||||||
"and the second being either a string, and integer, or a float")
|
|
||||||
.def("__init__", make_constructor(create_parameter_from_int),
|
|
||||||
"Create a mapnik.Parameter from a pair of values, the first being a string\n"
|
"Create a mapnik.Parameter from a pair of values, the first being a string\n"
|
||||||
"and the second being either a string, and integer, or a float")
|
"and the second being either a string, and integer, or a float")
|
||||||
.def_pickle(parameter_pickle_suite())
|
.def_pickle(parameter_pickle_suite())
|
||||||
|
|
|
@ -11,22 +11,30 @@ import mapnik
|
||||||
def setup():
|
def setup():
|
||||||
os.chdir(execution_path('.'))
|
os.chdir(execution_path('.'))
|
||||||
|
|
||||||
def test_parameter():
|
def test_parameter_null():
|
||||||
|
p = mapnik.Parameter('key',None)
|
||||||
|
eq_(p[0],'key')
|
||||||
|
eq_(p[1],None)
|
||||||
|
|
||||||
|
def test_parameter_string():
|
||||||
p = mapnik.Parameter('key','value')
|
p = mapnik.Parameter('key','value')
|
||||||
eq_(p[0],'key')
|
eq_(p[0],'key')
|
||||||
eq_(p[1],'value')
|
eq_(p[1],'value')
|
||||||
|
|
||||||
|
def test_parameter_integer():
|
||||||
p = mapnik.Parameter('int',sys.maxint)
|
p = mapnik.Parameter('int',sys.maxint)
|
||||||
eq_(p[0],'int')
|
eq_(p[0],'int')
|
||||||
eq_(p[1],sys.maxint)
|
eq_(p[1],sys.maxint)
|
||||||
|
|
||||||
p = mapnik.Parameter('float',float(sys.maxint))
|
def test_parameter_double():
|
||||||
eq_(p[0],'float')
|
p = mapnik.Parameter('double',float(sys.maxint))
|
||||||
|
eq_(p[0],'double')
|
||||||
eq_(p[1],float(sys.maxint))
|
eq_(p[1],float(sys.maxint))
|
||||||
|
|
||||||
p = mapnik.Parameter('bool_string','True')
|
def test_parameter_boolean():
|
||||||
eq_(p[0],'bool_string')
|
p = mapnik.Parameter('boolean',True)
|
||||||
eq_(p[1],'True')
|
eq_(p[0],'boolean')
|
||||||
|
eq_(p[1],True)
|
||||||
eq_(bool(p[1]),True)
|
eq_(bool(p[1]),True)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue