]> git.openstreetmap.org Git - nominatim.git/blob - test/python/api/search/test_query_analyzer_factory.py
Merge pull request #3530 from lonvia/clean-use-of-os-environ
[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) 2024 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.search.query_analyzer_factory import make_query_analyzer
15 from nominatim_api.search.icu_tokenizer import ICUQueryAnalyzer
16
17 @pytest.mark.asyncio
18 async def test_import_icu_tokenizer(table_factory, api):
19     table_factory('nominatim_properties',
20                   definition='property TEXT, value TEXT',
21                   content=(('tokenizer', 'icu'),
22                            ('tokenizer_import_normalisation', ':: lower();'),
23                            ('tokenizer_import_transliteration', "'1' > '/1/'; 'ä' > 'ä '")))
24
25     async with api.begin() as conn:
26         ana = await make_query_analyzer(conn)
27
28         assert isinstance(ana, ICUQueryAnalyzer)
29
30
31 @pytest.mark.asyncio
32 async def test_import_missing_property(table_factory, api):
33     table_factory('nominatim_properties',
34                   definition='property TEXT, value TEXT')
35
36     async with api.begin() as conn:
37         with pytest.raises(ValueError, match='Property.*not found'):
38             await make_query_analyzer(conn)
39
40
41 @pytest.mark.asyncio
42 async def test_import_missing_module(table_factory, api):
43     table_factory('nominatim_properties',
44                   definition='property TEXT, value TEXT',
45                   content=(('tokenizer', 'missing'),))
46
47     async with api.begin() as conn:
48         with pytest.raises(RuntimeError, match='Tokenizer not found'):
49             await make_query_analyzer(conn)