Skip to content

Commit f61bfeb

Browse files
committed
convert even more unit tests to use pytest [WIP]
1 parent a3ebedc commit f61bfeb

File tree

9 files changed

+390
-617
lines changed

9 files changed

+390
-617
lines changed

test/python_tests/image_test.py

Lines changed: 149 additions & 171 deletions
Large diffs are not rendered by default.

test/python_tests/image_tiff_test.py

Lines changed: 151 additions & 220 deletions
Large diffs are not rendered by default.
Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,21 @@
1-
#!/usr/bin/env python
2-
3-
import os
4-
5-
from nose.tools import eq_
6-
71
import mapnik
82

9-
from .utilities import execution_path, run_all
10-
11-
12-
def setup():
13-
# All of the paths used are relative, if we run the tests
14-
# from another directory we need to chdir()
15-
os.chdir(execution_path('.'))
16-
17-
183
def test_introspect_symbolizers():
194
# create a symbolizer
205
p = mapnik.PointSymbolizer()
21-
p.file = "../data/images/dummy.png"
6+
p.file = "./test/data/images/dummy.png"
227
p.allow_overlap = True
238
p.opacity = 0.5
249

25-
eq_(p.allow_overlap, True)
26-
eq_(p.opacity, 0.5)
27-
eq_(p.filename, '../data/images/dummy.png')
10+
assert p.allow_overlap == True
11+
assert p.opacity == 0.5
12+
assert p.filename == './test/data/images/dummy.png'
2813

2914
# make sure the defaults
3015
# are what we think they are
31-
eq_(p.allow_overlap, True)
32-
eq_(p.opacity, 0.5)
33-
eq_(p.filename, '../data/images/dummy.png')
16+
assert p.allow_overlap == True
17+
assert p.opacity == 0.5
18+
assert p.filename == './test/data/images/dummy.png'
3419

3520
# contruct objects to hold it
3621
r = mapnik.Rule()
@@ -46,20 +31,16 @@ def test_introspect_symbolizers():
4631

4732
s2 = m.find_style('s')
4833
rules = s2.rules
49-
eq_(len(rules), 1)
34+
assert len(rules) == 1
5035
r2 = rules[0]
5136
syms = r2.symbols
52-
eq_(len(syms), 1)
37+
assert len(syms) == 1
5338

5439
# TODO here, we can do...
5540
sym = syms[0]
5641
p2 = sym.extract()
5742
assert isinstance(p2, mapnik.PointSymbolizer)
5843

59-
eq_(p2.allow_overlap, True)
60-
eq_(p2.opacity, 0.5)
61-
eq_(p2.filename, '../data/images/dummy.png')
62-
63-
if __name__ == "__main__":
64-
setup()
65-
exit(run_all(eval(x) for x in dir() if x.startswith("test_")))
44+
assert p2.allow_overlap == True
45+
assert p2.opacity == 0.5
46+
assert p2.filename == './test/data/images/dummy.png'

test/python_tests/json_feature_properties_test.py

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
# encoding: utf8
2-
3-
from nose.tools import eq_
4-
51
import mapnik
6-
7-
from .utilities import run_all
8-
92
try:
103
import json
114
except ImportError:
@@ -83,30 +76,20 @@
8376
ctx = mapnik.Context()
8477
ctx.push('name')
8578

86-
8779
def test_char_escaping():
8880
for char in chars:
8981
feat = mapnik.Feature(ctx, 1)
9082
expected = char['test']
9183
feat["name"] = expected
92-
eq_(feat["name"], expected)
84+
assert feat["name"] == expected
9385
# confirm the python json module
9486
# is working as we would expect
9587
pyjson2 = json.loads(char['json'])
96-
eq_(pyjson2['properties']['name'], expected)
88+
assert pyjson2['properties']['name'] == expected
9789
# confirm our behavior is the same as python json module
9890
# for the original string
9991
geojson_feat_string = feat.to_geojson()
100-
eq_(
101-
geojson_feat_string,
102-
char['json'],
103-
"Mapnik's json escaping is not to spec: actual(%s) and expected(%s) for %s" %
104-
(geojson_feat_string,
105-
char['json'],
106-
char['name']))
92+
assert geojson_feat_string == char['json'], "Mapnik's json escaping is not to spec: actual(%s) and expected(%s) for %s" % (geojson_feat_string, char['json'], char['name'])
10793
# and the round tripped string
10894
pyjson = json.loads(geojson_feat_string)
109-
eq_(pyjson['properties']['name'], expected)
110-
111-
if __name__ == "__main__":
112-
exit(run_all(eval(x) for x in dir() if x.startswith("test_")))
95+
assert pyjson['properties']['name'] == expected
Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,22 @@
1-
# coding=utf8
2-
import os
3-
4-
from nose.tools import eq_
5-
61
import mapnik
72

