Skip to content

Commit f72211a

Browse files
committed
update tests
1 parent b188a6b commit f72211a

15 files changed

Lines changed: 80 additions & 86 deletions

test/python_tests/csv_test.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def test_type_detection(**kwargs):
120120
'geo_longitude': -70,
121121
'geo_latitude': 40}
122122
eq_(feat.attributes, attr)
123-
eq_(len(ds.all_features()), 2)
123+
eq_(len(list(ds.all_features())), 2)
124124
desc = ds.describe()
125125
eq_(desc['geometry_type'], mapnik.DataGeometryType.Point)
126126
eq_(desc['name'], 'csv')
@@ -131,7 +131,7 @@ def test_skipping_blank_rows(**kwargs):
131131
ds = get_csv_ds('blank_rows.csv')
132132
eq_(ds.fields(), ['x', 'y', 'name'])
133133
eq_(ds.field_types(), ['int', 'int', 'str'])
134-
eq_(len(ds.all_features()), 2)
134+
eq_(len(list(ds.all_features())), 2)
135135
desc = ds.describe()
136136
eq_(desc['geometry_type'], mapnik.DataGeometryType.Point)
137137
eq_(desc['name'], 'csv')
@@ -159,7 +159,7 @@ def test_empty_rows(**kwargs):
159159
'date': u'1971-01-01',
160160
'integer': 40}
161161
first = True
162-
for feat in fs.features:
162+
for feat in fs:
163163
if first:
164164
first = False
165165
eq_(feat.attributes, attr)
@@ -175,7 +175,7 @@ def test_empty_rows(**kwargs):
175175
def test_slashes(**kwargs):
176176
ds = get_csv_ds('has_attributes_with_slashes.csv')
177177
eq_(len(ds.fields()), 3)
178-
fs = ds.all_features()
178+
fs = list(ds.all_features())
179179
eq_(fs[0].attributes, {'x': 0, 'y': 0, 'name': u'a/a'})
180180
eq_(fs[1].attributes, {'x': 1, 'y': 4, 'name': u'b/b'})
181181
eq_(fs[2].attributes, {'x': 10, 'y': 2.5, 'name': u'c/c'})
@@ -190,7 +190,7 @@ def test_wkt_field(**kwargs):
190190
eq_(len(ds.fields()), 1)
191191
eq_(ds.fields(), ['type'])
192192
eq_(ds.field_types(), ['str'])
193-
fs = ds.all_features()
193+
fs = list(ds.all_features())
194194
# eq_(len(fs[0].geometries()),1)
195195
eq_(fs[0].geometry.type(), mapnik.GeometryType.Point)
196196
# eq_(len(fs[1].geometries()),1)
@@ -243,7 +243,7 @@ def test_quoted_numbers(**kwargs):
243243
ds = get_csv_ds('points.csv')
244244
eq_(len(ds.fields()), 6)
245245
eq_(ds.fields(), ['lat', 'long', 'name', 'nr', 'color', 'placements'])
246-
fs = ds.all_features()
246+
fs = list(ds.all_features())
247247
eq_(fs[0]['placements'], "N,S,E,W,SW,10,5")
248248
eq_(fs[1]['placements'], "N,S,E,W,SW,10,5")
249249
eq_(fs[2]['placements'], "N,S,E,W,SW,10,5")
@@ -258,7 +258,7 @@ def test_quoted_numbers(**kwargs):
258258
def test_reading_windows_newlines(**kwargs):
259259
ds = get_csv_ds('windows_newlines.csv')
260260
eq_(len(ds.fields()), 3)
261-
feats = ds.all_features()
261+
feats = list(ds.all_features())
262262
eq_(len(feats), 1)
263263
fs = ds.featureset()
264264
feat = fs.next()
@@ -274,7 +274,7 @@ def test_reading_windows_newlines(**kwargs):
274274
def test_reading_mac_newlines(**kwargs):
275275
ds = get_csv_ds('mac_newlines.csv')
276276
eq_(len(ds.fields()), 3)
277-
feats = ds.all_features()
277+
feats = list(ds.all_features())
278278
eq_(len(feats), 1)
279279
fs = ds.featureset()
280280
feat = fs.next()
@@ -290,7 +290,7 @@ def test_reading_mac_newlines(**kwargs):
290290
def check_newlines(filename):
291291
ds = get_csv_ds(filename)
292292
eq_(len(ds.fields()), 3)
293-
feats = ds.all_features()
293+
feats = list(ds.all_features())
294294
eq_(len(feats), 1)
295295
fs = ds.featureset()
296296
feat = fs.next()
@@ -457,7 +457,7 @@ def validate_geojson_datasource(ds):
457457
eq_(len(ds.fields()), 1)
458458
eq_(ds.fields(), ['type'])
459459
eq_(ds.field_types(), ['str'])
460-
fs = ds.all_features()
460+
fs = list(ds.all_features())
461461
# eq_(len(fs[0].geometries()),1)
462462
eq_(fs[0].geometry.type(), mapnik.GeometryType.Point)
463463
# eq_(len(fs[1].geometries()),1)
@@ -497,8 +497,8 @@ def test_that_blank_undelimited_rows_are_still_parsed(**kwargs):
497497
eq_(len(ds.fields()), 0)
498498
eq_(ds.fields(), [])
499499
eq_(ds.field_types(), [])
500-
fs = ds.featureset()
501-
eq_(fs, None)
500+
fs = list(ds.featureset())
501+
eq_(len(fs), 0)
502502
desc = ds.describe()
503503
eq_(desc['geometry_type'], None)
504504

