示例#1
0
def test_get_collection_length(road_a, road_b):
    # road_a length == 4030
    # road_b length == 2160
    output = KmlOutput('km')
    collection = {'join_type': 'arbitrary', 'ways': [road_a, road_b]}
    length = output.get_collection_length(collection)
    assert length == 6190
示例#2
0
def test_get_collection_segments(road_a, road_b):
    output = KmlOutput('km')
    collection = {'join_type': 'arbitrary', 'ways': [road_a, road_b]}
    segments = output.get_collection_segments(collection)
    assert len(segments) == 13
    assert segments[0]['start'][0] == 44.47486310000014
    assert segments[12]['start'][0] == 44.57721230000033
示例#3
0
def test_get_collection_curvature_on_way(road_a, road_b):
    output = KmlOutput('km')
    # Set a different curvature for road_b: 300 instead of 226
    road_b['curvature'] = 300
    collection = {'join_type': 'arbitrary', 'ways': [road_a, road_b]}
    curvature = output.get_collection_curvature(collection)
    assert curvature == 824
示例#4
0
def test_get_collection_segments(road_a, road_b):
    output = KmlOutput('km')
    collection = {'join_type': 'arbitrary', 'ways': [road_a, road_b]}
    segments = output.get_collection_segments(collection)
    assert len(segments) == 13
    assert segments[0]['start'][0] == 44.47486310000014
    assert segments[12]['start'][0] == 44.57721230000033
示例#5
0
def test_get_collection_length(road_a, road_b):
    # road_a length == 4030
    # road_b length == 2160
    output = KmlOutput('km')
    collection = {'join_type': 'arbitrary', 'ways': [road_a, road_b]}
    length = output.get_collection_length(collection)
    assert length == 6190
示例#6
0
def test_get_length_weighted_collection_tags_many_ways(road_a, road_b):
    # road_a length == 4030
    # road_b length == 2160
    output = KmlOutput('km')
    road_c = {
        'id': 1002,
        'tags': {
            'name': 'Road B',
            'highway': 'tertiary',
            'ref': 'VT-555'
        },
        'length': 3000
    }
    road_d = {
        'id': 1003,
        'tags': {
            'name': 'Road A',
            'highway': 'tertiary',
            'ref': 'VT-555'
        },
        'length': 100
    }

    collection = {
        'join_type': 'arbitrary',
        'ways': [road_a, road_b, road_c, road_d]
    }
    names = output.get_length_weighted_collection_tags(collection, 'name')
    assert names == ['Road B', 'Road A']
示例#7
0
def test_get_collection_curvature_on_way(road_a, road_b):
    output = KmlOutput('km')
    # Set a different curvature for road_b: 300 instead of 226
    road_b['curvature'] = 300
    collection = {'join_type': 'arbitrary', 'ways': [road_a, road_b]}
    curvature = output.get_collection_curvature(collection)
    assert curvature == 824
示例#8
0
def test_get_collection_length_on_way(road_a, road_b):
    # road_a length == 4030
    # road_b length == 2160
    output = KmlOutput('km')
    # Set a different curvature for road_b: 4000 instead of 2160
    road_b['length'] = 4000
    collection = {'join_type': 'arbitrary', 'ways': [road_a, road_b]}
    length = output.get_collection_length(collection)
    assert length == 8030
示例#9
0
def test_get_collection_length_on_way(road_a, road_b):
    # road_a length == 4030
    # road_b length == 2160
    output = KmlOutput('km')
    # Set a different curvature for road_b: 4000 instead of 2160
    road_b['length'] = 4000
    collection = {'join_type': 'arbitrary', 'ways': [road_a, road_b]}
    length = output.get_collection_length(collection)
    assert length == 8030
