2010-03-19 16:16:15 +00:00
|
|
|
#encoding: utf8
|
|
|
|
import itertools
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
from utilities import Todo
|
|
|
|
|
|
|
|
class MemoryDatasource(unittest.TestCase):
|
|
|
|
ids = itertools.count(0)
|
|
|
|
|
|
|
|
def makeOne(self, *args, **kw):
|
2011-11-23 11:33:58 +00:00
|
|
|
from mapnik import MemoryDatasource
|
2010-03-19 16:16:15 +00:00
|
|
|
return MemoryDatasource(*args, **kw)
|
|
|
|
|
2011-09-13 13:32:42 +00:00
|
|
|
def makeFeature(self, wkt, **properties):
|
2011-11-23 11:33:58 +00:00
|
|
|
from mapnik import Feature
|
2010-03-19 16:16:15 +00:00
|
|
|
f = Feature(self.ids.next())
|
2011-09-13 13:32:42 +00:00
|
|
|
f.add_geometries_from_wkt(wkt)
|
2010-03-19 16:16:15 +00:00
|
|
|
for k,v in properties.iteritems():
|
|
|
|
f[k] = v
|
|
|
|
return f
|
|
|
|
|
|
|
|
def test_default_constructor(self):
|
|
|
|
f = self.makeOne()
|
|
|
|
self.failUnless(f is not None)
|
|
|
|
|
|
|
|
def test_add_feature(self):
|
|
|
|
md = self.makeOne()
|
|
|
|
self.failUnlessEqual(md.num_features(), 0)
|
2011-09-13 13:32:42 +00:00
|
|
|
md.add_feature(self.makeFeature('Point(2 3)', foo='bar'))
|
2010-03-19 16:16:15 +00:00
|
|
|
self.failUnlessEqual(md.num_features(), 1)
|
|
|
|
|
2011-11-23 11:33:58 +00:00
|
|
|
from mapnik import Coord
|
2010-03-19 16:16:15 +00:00
|
|
|
retrieved = md.features_at_point(Coord(2,3)).features
|
|
|
|
self.failUnlessEqual(len(retrieved), 1)
|
|
|
|
f = retrieved[0]
|
|
|
|
self.failUnlessEqual(f['foo'], 'bar')
|
|
|
|
|
|
|
|
retrieved = md.features_at_point(Coord(20,30)).features
|
|
|
|
self.failUnlessEqual(len(retrieved), 0)
|
2011-08-30 22:51:42 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
[eval(run)() for run in dir() if 'test_' in run]
|