1 # SPDX-License-Identifier: GPL-3.0-or-later
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2023 by the Nominatim developer community.
6 # For a full list of authors see the git log.
8 Tests for query analyzer creation.
10 from pathlib import Path
14 from nominatim.api import NominatimAPIAsync
15 from nominatim.api.search.query_analyzer_factory import make_query_analyzer
16 from nominatim.api.search.icu_tokenizer import ICUQueryAnalyzer
19 async def test_import_icu_tokenizer(table_factory):
20 table_factory('nominatim_properties',
21 definition='property TEXT, value TEXT',
22 content=(('tokenizer', 'icu'),
23 ('tokenizer_import_normalisation', ':: lower();'),
24 ('tokenizer_import_transliteration', "'1' > '/1/'; 'ä' > 'ä '")))
26 api = NominatimAPIAsync(Path('/invalid'), {})
27 async with api.begin() as conn:
28 ana = await make_query_analyzer(conn)
30 assert isinstance(ana, ICUQueryAnalyzer)
35 async def test_import_missing_property(table_factory):
36 api = NominatimAPIAsync(Path('/invalid'), {})
37 table_factory('nominatim_properties',
38 definition='property TEXT, value TEXT')
40 async with api.begin() as conn:
41 with pytest.raises(ValueError, match='Property.*not found'):
42 await make_query_analyzer(conn)
47 async def test_import_missing_module(table_factory):
48 api = NominatimAPIAsync(Path('/invalid'), {})
49 table_factory('nominatim_properties',
50 definition='property TEXT, value TEXT',
51 content=(('tokenizer', 'missing'),))
53 async with api.begin() as conn:
54 with pytest.raises(RuntimeError, match='Tokenizer not found'):
55 await make_query_analyzer(conn)