csv plugin: ensure that the datasource throws if invalid attributes are queried to keep consistent with other datasource - refs #792
This commit is contained in:
parent
c683be63d2
commit
ddeca1e81e
2 changed files with 38 additions and 2 deletions
|
@ -851,8 +851,31 @@ mapnik::featureset_ptr csv_datasource::features(mapnik::query const& q) const
|
|||
{
|
||||
if (!is_bound_) bind();
|
||||
|
||||
// TODO - should we check q.property_names() and throw if not found in headers_?
|
||||
// const std::set<std::string>& attribute_names = q.property_names();
|
||||
const std::set<std::string>& attribute_names = q.property_names();
|
||||
std::set<std::string>::const_iterator pos = attribute_names.begin();
|
||||
while (pos != attribute_names.end())
|
||||
{
|
||||
bool found_name = false;
|
||||
for (int i = 0; i < headers_.size(); ++i)
|
||||
{
|
||||
if (headers_[i] == *pos)
|
||||
{
|
||||
found_name = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (! found_name)
|
||||
{
|
||||
std::ostringstream s;
|
||||
|
||||
s << "CSV Plugin: no attribute '" << *pos << "'. Valid attributes are: "
|
||||
<< boost::algorithm::join(headers_, ",") << ".";
|
||||
|
||||
throw mapnik::datasource_exception(s.str());
|
||||
}
|
||||
++pos;
|
||||
}
|
||||
|
||||
return boost::make_shared<mapnik::memory_featureset>(q.get_bbox(),features_);
|
||||
}
|
||||
|
|
|
@ -214,6 +214,19 @@ if 'csv' in mapnik.DatasourceCache.instance().plugin_names():
|
|||
eq_(feat['null'],'')
|
||||
eq_(feat['boolean'],'false')
|
||||
|
||||
@raises(RuntimeError)
|
||||
def test_that_nonexistant_query_field_throws(**kwargs):
|
||||
ds = get_csv_ds('lon_lat.csv')
|
||||
eq_(len(ds.fields()),2)
|
||||
eq_(ds.fields(),['lon','lat'])
|
||||
eq_(ds.field_types(),['int','int'])
|
||||
query = mapnik.Query(ds.envelope())
|
||||
for fld in ds.fields():
|
||||
query.add_property_name(fld)
|
||||
# also add an invalid one, triggering throw
|
||||
query.add_property_name('bogus')
|
||||
fs = ds.features(query)
|
||||
|
||||
if __name__ == "__main__":
|
||||
setup()
|
||||
[eval(run)(visual=True) for run in dir() if 'test_' in run]
|
||||
|
|
Loading…
Reference in a new issue