Skip to content

Commit

Permalink
tests: make the sqlite rtree test more flexible
Browse files Browse the repository at this point in the history
  • Loading branch information
Dane Springmeyer committed Nov 19, 2011
1 parent f2a4e0c commit 0999523
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions tests/python_tests/sqlite_rtree_test.py
Expand Up @@ -14,12 +14,12 @@ def setup():
os.chdir(execution_path('.'))

NUM_THREADS = 10

TOTAL = 245
DB = '../data/sqlite/world.sqlite'
TABLE= 'world_merc'

def create_ds():
ds = mapnik2.SQLite(file=DB,table='world_merc')
ds = mapnik2.SQLite(file=DB,table=TABLE)
fs = ds.all_features()

if 'sqlite' in mapnik2.DatasourceCache.instance().plugin_names():
Expand All @@ -42,20 +42,31 @@ def test_rtree_creation():
eq_(os.path.exists(index),True)
conn = sqlite3.connect(index)
cur = conn.cursor()
cur.execute("Select count(*) from idx_world_merc_GEOMETRY")
cur.execute("Select count(*) from idx_%s_GEOMETRY" % TABLE.replace("'",""))
conn.commit()
eq_(cur.fetchone()[0],TOTAL)
cur.close()

ds = mapnik2.SQLite(file=DB,table='world_merc')
ds = mapnik2.SQLite(file=DB,table=TABLE)
fs = ds.all_features()
eq_(len(fs),TOTAL)
os.unlink(index)
ds = mapnik2.SQLite(file=DB,table='world_merc',use_spatial_index=False)
ds = mapnik2.SQLite(file=DB,table=TABLE,use_spatial_index=False)
fs = ds.all_features()
eq_(len(fs),TOTAL)
eq_(os.path.exists(index),False)

ds = mapnik2.SQLite(file=DB,table=TABLE,use_spatial_index=True)
fs = ds.all_features()
for feat in fs:
query = mapnik2.Query(feat.envelope())
selected = ds.features(query)
eq_(len(selected.features)>=1,True)

eq_(os.path.exists(index),True)
os.unlink(index)


if __name__ == "__main__":
setup()
[eval(run)() for run in dir() if 'test_' in run]
Expand Down

0 comments on commit 0999523

Please sign in to comment.