]> git.openstreetmap.org Git - nominatim.git/blob - test/python/api/search/test_query_analyzer_factory.py
enable all API tests for sqlite and port missing features
[nominatim.git] / test / python / api / search / test_query_analyzer_factory.py
1 # SPDX-License-Identifier: GPL-3.0-or-later
2 #
3 # This file is part of Nominatim. (https://nominatim.org)
4 #
5 # Copyright (C) 2023 by the Nominatim developer community.
6 # For a full list of authors see the git log.
7 """
8 Tests for query analyzer creation.
9 """
10 from pathlib import Path
11
12 import pytest
13
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
17
18 @pytest.mark.asyncio
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/'; 'ä' > 'ä '")))
25
26     api = NominatimAPIAsync(Path('/invalid'), {})
27     async with api.begin() as conn:
28         ana = await make_query_analyzer(conn)
29
30         assert isinstance(ana, ICUQueryAnalyzer)
31     await api.close()
32
33
34 @pytest.mark.asyncio
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')
39
40     async with api.begin() as conn:
41         with pytest.raises(ValueError, match='Property.*not found'):
42             await make_query_analyzer(conn)
43     await api.close()
44
45
46 @pytest.mark.asyncio
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'),))
52
53     async with api.begin() as conn:
54         with pytest.raises(RuntimeError, match='Tokenizer not found'):
55             await make_query_analyzer(conn)
56     await api.close()
57