Skip to content

Commit 8cc9d7b

Browse files
committed
add simple test for merging in MergeInputReader
1 parent 46d656b commit 8cc9d7b

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed

test/test_merge_input_reader.py

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# SPDX-License-Identifier: BSD-2-Clause
2+
#
3+
# This file is part of pyosmium. (https://osmcode.org/pyosmium/)
4+
#
5+
# Copyright (C) 2026 Sarah Hoffmann <lonvia@denofr.de> and others.
6+
# For a full list of authors see the git log.
7+
from textwrap import dedent
8+
import uuid
9+
10+
import pytest
11+
12+
import osmium
13+
14+
15+
class ListHandler:
16+
def __init__(self):
17+
self.data = []
18+
19+
def node(self, o):
20+
self.data.append(f"N{o.id}/{o.version}")
21+
22+
def way(self, o):
23+
self.data.append(f"W{o.id}/{o.version}")
24+
25+
def relation(self, o):
26+
self.data.append(f"R{o.id}/{o.version}")
27+
28+
def area(self, _):
29+
assert not "Area handler should not be called"
30+
31+
32+
def add_as_buffer(mir, opl, tmp_path):
33+
mir.add_buffer(dedent(opl).encode('utf-8'), format='opl')
34+
35+
36+
def add_as_file(mir, opl, tmp_path):
37+
fn = tmp_path / (str(uuid.uuid4()) + '.opl')
38+
fn.write_text(dedent(opl))
39+
40+
mir.add_file(str(fn))
41+
42+
43+
@pytest.mark.parametrize('adder', [add_as_buffer, add_as_file])
44+
def test_simple_input(adder, tmp_path):
45+
mir = osmium.MergeInputReader()
46+
47+
opl = """\
48+
n1 v1 x1 y1
49+
w3 v34 Nn1
50+
"""
51+
52+
adder(mir, opl, tmp_path)
53+
54+
h = ListHandler()
55+
mir.apply(h)
56+
57+
assert h.data == ['N1/1', 'W3/34']
58+
59+
60+
@pytest.mark.parametrize('adder', [add_as_buffer, add_as_file])
61+
def test_multibuffer_no_simplify(adder, tmp_path):
62+
mir = osmium.MergeInputReader()
63+
64+
opls = ["""\
65+
n1 v1 x1 y1
66+
w3 v2 Nn1
67+
""",
68+
"""\
69+
n2 v1 x1 y1
70+
w3 v1 Nn2
71+
"""]
72+
73+
for opl in opls:
74+
adder(mir, opl, tmp_path)
75+
76+
h = ListHandler()
77+
mir.apply(h, simplify=False)
78+
79+
assert h.data == ['N1/1', 'N2/1', 'W3/1', 'W3/2']
80+
81+
82+
@pytest.mark.parametrize('adder', [add_as_buffer, add_as_file])
83+
def test_multibuffer_simplify(adder, tmp_path):
84+
mir = osmium.MergeInputReader()
85+
86+
opls = ["""\
87+
n1 v1 x1 y1
88+
w3 v2 Nn1
89+
""",
90+
"""\
91+
n2 v1 x1 y1
92+
w3 v1 Nn2
93+
"""]
94+
95+
for opl in opls:
96+
adder(mir, opl, tmp_path)
97+
98+
h = ListHandler()
99+
mir.apply(h, simplify=True)
100+
101+
assert h.data == ['N1/1', 'N2/1', 'W3/2']

0 commit comments

Comments
 (0)