8-
from .utilities import execution_path, run_all
9-
10-
11-
def setup():
12-
# All of the paths used are relative, if we run the tests
13-
# from another directory we need to chdir()
14-
os.chdir(execution_path('.'))
15-
163
if 'sqlite' in mapnik.DatasourceCache.plugin_names():
174

185
# the negative buffer on the layer should
196
# override the postive map buffer leading
207
# only one point to be rendered in the map
218
def test_layer_buffer_size_1():
229
m = mapnik.Map(512, 512)
23-
eq_(m.buffer_size, 0)
24-
mapnik.load_map(m, '../data/good_maps/layer_buffer_size_reduction.xml')
25-
eq_(m.buffer_size, 256)
26-
eq_(m.layers[0].buffer_size, -150)
10+
assert m.buffer_size == 0
11+
mapnik.load_map(m, './test/data/good_maps/layer_buffer_size_reduction.xml')
12+
assert m.buffer_size == 256
13+
assert m.layers[0].buffer_size == -150
2714
m.zoom_all()
2815
im = mapnik.Image(m.width, m.height)
2916
mapnik.render(m, im)
3017
actual = '/tmp/mapnik-layer-buffer-size.png'
31-
expected = 'images/support/mapnik-layer-buffer-size.png'
18+
expected = './test/python_tests/images/support/mapnik-layer-buffer-size.png'
3219
im.save(actual, "png32")
3320
expected_im = mapnik.Image.open(expected)
34-
eq_(im.tostring('png32'),
35-
expected_im.tostring('png32'),
36-
'failed comparing actual (%s) and expected (%s)' % (actual,
37-
'tests/python_tests/' + expected))
38-
39-
40-
if __name__ == "__main__":
41-
setup()
42-
exit(run_all(eval(x) for x in dir() if x.startswith("test_")))
21+
assert im.tostring('png32') == expected_im.tostring('png32'),'failed comparing actual (%s) and expected (%s)' % (actual,
22+
'tests/python_tests/' + expected)
Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
1-
#!/usr/bin/env python
2-
3-
import os
4-
5-
from nose.tools import eq_
6-
71
import mapnik
82

