1 # SPDX-License-Identifier: GPL-2.0-only
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2022 by the Nominatim developer community.
6 # For a full list of authors see the git log.
11 class MockParamCapture:
12 """ Mock that records the parameters with which a function was called
13 as well as the number of calls.
15 def __init__(self, retval=0):
17 self.return_value = retval
19 self.last_kwargs = None
21 def __call__(self, *args, **kwargs):
24 self.last_kwargs = kwargs
25 return self.return_value
29 def __init__(self, *args, **kwargs):
30 self.update_sql_functions_called = False
31 self.finalize_import_called = False
32 self.update_statistics_called = False
34 def update_sql_functions(self, *args):
35 self.update_sql_functions_called = True
37 def finalize_import(self, *args):
38 self.finalize_import_called = True
40 def update_statistics(self):
41 self.update_statistics_called = True
45 def cli_call(src_dir):
46 """ Call the nominatim main function with the correct paths set.
47 Returns a function that can be called with the desired CLI arguments.
49 def _call_nominatim(*args):
50 return nominatim.cli.nominatim(module_dir='MODULE NOT AVAILABLE',
51 osm2pgsql_path='OSM2PGSQL NOT AVAILABLE',
52 phplib_dir=str(src_dir / 'lib-php'),
53 data_dir=str(src_dir / 'data'),
54 phpcgi_path='/usr/bin/php-cgi',
55 sqllib_dir=str(src_dir / 'lib-sql'),
56 config_dir=str(src_dir / 'settings'),
59 return _call_nominatim
63 def mock_run_legacy(monkeypatch):
64 mock = MockParamCapture()
65 monkeypatch.setattr(nominatim.cli, 'run_legacy_script', mock)
70 def mock_func_factory(monkeypatch):
71 def get_mock(module, func):
72 mock = MockParamCapture()
74 monkeypatch.setattr(module, func, mock)
81 def cli_tokenizer_mock(monkeypatch):
82 tok = DummyTokenizer()
83 monkeypatch.setattr(nominatim.tokenizer.factory, 'get_tokenizer_for_db',
85 monkeypatch.setattr(nominatim.tokenizer.factory, 'create_tokenizer',