]> git.openstreetmap.org Git - nominatim.git/blob - test/python/api/test_export.py
remove warning about now removed legacy tokenizer
[nominatim.git] / test / python / api / test_export.py
1 # SPDX-License-Identifier: GPL-3.0-or-later
2 #
3 # This file is part of Nominatim. (https://nominatim.org)
4 #
5 # Copyright (C) 2024 by the Nominatim developer community.
6 # For a full list of authors see the git log.
7 """
8 Tests for export CLI function.
9 """
10 import pytest
11
12 import nominatim_db.cli
13
14 @pytest.fixture
15 def run_export(tmp_path, capsys):
16     def _exec(args):
17         assert 0 == nominatim_db.cli.nominatim(module_dir='MODULE NOT AVAILABLE',
18                                                osm2pgsql_path='OSM2PGSQL NOT AVAILABLE',
19                                                cli_args=['export', '--project-dir', str(tmp_path)]
20                                                         + args)
21         return capsys.readouterr().out.split('\r\n')
22
23     return _exec
24
25
26 @pytest.fixture(autouse=True)
27 def setup_database_with_context(apiobj):
28     apiobj.add_placex(place_id=332, osm_type='W', osm_id=4,
29                      class_='highway', type='residential',  name='Street',
30                      country_code='pl', postcode='55674',
31                      rank_search=27, rank_address=26)
32     apiobj.add_address_placex(332, fromarea=False, isaddress=False,
33                               distance=0.0034,
34                               place_id=1000, osm_type='N', osm_id=3333,
35                               class_='place', type='suburb', name='Smallplace',
36                               country_code='pl', admin_level=13,
37                               rank_search=24, rank_address=23)
38     apiobj.add_address_placex(332, fromarea=True, isaddress=True,
39                               place_id=1001, osm_type='N', osm_id=3334,
40                               class_='place', type='city', name='Bigplace',
41                               country_code='pl',
42                               rank_search=17, rank_address=16)
43
44
45 def test_export_default(run_export):
46     csv = run_export([])
47
48     assert csv == ['street,suburb,city,county,state,country', 'Street,,Bigplace,,,', '']
49
50
51 def test_export_output_type(run_export):
52     csv = run_export(['--output-type', 'city'])
53
54     assert csv == ['street,suburb,city,county,state,country', ',,Bigplace,,,', '']
55
56
57 def test_export_output_format(run_export):
58     csv = run_export(['--output-format', 'placeid;street;nothing;postcode'])
59
60     assert csv == ['placeid,street,nothing,postcode', '332,Street,,55674', '']
61
62
63 def test_export_restrict_to_node_good(run_export):
64     csv = run_export(['--restrict-to-osm-node', '3334'])
65
66     assert csv == ['street,suburb,city,county,state,country', 'Street,,Bigplace,,,', '']
67
68
69 def test_export_restrict_to_node_not_address(run_export):
70     csv = run_export(['--restrict-to-osm-node', '3333'])
71
72     assert csv == ['street,suburb,city,county,state,country', '']