-
Notifications
You must be signed in to change notification settings - Fork 85
/
test_osm.py
103 lines (76 loc) · 2.31 KB
/
test_osm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import pytest
import pandana
from pandana.loaders import osm
from pandana.testing import skipiftravis
@pytest.fixture(scope='module')
def bbox1():
# Intersection of Telegraph and Haste in Berkeley
# Sample query: http://overpass-turbo.eu/s/6AK
return 37.8659303546, -122.2588003879, 37.8661598571, -122.2585062512
@pytest.fixture(scope='module')
def bbox2():
# Telegraph Channing to Durant in Berkeley
# Sample query: http://overpass-turbo.eu/s/6B0
return 37.8668405874, -122.2590948685, 37.8679028054, -122.2586363885
def test_process_node():
test_node = {
'id': 'id',
'lat': 'lat',
'lon': 'lon',
'extra': 'extra'
}
expected = {
'id': 'id',
'lat': 'lat',
'lon': 'lon'
}
assert osm.process_node(test_node) == expected
test_node['tags'] = {'highway': 'highway', 'source': 'source'}
expected['highway'] = 'highway'
assert osm.process_node(test_node) == expected
@skipiftravis
def test_network_from_bbox(bbox2):
net = osm.pdna_network_from_bbox(*bbox2)
assert isinstance(net, pandana.Network)
def test_build_node_query_no_tags(bbox1):
query = osm.build_node_query(*bbox1)
assert query == (
'[out:json];'
'('
' node'
' '
' ({},{},{},{});'
');'
'out;').format(*bbox1)
def test_build_node_query_str_tag(bbox1):
tag = '"tag"'
query = osm.build_node_query(*bbox1, tags=tag)
assert query == (
'[out:json];'
'('
' node'
' ["tag"]'
' ({},{},{},{});'
');'
'out;').format(*bbox1)
def test_build_node_query_tag_list(bbox1):
tags = ['"tag1"="tag1"', '"tag2"!~"tag2|tag2"']
query = osm.build_node_query(*bbox1, tags=tags)
assert query == (
'[out:json];'
'('
' node'
' ["tag1"="tag1"]["tag2"!~"tag2|tag2"]'
' ({},{},{},{});'
');'
'out;').format(*bbox1)
def test_node_query(bbox2):
tags = '"amenity"="restaurant"'
cafes = osm.node_query(*bbox2, tags=tags)
assert len(cafes) == 2
assert 'lat' in cafes.columns
assert 'lon' in cafes.columns
assert cafes['name'][1419597327] == 'Cream'
def test_node_query_raises():
with pytest.raises(RuntimeError):
osm.node_query(37.8, -122.282, 37.8, -122.252)