示例#10
0
def test_get_shared_collection_ref(road_a, road_b):
    output = KmlOutput('km')
    collection = {'join_type': 'arbitrary', 'ways': [road_a, road_b]}
    refs = output.get_shared_collection_refs(collection)
    assert len(refs) == 1
    assert 'VT-555' in refs

    # Ensure that if a way in the collection has no refs, there are none shared.
    road_c = {
        'id': 1002,
        'tags': {
            'name': 'Road B',
            'highway': 'tertiary'
        },
        'length': 3000
    }
    collection = {'join_type': 'arbitrary', 'ways': [road_a, road_b, road_c]}
    refs = output.get_shared_collection_refs(collection)
    assert len(refs) == 0

    # Ensure that multiple refs can be returned
    road_c = {
        'id': 1002,
        'tags': {
            'name': 'Road B',
            'highway': 'tertiary',
            'ref': 'VT-555;VT-17'
        },
        'length': 3000
    }
    road_d = {
        'id': 1003,
        'tags': {
            'name': 'Road A',
            'highway': 'tertiary',
            'ref': 'VT-555;VT-17'
        },
        'length': 100
    }
    road_e = {
        'id': 1003,
        'tags': {
            'name': 'Road A',
            'highway': 'tertiary',
            'ref': 'VT-555;US-30;VT-17'
        },
        'length': 100
    }
    collection = {'join_type': 'arbitrary', 'ways': [road_c, road_d, road_e]}
    refs = output.get_shared_collection_refs(collection)
    assert len(refs) == 2
    assert 'VT-555' in refs
    assert 'VT-17' in refs
示例#11
0
def test_get_length_weighted_collection_tags_many_ways(road_a, road_b):
    # road_a length == 4030
    # road_b length == 2160
    output = KmlOutput('km')
    road_c = {'id':   1002,
            'tags': {   'name':     'Road B',
                        'highway':  'tertiary',
                        'ref':      'VT-555'},
            'length': 3000}
    road_d = {'id':   1003,
            'tags': {   'name':     'Road A',
                        'highway':  'tertiary',
                        'ref':      'VT-555'},
            'length': 100}

    collection = {'join_type': 'arbitrary', 'ways': [road_a, road_b, road_c, road_d]}
    names = output.get_length_weighted_collection_tags(collection, 'name')
    assert names == ['Road B', 'Road A']
示例#12
0
def test_get_length_weighted_collection_tags(road_a, road_b):
    # road_a length == 4030
    # road_b length == 2160
    output = KmlOutput('km')
    collection = {'join_type': 'arbitrary', 'ways': [road_a, road_b]}
    names = output.get_length_weighted_collection_tags(collection, 'name')
    assert names == ['Road A', 'Road B']

    # Ensure that reversing the ways doesn't change anything.
    collection = {'join_type': 'arbitrary', 'ways': [road_b, road_a]}
    names = output.get_length_weighted_collection_tags(collection, 'name')
    assert names == ['Road A', 'Road B']

    # Ensure that giving B a larger length does change the order.
    road_b['length'] = 5000
    collection = {'join_type': 'arbitrary', 'ways': [road_a, road_b]}
    names = output.get_length_weighted_collection_tags(collection, 'name')
    assert names == ['Road B', 'Road A']
示例#13
0
def test_get_length_weighted_collection_tags(road_a, road_b):
    # road_a length == 4030
    # road_b length == 2160
    output = KmlOutput('km')
    collection = {'join_type': 'arbitrary', 'ways': [road_a, road_b]}
    names = output.get_length_weighted_collection_tags(collection, 'name')
    assert names == ['Road A', 'Road B']

    # Ensure that reversing the ways doesn't change anything.
    collection = {'join_type': 'arbitrary', 'ways': [road_b, road_a]}
    names = output.get_length_weighted_collection_tags(collection, 'name')
    assert names == ['Road A', 'Road B']

    # Ensure that giving B a larger length does change the order.
    road_b['length'] = 5000
    collection = {'join_type': 'arbitrary', 'ways': [road_a, road_b]}
    names = output.get_length_weighted_collection_tags(collection, 'name')
    assert names == ['Road B', 'Road A']
