1 # SPDX-License-Identifier: GPL-2.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 index command of the command-line interface wrapper.
12 import nominatim_db.indexer.indexer
15 class TestCliIndexWithDb:
17 @pytest.fixture(autouse=True)
18 def setup_cli_call(self, cli_call, cli_tokenizer_mock):
19 self.call_nominatim = cli_call
20 self.tokenizer_mock = cli_tokenizer_mock
22 def test_index_empty_subset(self, monkeypatch, async_mock_func_factory, placex_row):
23 placex_row(rank_address=1, indexed_status=1)
24 placex_row(rank_address=20, indexed_status=1)
27 async_mock_func_factory(nominatim_db.indexer.indexer.Indexer, 'index_boundaries'),
28 async_mock_func_factory(nominatim_db.indexer.indexer.Indexer, 'index_by_rank'),
29 async_mock_func_factory(nominatim_db.indexer.indexer.Indexer, 'index_postcodes'),
32 def _reject_repeat_call(*args, **kwargs):
33 assert False, "Did not expect multiple Indexer.has_pending invocations"
35 has_pending_calls = [nominatim_db.indexer.indexer.Indexer.has_pending, _reject_repeat_call]
36 monkeypatch.setattr(nominatim_db.indexer.indexer.Indexer, 'has_pending',
37 lambda *args, **kwargs: has_pending_calls.pop(0)(*args, **kwargs))
39 assert self.call_nominatim('index', '--minrank', '5', '--maxrank', '10') == 0
42 assert mock.called == 1, "Mock '{}' not called".format(mock.func_name)