5 class MockParamCapture:
6 """ Mock that records the parameters with which a function was called
7 as well as the number of calls.
9 def __init__(self, retval=0):
11 self.return_value = retval
13 self.last_kwargs = None
15 def __call__(self, *args, **kwargs):
18 self.last_kwargs = kwargs
19 return self.return_value
23 def __init__(self, *args, **kwargs):
24 self.update_sql_functions_called = False
25 self.finalize_import_called = False
26 self.update_statistics_called = False
28 def update_sql_functions(self, *args):
29 self.update_sql_functions_called = True
31 def finalize_import(self, *args):
32 self.finalize_import_called = True
34 def update_statistics(self):
35 self.update_statistics_called = True
39 def cli_call(src_dir):
40 """ Call the nominatim main function with the correct paths set.
41 Returns a function that can be called with the desired CLI arguments.
43 def _call_nominatim(*args):
44 return nominatim.cli.nominatim(module_dir='MODULE NOT AVAILABLE',
45 osm2pgsql_path='OSM2PGSQL NOT AVAILABLE',
46 phplib_dir=str(src_dir / 'lib-php'),
47 data_dir=str(src_dir / 'data'),
48 phpcgi_path='/usr/bin/php-cgi',
49 sqllib_dir=str(src_dir / 'lib-sql'),
50 config_dir=str(src_dir / 'settings'),
53 return _call_nominatim
57 def mock_run_legacy(monkeypatch):
58 mock = MockParamCapture()
59 monkeypatch.setattr(nominatim.cli, 'run_legacy_script', mock)
64 def mock_func_factory(monkeypatch):
65 def get_mock(module, func):
66 mock = MockParamCapture()
68 monkeypatch.setattr(module, func, mock)
75 def cli_tokenizer_mock(monkeypatch):
76 tok = DummyTokenizer()
77 monkeypatch.setattr(nominatim.tokenizer.factory, 'get_tokenizer_for_db',
79 monkeypatch.setattr(nominatim.tokenizer.factory, 'create_tokenizer',