1- #!/usr/bin/env python
21import os
32import sqlite3
43import sys
54import threading
6-
7- from nose .tools import eq_
8-
95import mapnik
10-
11- from .utilities import execution_path , run_all
12-
13- PYTHON3 = sys .version_info [0 ] == 3
6+ import pytest
7+ from .utilities import execution_path
148
159
10+ @pytest .fixture (scope = "module" )
1611def setup ():
1712 # All of the paths used are relative, if we run the tests
1813 # from another directory we need to chdir()
1914 os .chdir (execution_path ('.' ))
15+ yield
16+
2017
2118NUM_THREADS = 10
2219TOTAL = 245
2320
24-
2521def create_ds (test_db , table ):
2622 ds = mapnik .SQLite (file = test_db , table = table )
2723 ds .all_features ()
2824 del ds
2925
3026if 'sqlite' in mapnik .DatasourceCache .plugin_names ():
3127
32- def test_rtree_creation ():
28+ def test_rtree_creation (setup ):
3329 test_db = '../data/sqlite/world.sqlite'
3430 index = test_db + '.index'
3531 table = 'world_merc'
@@ -46,7 +42,7 @@ def test_rtree_creation():
4642 for i in threads :
4743 i .join ()
4844
49- eq_ ( os .path .exists (index ), True )
45+ assert os .path .exists (index )
5046 conn = sqlite3 .connect (index )
5147 cur = conn .cursor ()
5248 try :
@@ -55,7 +51,7 @@ def test_rtree_creation():
5551 table .replace (
5652 "'" , "" ))
5753 conn .commit ()
58- eq_ ( cur .fetchone ()[0 ], TOTAL )
54+ assert cur .fetchone ()[0 ] == TOTAL
5955 except sqlite3 .OperationalError :
6056 # don't worry about testing # of index records if
6157 # python's sqlite module does not support rtree
@@ -66,13 +62,13 @@ def test_rtree_creation():
6662 ds = mapnik .SQLite (file = test_db , table = table )
6763 fs = list (ds .all_features ())
6864 del ds
69- eq_ ( len (fs ), TOTAL )
65+ assert len (fs ) == TOTAL
7066 os .unlink (index )
7167 ds = mapnik .SQLite (file = test_db , table = table , use_spatial_index = False )
7268 fs = list (ds .all_features ())
7369 del ds
74- eq_ ( len (fs ), TOTAL )
75- eq_ ( os .path .exists (index ), False )
70+ assert len (fs ) == TOTAL
71+ assert os .path .exists (index ) == False
7672
7773 ds = mapnik .SQLite (file = test_db , table = table , use_spatial_index = True )
7874 fs = list (ds .all_features ())
@@ -82,10 +78,10 @@ def test_rtree_creation():
8278 # for feat in fs:
8379 # query = mapnik.Query(feat.envelope())
8480 # selected = ds.features(query)
85- # eq_( len(selected.features)>=1, True)
81+ # assert len(selected.features)>=1 == True
8682 del ds
8783
88- eq_ ( os .path .exists (index ), True )
84+ assert os .path .exists (index ) == True
8985 os .unlink (index )
9086
9187 test_rtree_creation .requires_data = True
@@ -148,17 +144,17 @@ def make_wkb_point(x, y):
148144
149145 # confirm the wkb matches a manually formed wkb
150146 wkb2 = make_wkb_point (x , y )
151- eq_ ( wkb , wkb2 )
147+ assert wkb == wkb2
152148
153149 # ensure we can read this data back out properly with mapnik
154150 ds = mapnik .Datasource (
155151 ** {'type' : 'sqlite' , 'file' : test_db , 'table' : 'point_table' })
156152 fs = ds .featureset ()
157153 feat = fs .next ()
158- eq_ ( feat .id (), 1 )
159- eq_ ( feat ['name' ], 'test point' )
154+ assert feat .id () == 1
155+ assert feat ['name' ] == 'test point'
160156 geom = feat .geometry
161- eq_ ( geom .to_wkt (), 'POINT(-122 48)' )
157+ assert geom .to_wkt () == 'POINT(-122 48)'
162158 del ds
163159
164160 # ensure it matches data read with just sqlite
@@ -169,19 +165,12 @@ def make_wkb_point(x, y):
169165 result = cur .fetchone ()
170166 cur .close ()
171167 feat_id = result [0 ]
172- eq_ ( feat_id , 1 )
168+ assert feat_id == 1
173169 name = result [2 ]
174- eq_ ( name , 'test point' )
170+ assert name == 'test point'
175171 geom_wkb_blob = result [1 ]
176- if not PYTHON3 :
177- geom_wkb_blob = str (geom_wkb_blob )
178- eq_ (geom_wkb_blob , geom .to_wkb (mapnik .wkbByteOrder .NDR ))
172+ assert geom_wkb_blob == geom .to_wkb (mapnik .wkbByteOrder .NDR )
179173 new_geom = mapnik .Geometry .from_wkb (geom_wkb_blob )
180- eq_ ( new_geom .to_wkt (), geom .to_wkt () )
174+ assert new_geom .to_wkt () == geom .to_wkt ()
181175 conn .close ()
182176 os .unlink (test_db )
183-
184- if __name__ == "__main__" :
185- setup ()
186- returncode = run_all (eval (x ) for x in dir () if x .startswith ("test_" ))
187- exit (returncode )
0 commit comments