2011-11-14 00:42:37 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
from nose.tools import *
|
|
|
|
from utilities import execution_path
|
|
|
|
from Queue import Queue
|
|
|
|
import threading
|
|
|
|
|
2011-11-23 11:33:58 +00:00
|
|
|
import os, mapnik
|
2011-11-14 00:42:37 +00:00
|
|
|
import sqlite3
|
|
|
|
|
|
|
|
def setup():
|
|
|
|
# All of the paths used are relative, if we run the tests
|
|
|
|
# from another directory we need to chdir()
|
|
|
|
os.chdir(execution_path('.'))
|
|
|
|
|
|
|
|
NUM_THREADS = 10
|
2011-11-14 01:00:34 +00:00
|
|
|
TOTAL = 245
|
2011-11-14 00:42:37 +00:00
|
|
|
DB = '../data/sqlite/world.sqlite'
|
2011-11-19 19:39:59 +00:00
|
|
|
TABLE= 'world_merc'
|
2011-11-14 00:42:37 +00:00
|
|
|
|
|
|
|
def create_ds():
|
2011-11-23 11:33:58 +00:00
|
|
|
ds = mapnik.SQLite(file=DB,table=TABLE)
|
2011-11-14 00:42:37 +00:00
|
|
|
fs = ds.all_features()
|
|
|
|
|
2011-11-23 11:33:58 +00:00
|
|
|
if 'sqlite' in mapnik.DatasourceCache.instance().plugin_names():
|
2012-02-24 21:13:56 +00:00
|
|
|
|
2011-11-14 00:42:37 +00:00
|
|
|
def test_rtree_creation():
|
|
|
|
|
|
|
|
index = DB +'.index'
|
|
|
|
if os.path.exists(index):
|
|
|
|
os.unlink(index)
|
|
|
|
|
|
|
|
threads = []
|
|
|
|
for i in range(NUM_THREADS):
|
|
|
|
t = threading.Thread(target=create_ds)
|
|
|
|
t.start()
|
|
|
|
threads.append(t)
|
|
|
|
|
|
|
|
for i in threads:
|
|
|
|
i.join()
|
2012-02-24 21:13:56 +00:00
|
|
|
|
2011-11-14 01:00:34 +00:00
|
|
|
eq_(os.path.exists(index),True)
|
|
|
|
conn = sqlite3.connect(index)
|
|
|
|
cur = conn.cursor()
|
2011-12-01 03:15:11 +00:00
|
|
|
try:
|
|
|
|
cur.execute("Select count(*) from idx_%s_GEOMETRY" % TABLE.replace("'",""))
|
|
|
|
conn.commit()
|
|
|
|
eq_(cur.fetchone()[0],TOTAL)
|
|
|
|
except sqlite3.OperationalError:
|
|
|
|
# don't worry about testing # of index records if
|
|
|
|
# python's sqlite module does not support rtree
|
|
|
|
pass
|
2011-11-14 01:00:34 +00:00
|
|
|
cur.close()
|
|
|
|
|
2011-11-23 11:33:58 +00:00
|
|
|
ds = mapnik.SQLite(file=DB,table=TABLE)
|
2011-11-14 01:00:34 +00:00
|
|
|
fs = ds.all_features()
|
|
|
|
eq_(len(fs),TOTAL)
|
|
|
|
os.unlink(index)
|
2011-11-23 11:33:58 +00:00
|
|
|
ds = mapnik.SQLite(file=DB,table=TABLE,use_spatial_index=False)
|
2011-11-14 01:00:34 +00:00
|
|
|
fs = ds.all_features()
|
|
|
|
eq_(len(fs),TOTAL)
|
|
|
|
eq_(os.path.exists(index),False)
|
2011-11-14 00:42:37 +00:00
|
|
|
|
2011-11-23 11:33:58 +00:00
|
|
|
ds = mapnik.SQLite(file=DB,table=TABLE,use_spatial_index=True)
|
2011-11-19 19:39:59 +00:00
|
|
|
fs = ds.all_features()
|
|
|
|
for feat in fs:
|
2011-11-23 11:33:58 +00:00
|
|
|
query = mapnik.Query(feat.envelope())
|
2011-11-19 19:39:59 +00:00
|
|
|
selected = ds.features(query)
|
|
|
|
eq_(len(selected.features)>=1,True)
|
|
|
|
|
|
|
|
eq_(os.path.exists(index),True)
|
|
|
|
os.unlink(index)
|
|
|
|
|
|
|
|
|
2011-11-14 00:42:37 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
setup()
|
|
|
|
[eval(run)() for run in dir() if 'test_' in run]
|