@@ -526,7 +526,7 @@ def test_that_feature_id_only_incremented_for_valid_rows(**kwargs):
526526
eq_(feat['id'], 2)
527527
desc = ds.describe()
528528
eq_(desc['geometry_type'], mapnik.DataGeometryType.Point)
529-
eq_(len(ds.all_features()), 2)
529+
eq_(len(list(ds.all_features())), 2)
530530

531531
def test_dynamically_defining_headers1(**kwargs):
532532
ds = mapnik.Datasource(type='csv',
@@ -543,7 +543,7 @@ def test_dynamically_defining_headers1(**kwargs):
543543
eq_(feat['name'], 'data_name')
544544
desc = ds.describe()
545545
eq_(desc['geometry_type'], mapnik.DataGeometryType.Point)
546-
eq_(len(ds.all_features()), 2)
546+
eq_(len(list(ds.all_features())), 2)
547547

548548
def test_dynamically_defining_headers2(**kwargs):
549549
ds = mapnik.Datasource(type='csv',
@@ -560,7 +560,7 @@ def test_dynamically_defining_headers2(**kwargs):
560560
eq_(feat['name'], 'data_name')
561561
desc = ds.describe()
562562
eq_(desc['geometry_type'], mapnik.DataGeometryType.Point)
563-
eq_(len(ds.all_features()), 1)
563+
eq_(len(list(ds.all_features())), 1)
564564

565565
def test_dynamically_defining_headers3(**kwargs):
566566
ds = mapnik.Datasource(type='csv',
@@ -577,7 +577,7 @@ def test_dynamically_defining_headers3(**kwargs):
577577
eq_(feat['name'], 'data_name')
578578
desc = ds.describe()
579579
eq_(desc['geometry_type'], mapnik.DataGeometryType.Point)
580-
eq_(len(ds.all_features()), 1)
580+
eq_(len(list(ds.all_features())), 1)
581581

582582
def test_that_64bit_int_fields_work(**kwargs):
583583
ds = get_csv_ds('64bit_int.csv')
@@ -592,7 +592,7 @@ def test_that_64bit_int_fields_work(**kwargs):
592592
eq_(feat['bigint'], 0x7FFFFFFFFFFFFFFF)
593593
desc = ds.describe()
594594
eq_(desc['geometry_type'], mapnik.DataGeometryType.Point)
595-
eq_(len(ds.all_features()), 2)
595+
eq_(len(list(ds.all_features())), 2)
596596

597597
def test_various_number_types(**kwargs):
598598
ds = get_csv_ds('number_types.csv')
@@ -616,7 +616,7 @@ def test_various_number_types(**kwargs):
616616
eq_(feat['floats'], 1.234e+16)
617617
desc = ds.describe()
618618
eq_(desc['geometry_type'], mapnik.DataGeometryType.Point)
619-
eq_(len(ds.all_features()), 8)
619+
eq_(len(list(ds.all_features())), 8)
620620

621621
def test_manually_supplied_extent(**kwargs):
622622
csv_string = '''

test/python_tests/datasource_test.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def test_vrt_referring_to_missing_files():
5757
# *** run the function ***
5858
try:
5959
# Should RuntimeError here
60-
_map.query_point(0, x, y).features
60+
list(_map.query_point(0, x, y))
6161
finally:
6262
# restore file descriptors so I can print the results
6363
os.dup2(save[0], 1)
@@ -83,7 +83,7 @@ def test_total_feature_count_shp():
8383
if 'shape' in mapnik.DatasourceCache.plugin_names():
8484
ds = mapnik.Shapefile(file='../data/shp/poly.shp')
8585
features = ds.all_features()
86-
num_feats = len(features)
86+
num_feats = len(list(features))
8787
eq_(num_feats, 10)
8888

8989

@@ -96,7 +96,7 @@ def test_total_feature_count_json():
9696
eq_(desc['type'], mapnik.DataType.Vector)
9797
eq_(desc['encoding'], 'utf-8')
9898
features = ds.all_features()
99-
num_feats = len(features)
99+
num_feats = len(list(features))
100100
eq_(num_feats, 5)
101101

102102

@@ -111,7 +111,7 @@ def test_sqlite_reading():
111111
eq_(desc['type'], mapnik.DataType.Vector)
112112
eq_(desc['encoding'], 'utf-8')
113113
features = ds.all_features()
114-
num_feats = len(features)
114+
num_feats = len(list(features))
115115
eq_(num_feats, 245)
116116

117117

@@ -121,7 +121,7 @@ def test_reading_json_from_string():
121121
if 'ogr' in mapnik.DatasourceCache.plugin_names():
122122
ds = mapnik.Ogr(file=json, layer_by_index=0)
123123
features = ds.all_features()
124-
num_feats = len(features)
124+
num_feats = len(list(features))
125125
eq_(num_feats, 5)
126126

127127

@@ -140,7 +140,7 @@ def test_feature_envelope():
140140
def test_feature_attributes():
141141
if 'shape' in mapnik.DatasourceCache.plugin_names():
142142
ds = mapnik.Shapefile(file='../data/shp/poly.shp')
143-
features = ds.all_features()
143+
features = list(ds.all_features())
144144
feat = features[0]
145145
attrs = {'PRFEDEA': u'35043411', 'EAS_ID': 168, 'AREA': 215229.266}
146146
eq_(feat.attributes, attrs)
@@ -153,7 +153,7 @@ def test_ogr_layer_by_sql():
153153
ds = mapnik.Ogr(file='../data/shp/poly.shp',
154154
layer_by_sql='SELECT * FROM poly WHERE EAS_ID = 168')
155155
features = ds.all_features()
156-
num_feats = len(features)
156+
num_feats = len(list(features))
157157
eq_(num_feats, 1)
158158

159159

@@ -174,7 +174,7 @@ def rle_encode(l):
174174
for x in xrange(0, 256, 4):
175175
featureset = m.query_map_point(0, x, y)
176176
added = False
177-
for feature in featureset.features:
177+
for feature in featureset:
178178
fg.append(feature[join_field])
179179
added = True
180180
if not added:

test/python_tests/feature_id_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def compare_shape_between_mapnik_and_ogr(shapefile, query=None):
3232
fs1 = ds1.featureset()
3333
fs2 = ds2.featureset()
3434
count = 0
35-
for feat1, feat2 in zip(fs1.features, fs2.features):
35+
for feat1, feat2 in zip(fs1, fs2):
3636
count += 1
3737
eq_(feat1.id(), feat2.id(),
3838
'%s : ogr feature id %s "%s" does not equal shapefile feature id %s "%s"'

test/python_tests/geojson_plugin_test.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def test_geojson_properties():
3131
ds = mapnik.Datasource(
3232
type='geojson',
3333
file='../data/json/escaped.geojson')
34-
f = ds.features_at_point(ds.envelope().center()).features[0]
34+
f = list(ds.features_at_point(ds.envelope().center()))[0]
3535
eq_(len(ds.fields()), 11)
3636
desc = ds.describe()
3737
eq_(desc['geometry_type'], mapnik.DataGeometryType.Point)
@@ -48,7 +48,7 @@ def test_geojson_properties():
4848
ds = mapnik.Datasource(
4949
type='geojson',
5050
file='../data/json/escaped.geojson')
51-
f = ds.all_features()[0]
51+
f = list(ds.all_features())[0]
5252
eq_(len(ds.fields()), 11)
5353

5454
desc = ds.describe()
@@ -68,7 +68,7 @@ def test_large_geojson_properties():
6868
type='geojson',
6969
file='../data/json/escaped.geojson',
7070
cache_features=False)
71-
f = ds.features_at_point(ds.envelope().center()).features[0]
71+
f = list(ds.features_at_point(ds.envelope().center()))[0]
7272
eq_(len(ds.fields()), 11)
7373
desc = ds.describe()
7474
eq_(desc['geometry_type'], mapnik.DataGeometryType.Point)
@@ -85,7 +85,7 @@ def test_large_geojson_properties():
8585
ds = mapnik.Datasource(
8686
type='geojson',
8787
file='../data/json/escaped.geojson')
88-
f = ds.all_features()[0]
88+
f = list(ds.all_features())[0]
8989
eq_(len(ds.fields()), 11)
9090

9191
desc = ds.describe()
@@ -108,7 +108,7 @@ def test_geojson_from_in_memory_string():
108108
type='geojson',
109109
inline='{ "type":"FeatureCollection", "features": [ { "type":"Feature", "properties":{"name":"test"}, "geometry": { "type":"LineString","coordinates":[[0,0],[10,10]] } } ]}')
110110
eq_(len(ds.fields()), 1)
111-
f = ds.all_features()[0]
111+
f = list(ds.all_features())[0]
112112
desc = ds.describe()
113113
eq_(desc['geometry_type'], mapnik.DataGeometryType.LineString)
114114
eq_(f['name'], u'test')
@@ -134,7 +134,7 @@ def test_parsing_feature_collection_with_top_level_properties():
134134
ds = mapnik.Datasource(
135135
type='geojson',
136136
file='../data/json/feature_collection_level_properties.json')
137-
f = ds.all_features()[0]
137+
f = list(ds.all_features())[0]
138138

139139
desc = ds.describe()
140140
eq_(desc['geometry_type'], mapnik.DataGeometryType.Point)

test/python_tests/memory_datasource_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def test_add_feature():
2020
featureset = md.features_at_point(mapnik.Coord(2, 3))
2121
retrieved = []
2222

23-
for feat in featureset.features:
23+
for feat in featureset:
2424
retrieved.append(feat)
2525

2626
eq_(len(retrieved), 1)
@@ -29,7 +29,7 @@ def test_add_feature():
2929

3030
featureset = md.features_at_point(mapnik.Coord(20, 30))
3131
retrieved = []
32-
for feat in featureset.features:
32+
for feat in featureset:
3333
retrieved.append(feat)
3434
eq_(len(retrieved), 0)
3535

test/python_tests/ogr_and_shape_geometries_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def ensure_geometries_are_interpreted_equivalently(filename):
3535
fs1 = ds1.featureset()
3636
fs2 = ds2.featureset()
3737
count = 0
38-
for feat1, feat2 in zip(fs1.features, fs2.features):
38+
for feat1, feat2 in zip(fs1, fs2):
3939
count += 1
4040
eq_(feat1.attributes, feat2.attributes)
4141
# TODO - revisit this: https://github.com/mapnik/mapnik/issues/1093

test/python_tests/ogr_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def test_shapefile_init():
3737
# Shapefile properties
3838
def test_shapefile_properties():
3939
ds = mapnik.Ogr(file='../data/shp/boundaries.shp', layer_by_index=0)
40-
f = ds.features_at_point(ds.envelope().center(), 0.001).features[0]
40+
f = list(ds.features_at_point(ds.envelope().center(), 0.001))[0]
4141
eq_(ds.geometry_type(), mapnik.DataGeometryType.Polygon)
4242

4343
eq_(f['CGNS_FID'], u'6f733341ba2011d892e2080020a0f4c9')

test/python_tests/pickling_test.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,18 @@ def setup():
1717
os.chdir(execution_path('.'))
1818

1919

20-
def test_color_pickle():
21-
c = mapnik.Color('blue')
22-
23-
eq_(pickle.loads(pickle.dumps(c)), c)
24-
25-
c = mapnik.Color(0, 64, 128)
26-
27-
eq_(pickle.loads(pickle.dumps(c)), c)
28-
29-
c = mapnik.Color(0, 64, 128, 192)
30-
31-
eq_(pickle.loads(pickle.dumps(c)), c)
32-
33-
34-
def test_envelope_pickle():
35-
e = mapnik.Box2d(100, 100, 200, 200)
36-
37-
eq_(pickle.loads(pickle.dumps(e)), e)
20+
#def test_color_pickle():
21+
# c = mapnik.Color('blue')
22+
# eq_(pickle.loads(pickle.dumps(c)), c)
23+
# c = mapnik.Color(0, 64, 128)
24+
# eq_(pickle.loads(pickle.dumps(c)), c)
25+
# c = mapnik.Color(0, 64, 128, 192)
26+
# eq_(pickle.loads(pickle.dumps(c)), c)
27+
28+
29+
#def test_envelope_pickle():
30+
# e = mapnik.Box2d(100, 100, 200, 200)
31+
# eq_(pickle.loads(pickle.dumps(e)), e)
3832

3933

4034
def test_parameters_pickle():

test/python_tests/query_tolerance_test.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@ def test_query_tolerance():
3232
eq_(tol, 0.046875)
3333
# check point really exists
3434
x, y = 2.0, 4.0
35-
features = _map.query_point(0, x, y).features
36-
eq_(len(features), 1)
35+
features = _map.query_point(0, x, y)
36+
eq_(len(list(features)), 1)
3737
# check inside tolerance limit
3838
x = 2.0 + tol * 0.9
39-
features = _map.query_point(0, x, y).features
40-
eq_(len(features), 1)
39+
features = _map.query_point(0, x, y)
40+
eq_(len(list(features)), 1)
4141
# check outside tolerance limit
4242
x = 2.0 + tol * 1.1
43-
features = _map.query_point(0, x, y).features
44-
eq_(len(features), 0)
43+
features = _map.query_point(0, x, y)
44+
eq_(len(list(features)), 0)
4545

4646
if __name__ == "__main__":
4747
setup()

0 commit comments

Comments
 (0)