示例#14
0
def test_get_collection_name(road_a, road_b):
    # road_a length == 4030
    # road_b length == 2160
    output = KmlOutput('km')
    collection = {'join_type': 'arbitrary', 'ways': [road_a, road_b]}
    name = output.tools.get_collection_name(collection)
    assert name == 'Road A (VT-555)'

    # Try with additional ways that make 'Road B' longer.
    road_c = {'id':   1002,
            'tags': {   'name':     'Road B',
                        'highway':  'tertiary',
                        'ref':      'VT-555;VT-17'},
            'length': 3000}
    road_d = {'id':   1003,
            'tags': {   'name':     'Road A',
                        'highway':  'tertiary',
                        'ref':      'VT-555;VT-17'},
            'length': 100}
    collection = {'join_type': 'arbitrary', 'ways': [road_a, road_b, road_c, road_d]}
    name = output.tools.get_collection_name(collection)
    assert name == 'Road B (VT-555)'

    # Multiple route-numbers.
    road_a['tags']['ref'] = 'VT-555;VT-17'
    road_b['tags']['ref'] = 'VT-555;VT-17'
    road_e = {'id':   1003,
            'tags': {   'name':     'Road A',
                        'highway':  'tertiary',
                        'ref':      'VT-555;US-30;VT-17'},
            'length': 100}
    collection = {'join_type': 'arbitrary', 'ways': [road_a, road_b, road_c, road_d, road_e]}
    name = output.tools.get_collection_name(collection)
    assert name == 'Road B (VT-555 / VT-17)' or name == 'Road B (VT-17 / VT-555)'

    # no road name
    road_f = {'id':   1004,
            'tags': {   'highway':  'unclassified'},
            'length': 100}
    collection = {'join_type': 'none', 'ways': [road_f]}
    name = output.tools.get_collection_name(collection)
    assert name == '1004'

    # ref only
    road_g = {'id':   1005,
            'tags': {   'highway':  'tertiary',
                        'ref':      'VT-555;VT-17'},
            'length': 100}
    collection = {'join_type': 'none', 'ways': [road_g]}
    name = output.tools.get_collection_name(collection)
    assert name == 'VT-555 / VT-17' or name == 'VT-17 / VT-555'
示例#15
0
def test_get_shared_collection_ref(road_a, road_b):
    output = KmlOutput('km')
    collection = {'join_type': 'arbitrary', 'ways': [road_a, road_b]}
    refs = output.get_shared_collection_refs(collection)
    assert len(refs) == 1
    assert 'VT-555' in refs

    # Ensure that if a way in the collection has no refs, there are none shared.
    road_c = {'id':   1002,
            'tags': {   'name':     'Road B',
                        'highway':  'tertiary'},
            'length': 3000}
    collection = {'join_type': 'arbitrary', 'ways': [road_a, road_b, road_c]}
    refs = output.get_shared_collection_refs(collection)
    assert len(refs) == 0

    # Ensure that multiple refs can be returned
    road_c = {'id':   1002,
            'tags': {   'name':     'Road B',
                        'highway':  'tertiary',
                        'ref':      'VT-555;VT-17'},
            'length': 3000}
    road_d = {'id':   1003,
            'tags': {   'name':     'Road A',
                        'highway':  'tertiary',
                        'ref':      'VT-555;VT-17'},
            'length': 100}
    road_e = {'id':   1003,
            'tags': {   'name':     'Road A',
                        'highway':  'tertiary',
                        'ref':      'VT-555;US-30;VT-17'},
            'length': 100}
    collection = {'join_type': 'arbitrary', 'ways': [road_c, road_d, road_e]}
    refs = output.get_shared_collection_refs(collection)
    assert len(refs) == 2
    assert 'VT-555' in refs
    assert 'VT-17' in refs
