From e0622be27d1edaaee6c00a8f57fdfd0eed0490ae Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Fri, 4 Jan 2013 11:28:00 -0800 Subject: [PATCH] fixup parameters conversion from python --- bindings/python/mapnik_parameters.cpp | 25 +++++++------------------ tests/python_tests/parameters_test.py | 20 ++++++++++++++------ 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/bindings/python/mapnik_parameters.cpp b/bindings/python/mapnik_parameters.cpp index ca6545dbe..02fdc8671 100644 --- a/bindings/python/mapnik_parameters.cpp +++ b/bindings/python/mapnik_parameters.cpp @@ -175,17 +175,7 @@ mapnik::value_holder get_param(mapnik::parameter const& p, int index) } } -boost::shared_ptr create_parameter_from_string(std::string const& key, std::string const& value) -{ - return boost::make_shared(key,mapnik::value_holder(value)); -} - -boost::shared_ptr create_parameter_from_int(std::string const& key, mapnik::value_integer value) -{ - return boost::make_shared(key,mapnik::value_holder(value)); -} - -boost::shared_ptr create_parameter_from_float(std::string const& key, double value) +boost::shared_ptr create_parameter(std::string const& key, mapnik::value_holder const& value) { return boost::make_shared(key,mapnik::value_holder(value)); } @@ -194,14 +184,13 @@ boost::shared_ptr create_parameter_from_float(std::string con void export_parameters() { using namespace boost::python; + implicitly_convertible(); + implicitly_convertible(); + implicitly_convertible(); + implicitly_convertible(); + class_ >("Parameter",no_init) - .def("__init__", make_constructor(create_parameter_from_string), - "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), + .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_pickle(parameter_pickle_suite()) diff --git a/tests/python_tests/parameters_test.py b/tests/python_tests/parameters_test.py index bead2564a..e9123816f 100644 --- a/tests/python_tests/parameters_test.py +++ b/tests/python_tests/parameters_test.py @@ -11,22 +11,30 @@ import mapnik def setup(): 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') eq_(p[0],'key') eq_(p[1],'value') +def test_parameter_integer(): p = mapnik.Parameter('int',sys.maxint) eq_(p[0],'int') eq_(p[1],sys.maxint) - p = mapnik.Parameter('float',float(sys.maxint)) - eq_(p[0],'float') +def test_parameter_double(): + p = mapnik.Parameter('double',float(sys.maxint)) + eq_(p[0],'double') eq_(p[1],float(sys.maxint)) - p = mapnik.Parameter('bool_string','True') - eq_(p[0],'bool_string') - eq_(p[1],'True') +def test_parameter_boolean(): + p = mapnik.Parameter('boolean',True) + eq_(p[0],'boolean') + eq_(p[1],True) eq_(bool(p[1]),True)