Skip to content

Commit d8a6e05

Browse files
committed
Unite test pycaro [WIP]
1 parent 45ed937 commit d8a6e05

3 files changed

Lines changed: 36 additions & 67 deletions

File tree

test/python_tests/save_map_test.py

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,19 @@
1-
#!/usr/bin/env python
2-
31
import glob
42
import os
53
import tempfile
6-
7-
from nose.tools import eq_
8-
94
import mapnik
5+
import pytest
106

11-
from .utilities import execution_path, run_all
12-
7+
from .utilities import execution_path
138

149
default_logging_severity = mapnik.logger.get_severity()
1510

16-
11+
@pytest.fixture(scope="module")
1712
def setup():
18-
# make the tests silent to suppress unsupported params from harfbuzz tests
19-
# TODO: remove this after harfbuzz branch merges
20-
mapnik.logger.set_severity(getattr(mapnik.severity_type, "None"))
2113
# All of the paths used are relative, if we run the tests
2214
# from another directory we need to chdir()
2315
os.chdir(execution_path('.'))
24-
25-
26-
def teardown():
27-
mapnik.logger.set_severity(default_logging_severity)
28-
16+
yield
2917

3018
def compare_map(xml):
3119
m = mapnik.Map(256, 256)
@@ -56,7 +44,7 @@ def compare_map(xml):
5644
try:
5745
with open(test_map) as f1:
5846
with open(test_map2) as f2:
59-
eq_(f1.read(), f2.read())
47+
assert f1.read() == f2.read()
6048
except AssertionError as e:
6149
raise AssertionError(
6250
'serialized map "%s" not the same after being reloaded, \ncompare with command:\n\n$%s' %
@@ -69,7 +57,7 @@ def compare_map(xml):
6957
return False
7058

7159

72-
def test_compare_map():
60+
def test_compare_map(setup):
7361
good_maps = glob.glob("../data/good_maps/*.xml")
7462
good_maps = [os.path.normpath(p) for p in good_maps]
7563
# remove one map that round trips CDATA differently, but this is okay
@@ -89,7 +77,3 @@ def test_compare_map_deprecations():
8977
dep = [os.path.normpath(p) for p in dep]
9078
for m in dep:
9179
compare_map(m)
92-
93-
if __name__ == "__main__":
94-
setup()
95-
exit(run_all(eval(x) for x in dir() if x.startswith("test_")))

test/python_tests/shapeindex_test.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
#!/usr/bin/env python
2-
31
import fnmatch
42
import os
53
import shutil
64
from subprocess import PIPE, Popen
75

8-
from nose.tools import eq_
9-
106
import mapnik
7+
import pytest
118

12-
from .utilities import execution_path, run_all
13-
9+
from .utilities import execution_path
1410

11+
@pytest.fixture(scope="module")
1512
def setup():
1613
# All of the paths used are relative, if we run the tests
1714
# from another directory we need to chdir()
1815
os.chdir(execution_path('.'))
16+
yield
17+
index = '../data/sqlite/world.sqlite.index'
18+
if os.path.exists(index):
19+
os.unlink(index)
1920

20-
21-
def test_shapeindex():
21+
def test_shapeindex(setup):
2222
# first copy shapefiles to tmp directory
2323
source_dir = '../data/shp/'
2424
working_dir = '/tmp/mapnik-shp-tmp/'
@@ -53,8 +53,4 @@ def test_shapeindex():
5353
count2 = count2 + 1
5454
except StopIteration:
5555
pass
56-
eq_(count, count2)
57-
58-
if __name__ == "__main__":
59-
setup()
60-
exit(run_all(eval(x) for x in dir() if x.startswith("test_")))
56+
assert count == count2

test/python_tests/sqlite_rtree_test.py

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,31 @@
1-
#!/usr/bin/env python
21
import os
32
import sqlite3
43
import sys
54
import threading
6-
7-
from nose.tools import eq_
8-
95
import 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")
1611
def 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

2118
NUM_THREADS = 10
2219
TOTAL = 245
2320

24-
2521
def create_ds(test_db, table):
2622
ds = mapnik.SQLite(file=test_db, table=table)
2723
ds.all_features()
2824
del ds
2925

3026
if '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

Comments
 (0)