示例#16
0
def test_get_collection_name(road_a, road_b):
    # road_a length == 4030
    # road_b length == 2160
    output = KmlOutput('km')
    collection = {'join_type': 'arbitrary', 'ways': [road_a, road_b]}
    name = output.get_collection_name(collection)
    assert name == 'Road A (VT-555)'

    # Try with additional ways that make 'Road B' longer.
    road_c = {'id':   1002,
            'tags': {   'name':     'Road B',
                        'highway':  'tertiary',
                        'ref':      'VT-555;VT-17'},
            'length': 3000}
    road_d = {'id':   1003,
            'tags': {   'name':     'Road A',
                        'highway':  'tertiary',
                        'ref':      'VT-555;VT-17'},
            'length': 100}
    collection = {'join_type': 'arbitrary', 'ways': [road_a, road_b, road_c, road_d]}
    name = output.get_collection_name(collection)
    assert name == 'Road B (VT-555)'

    # Multiple route-numbers.
    road_a['tags']['ref'] = 'VT-555;VT-17'
    road_b['tags']['ref'] = 'VT-555;VT-17'
    road_e = {'id':   1003,
            'tags': {   'name':     'Road A',
                        'highway':  'tertiary',
                        'ref':      'VT-555;US-30;VT-17'},
            'length': 100}
    collection = {'join_type': 'arbitrary', 'ways': [road_a, road_b, road_c, road_d, road_e]}
    name = output.get_collection_name(collection)
    assert name == 'Road B (VT-555 / VT-17)' or name == 'Road B (VT-17 / VT-555)'

    # no road name
    road_f = {'id':   1004,
            'tags': {   'highway':  'unclassified'},
            'length': 100}
    collection = {'join_type': 'none', 'ways': [road_f]}
    name = output.get_collection_name(collection)
    assert name == '1004'

    # ref only
    road_g = {'id':   1005,
            'tags': {   'highway':  'tertiary',
                        'ref':      'VT-555;VT-17'},
            'length': 100}
    collection = {'join_type': 'none', 'ways': [road_g]}
    name = output.get_collection_name(collection)
    assert name == 'VT-555 / VT-17' or name == 'VT-17 / VT-555'
示例#17
0
def test_get_collection_curvature(road_a, road_b):
    output = KmlOutput('km')
    collection = {'join_type': 'arbitrary', 'ways': [road_a, road_b]}
    curvature = output.tools.get_collection_curvature(collection)
    assert curvature == 750
示例#18
0
def test_get_collection_name_alt_refs():
    output = KmlOutput('km')
    # Ensure that if a way in the collection has no refs with a shared key, there are none shared.
    road_a = {
        'id': 1000,
        'tags': {
            'name': 'Road A',
            'highway': 'tertiary',
            'official_ref': 'C555'
        },
        'length': 3000
    }
    road_b = {
        'id': 1001,
        'tags': {
            'name': 'Road B',
            'highway': 'tertiary',
            'highway_authority_ref': 'C555'
        },
        'length': 100
    }
    collection = {
        'join_type': 'ref',
        'join_data': 'C555',
        'ways': [road_a, road_b]
    }
    name = output.tools.get_collection_name(collection)
    assert name == 'Road A (C555)'

    # Ensure that multiple refs can be returned
    road_c = {
        'id': 1002,
        'tags': {
            'name': 'Road B',
            'highway': 'tertiary',
            'official_ref': 'C555;C17'
        },
        'length': 3000
    }
    road_d = {
        'id': 1003,
        'tags': {
            'name': 'Road A',
            'highway': 'tertiary',
            'official_ref': 'C555',
            'highway_authority_ref': 'C17'
        },
        'length': 100
    }
    road_e = {
        'id': 1003,
        'tags': {
            'name': 'Road A',
            'highway': 'tertiary',
            'admin_ref': 'C555'
        },
        'length': 100
    }
    collection = {
        'join_type': 'ref',
        'join_data': 'C555',
        'ways': [road_c, road_d, road_e]
    }
    refs = output.tools.get_shared_collection_refs(collection)
    name = output.tools.get_collection_name(collection)
    assert name == 'Road B (C555)'
示例#19
0
def test_get_collection_curvature(road_a, road_b):
    output = KmlOutput('km')
    collection = {'join_type': 'arbitrary', 'ways': [road_a, road_b]}
    curvature = output.get_collection_curvature(collection)
    assert curvature == 750