9-
from .utilities import execution_path, run_all
10-
11-
12-
def setup():
13-
# All of the paths used are relative, if we run the tests
14-
# from another directory we need to chdir()
15-
os.chdir(execution_path('.'))
16-
17-
183
def test_adding_datasource_to_layer():
194
map_string = '''<?xml version="1.0" encoding="utf-8"?>
205
<Map>
@@ -25,7 +10,7 @@ def test_adding_datasource_to_layer():
2510
<!-- leave datasource empty -->
2611
<!--
2712
<Datasource>
28-
<Parameter name="file">../data/shp/world_merc.shp</Parameter>
13+
<Parameter name="file">./test/data/shp/world_merc.shp</Parameter>
2914
<Parameter name="type">shape</Parameter>
3015
</Datasource>
3116
-->
@@ -39,45 +24,39 @@ def test_adding_datasource_to_layer():
3924
mapnik.load_map_from_string(m, map_string)
4025

4126
# validate it loaded fine
42-
eq_(m.layers[0].styles[0], 'world_borders_style')
43-
eq_(m.layers[0].styles[1], 'point_style')
44-
eq_(len(m.layers), 1)
27+
assert m.layers[0].styles[0] == 'world_borders_style'
28+
assert m.layers[0].styles[1] == 'point_style'
29+
assert len(m.layers) == 1
4530

4631
# also assign a variable reference to that layer
4732
# below we will test that this variable references
4833
# the same object that is attached to the map
4934
lyr = m.layers[0]
5035

5136
# ensure that there was no datasource for the layer...
52-
eq_(m.layers[0].datasource, None)
53-
eq_(lyr.datasource, None)
37+
assert m.layers[0].datasource == None
38+
assert lyr.datasource == None
5439

5540
# also note that since the srs was black it defaulted to wgs84
56-
eq_(m.layers[0].srs,
57-
'epsg:4326')
58-
eq_(lyr.srs, 'epsg:4326')
41+
assert m.layers[0].srs == 'epsg:4326'
42+
assert lyr.srs == 'epsg:4326'
5943

6044
# now add a datasource one...
61-
ds = mapnik.Shapefile(file='../data/shp/world_merc.shp')
45+
ds = mapnik.Shapefile(file='./test/data/shp/world_merc.shp')
6246
m.layers[0].datasource = ds
6347

6448
# now ensure it is attached
65-
eq_(m.layers[0].datasource.describe()['name'], "shape")
66-
eq_(lyr.datasource.describe()['name'], "shape")
49+
assert m.layers[0].datasource.describe()['name'] == "shape"
50+
assert lyr.datasource.describe()['name'] == "shape"
6751

6852
# and since we have now added a shapefile in spherical mercator, adjust
6953
# the projection
7054
lyr.srs = '+proj=merc +lon_0=0 +lat_ts=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs'
7155

7256
# test that assignment
73-
eq_(m.layers[
74-
0].srs, '+proj=merc +lon_0=0 +lat_ts=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs')
75-
eq_(lyr.srs, '+proj=merc +lon_0=0 +lat_ts=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs')
57+
assert m.layers[0].srs == '+proj=merc +lon_0=0 +lat_ts=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs'
58+
assert lyr.srs == '+proj=merc +lon_0=0 +lat_ts=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs'
7659
except RuntimeError as e:
7760
# only test datasources that we have installed
7861
if not 'Could not create datasource' in str(e):
7962
raise RuntimeError(e)
80-
81-
if __name__ == "__main__":
82-
setup()
83-
exit(run_all(eval(x) for x in dir() if x.startswith("test_")))

test/python_tests/layer_test.py

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,21 @@
1-
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*-
3-
4-
from nose.tools import eq_
5-
61
import mapnik
72

8-
from .utilities import run_all
9-
10-
113
# Map initialization
124

13-
145
def test_layer_init():
156
l = mapnik.Layer('test')
16-
eq_(l.name, 'test')
17-
eq_(l.srs, 'epsg:4326')
18-
eq_(l.envelope(), mapnik.Box2d())
19-
eq_(l.clear_label_cache, False)
20-
eq_(l.cache_features, False)
21-
eq_(l.visible(1), True)
22-
eq_(l.active, True)
23-
eq_(l.datasource, None)
24-
eq_(l.queryable, False)
25-
eq_(l.minimum_scale_denominator, 0.0)
26-
eq_(l.maximum_scale_denominator > 1e+6, True)
27-
eq_(l.group_by, "")
28-
eq_(l.maximum_extent, None)
29-
eq_(l.buffer_size, None)
30-
eq_(len(l.styles), 0)
31-
32-
if __name__ == "__main__":
33-
exit(run_all(eval(x) for x in dir() if x.startswith("test_")))
7+
assert l.name == 'test'
8+
assert l.srs == 'epsg:4326'
9+
assert l.envelope() == mapnik.Box2d()
10+
assert not l.clear_label_cache
11+
assert not l.cache_features
12+
assert l.visible(1)
13+
assert l.active
14+
assert l.datasource == None
15+
assert not l.queryable
16+
assert l.minimum_scale_denominator == 0.0
17+
assert l.maximum_scale_denominator > 1e+6
18+
assert l.group_by == ""
19+
assert l.maximum_extent == None
20+
assert l.buffer_size == None
21+
assert len(l.styles) == 0

test/python_tests/load_map_test.py

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,11 @@
1-
#!/usr/bin/env python
2-
31
import glob
4-
import os
5-
6-
from nose.tools import eq_
7-
82
import mapnik
93

10-
from .utilities import execution_path, run_all
11-
12-
134
default_logging_severity = mapnik.logger.get_severity()
145

15-
16-
def setup():
17-
# make the tests silent to suppress unsupported params from harfbuzz tests
18-
# TODO: remove this after harfbuzz branch merges
19-
mapnik.logger.set_severity(getattr(mapnik.severity_type, "None"))
20-
# All of the paths used are relative, if we run the tests
21-
# from another directory we need to chdir()
22-
os.chdir(execution_path('.'))
23-
24-
256
def teardown():
267
mapnik.logger.set_severity(default_logging_severity)
278

28-
299
def test_broken_files():
3010
default_logging_severity = mapnik.logger.get_severity()
3111
mapnik.logger.set_severity(getattr(mapnik.severity_type, "None"))
@@ -44,7 +24,7 @@ def test_broken_files():
4424
filename)
4525
except RuntimeError:
4626
pass
47-
eq_(len(failures), 0, '\n' + '\n'.join(failures))
27+
assert len(failures) == 0, '\n' + '\n'.join(failures)
4828
mapnik.logger.set_severity(default_logging_severity)
4929

5030

@@ -75,7 +55,7 @@ def test_can_parse_xml_with_deprecated_properties():
7555
failures.append(
7656
'Failed to load valid map %s (%s)' %
7757
(filename, e))
78-
eq_(len(failures), 0, '\n' + '\n'.join(failures))
58+
assert len(failures) == 0, '\n' + '\n'.join(failures)
7959
mapnik.logger.set_severity(default_logging_severity)
8060

8161

@@ -100,8 +80,4 @@ def test_good_files():
10080
failures.append(
10181
'Failed to load valid map %s (%s)' %
10282
(filename, e))
103-
eq_(len(failures), 0, '\n' + '\n'.join(failures))
104-
105-
if __name__ == "__main__":
106-
setup()
107-
exit(run_all(eval(x) for x in dir() if x.startswith("test_")))
83+
assert len(failures) == 0, '\n' + '\n'.join(failures)

0 commit comments

Comments
 (0)