1 # SPDX-License-Identifier: GPL-3.0-or-later
 
   3 # This file is part of Nominatim. (https://nominatim.org)
 
   5 # Copyright (C) 2025 by the Nominatim developer community.
 
   6 # For a full list of authors see the git log.
 
   8 Tests for export CLI function.
 
  12 import nominatim_db.cli
 
  16 def run_export(tmp_path, capsys):
 
  18         cli_args = ['export', '--project-dir', str(tmp_path)] + args
 
  19         assert 0 == nominatim_db.cli.nominatim(cli_args=cli_args)
 
  20         return capsys.readouterr().out.split('\r\n')
 
  25 @pytest.fixture(autouse=True)
 
  26 def setup_database_with_context(apiobj):
 
  27     apiobj.add_placex(place_id=332, osm_type='W', osm_id=4,
 
  28                       class_='highway', type='residential',  name='Street',
 
  29                       country_code='pl', postcode='55674',
 
  30                       rank_search=27, rank_address=26)
 
  31     apiobj.add_address_placex(332, fromarea=False, isaddress=False,
 
  33                               place_id=1000, osm_type='N', osm_id=3333,
 
  34                               class_='place', type='suburb', name='Smallplace',
 
  35                               country_code='pl', admin_level=13,
 
  36                               rank_search=24, rank_address=23)
 
  37     apiobj.add_address_placex(332, fromarea=True, isaddress=True,
 
  38                               place_id=1001, osm_type='N', osm_id=3334,
 
  39                               class_='place', type='city', name='Bigplace',
 
  41                               rank_search=17, rank_address=16)
 
  44 def test_export_default(run_export):
 
  47     assert csv == ['street,suburb,city,county,state,country', 'Street,,Bigplace,,,', '']
 
  50 def test_export_output_type(run_export):
 
  51     csv = run_export(['--output-type', 'city'])
 
  53     assert csv == ['street,suburb,city,county,state,country', ',,Bigplace,,,', '']
 
  56 def test_export_output_format(run_export):
 
  57     csv = run_export(['--output-format', 'placeid;street;nothing;postcode'])
 
  59     assert csv == ['placeid,street,nothing,postcode', '332,Street,,55674', '']
 
  62 def test_export_restrict_to_node_good(run_export):
 
  63     csv = run_export(['--restrict-to-osm-node', '3334'])
 
  65     assert csv == ['street,suburb,city,county,state,country', 'Street,,Bigplace,,,', '']
 
  68 def test_export_restrict_to_node_not_address(run_export):
 
  69     csv = run_export(['--restrict-to-osm-node', '3333'])
 
  71     assert csv == ['street,suburb,city,county,state,country', '']