1111from helpers import CountingHandler
1212
1313
14- class NullHandler :
15-
16- def node (self , n ):
17- pass
18-
19-
20- def _run_file (fn ):
21- with osmium .io .Reader (fn ) as rd :
22- osmium .apply (rd , NullHandler ())
23-
24-
2514@pytest .mark .parametrize ('as_string' , [True , False ])
2615def test_file_simple (tmp_path , as_string ):
2716 fn = tmp_path / f"{ uuid .uuid4 ()} .opl"
@@ -48,36 +37,12 @@ def test_file_with_format(tmp_path, as_string):
4837 assert n .id == 1
4938
5039
51- def test_node_only (test_data ):
52- _run_file (test_data ('n1' ))
53-
54-
55- def test_way_only (test_data ):
56- _run_file (test_data ('w1 Nn1,n2,n3' ))
57-
58-
59- def test_relation_only (test_data ):
60- _run_file (test_data ('r573 Mw1@' ))
61-
62-
63- def test_node_with_tags (test_data ):
64- _run_file (test_data ('n32 Tbar=xx' ))
65-
66-
67- def test_way_with_tags (test_data ):
68- _run_file (test_data ('w5666 Nn1,n2,n3 Tbar=xx' ))
69-
70-
71- def test_relation_with_tags (test_data ):
72- _run_file (test_data ('r573 Mw1@ Tbar=xx' ))
73-
74-
7540def test_broken_timestamp (test_data ):
7641 fn = test_data ('n1 tx' )
7742
7843 with osmium .io .Reader (fn ) as rd :
7944 with pytest .raises (RuntimeError ):
80- osmium .apply (rd , NullHandler ())
45+ osmium .apply (rd , CountingHandler ())
8146
8247
8348@pytest .mark .parametrize ('as_string' , [True , False ])
@@ -101,11 +66,38 @@ def test_file_header(tmp_path, as_string):
10166
10267def test_reader_with_filebuffer ():
10368 rd = osmium .io .Reader (osmium .io .FileBuffer ('n1 x4 y1' .encode ('utf-8' ), 'opl' ))
104- handler = CountingHandler ()
69+ try :
70+ handler = CountingHandler ()
71+
72+ osmium .apply (rd , handler )
73+
74+ assert handler .counts == [1 , 0 , 0 , 0 ]
75+ assert rd .eof ()
76+ finally :
77+ rd .close ()
78+
79+
80+ def test_reader_with_separate_thread_pool (test_data ):
81+ with osmium .io .Reader (test_data ('n1 x1 y1' ), thread_pool = osmium .io .ThreadPool ()) as rd :
82+ for obj in osmium .OsmFileIterator (rd ):
83+ assert obj .id == 1
84+
85+
86+ @pytest .mark .parametrize ("entities,expected" , [(osmium .osm .NODE , [2 , 0 , 0 , 0 ]),
87+ (osmium .osm .ALL , [2 , 1 , 1 , 0 ])])
88+ def test_reader_with_entity_filter (test_data , entities , expected ):
89+ fn = test_data ("""\
90+ n1 x1 y2
91+ n2 x1 y3
92+ w34 Nn1,n2
93+ r67 Mw34@
94+ """ )
10595
106- osmium .apply (rd , handler )
96+ h = CountingHandler ()
97+ with osmium .io .Reader (fn , entities ) as rd :
98+ osmium .apply (rd , h )
10799
108- assert handler .counts == [ 1 , 0 , 0 , 0 ]
100+ assert h .counts == expected
109101
110102
111103def test_thread_pool ():
0 commit comments