File: test_area.py

package info (click to toggle)
pyosmium 4.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,584 kB
  • sloc: python: 4,400; cpp: 2,504; makefile: 20
file content (54 lines) | stat: -rw-r--r-- 1,406 bytes parent folder | download | duplicates (4)
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
# 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.
from pathlib import Path

import pytest
import osmium

from helpers import CountingHandler


TEST_FILE = str((Path(__file__) / '..' / 'example-test.pbf').resolve())


@pytest.mark.thread_unsafe
def test_area_handler():
    area = osmium.area.AreaManager()

    osmium.apply(osmium.io.Reader(TEST_FILE), area.first_pass_handler())

    ch_area = CountingHandler()
    ch_others = CountingHandler()

    lh = osmium.NodeLocationsForWays(osmium.index.create_map("flex_mem"))
    lh.ignore_errors()

    osmium.apply(osmium.io.Reader(TEST_FILE), lh,
                 ch_others, area.second_pass_handler(ch_area))

    assert ch_area.counts == [0, 0, 0, 5239]
    assert ch_others.counts == [211100, 10315, 244, 0]


def test_area_buffer_handler():
    area = osmium.area.AreaManager()

    osmium.apply(osmium.io.Reader(TEST_FILE), area.first_pass_handler())

    lh = osmium.NodeLocationsForWays(osmium.index.create_map("flex_mem"))
    lh.ignore_errors()

    buf = osmium.BufferIterator()

    osmium.apply(osmium.io.Reader(TEST_FILE), lh, area.second_pass_to_buffer(buf))

    counts = 0
    for obj in buf:
        assert obj.is_area()
        counts += 1

    assert counts == 5239