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
|
# SPDX-License-Identifier: BSD-2-Clause
#
# This file is part of pyosmium. (https://osmcode.org/pyosmium/)
#
# Copyright (C) 2025 Sarah Hoffmann <lonvia@denofr.de> and others.
# For a full list of authors see the git log.
import pytest
import osmium
def test_waynode_length(simple_handler):
data = """\
w593
w4 Nn1,n2,n-34
w8 Nn12,n12,n12,n0
"""
lens = {}
def way(w):
lens[w.id] = len(w.nodes)
simple_handler(data, way=way)
assert lens == {593: 0, 4: 3, 8: 4}
def test_node_ids(simple_handler):
refs = []
def way(w):
refs.extend(n.ref for n in w.nodes)
assert w.nodes[-2].ref == -34
with pytest.raises(IndexError):
w.nodes[5]
with pytest.raises(IndexError):
w.nodes[-6]
simple_handler("w4 Nn1,n1,n34359737784,n-34,n0", way=way)
assert refs == [1, 1, 34359737784, -34, 0]
def test_missing_location_without_location_handler(simple_handler):
data = """\
n1 x0.5 y10.0
w4 Nn1
"""
refs = []
def way(w):
refs.extend(n.ref for n in w.nodes)
assert not w.nodes[0].location.valid()
with pytest.raises(osmium.InvalidLocationError):
w.nodes[0].location.lat
with pytest.raises(osmium.InvalidLocationError):
w.nodes[0].location.lon
simple_handler(data, way=way)
assert refs == [1]
def test_valid_locations(simple_handler):
data = """\
n1 x0.5 y10.0
w4 Nn1
"""
locations = []
def way(w):
assert all(n.location.valid() for n in w.nodes)
locations.extend((int(10 * n.location.lon), int(10 * n.location.lat))
for n in w.nodes)
simple_handler(data, way=way, locations=True)
assert locations == [(5, 100)]
|