]> git.openstreetmap.org Git - nominatim.git/blob - test/python/api/query_processing/test_normalize.py
Merge remote-tracking branch 'upstream/master'
[nominatim.git] / test / python / api / query_processing / test_normalize.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) 2025 by the Nominatim developer community.
6 # For a full list of authors see the git log.
7 """
8 Tests for normalizing search queries.
9 """
10 from icu import Transliterator
11
12 import nominatim_api.search.query as qmod
13 from nominatim_api.query_preprocessing.config import QueryConfig
14 from nominatim_api.query_preprocessing import normalize
15
16
17 def run_preprocessor_on(query, norm):
18     normalizer = Transliterator.createFromRules("normalization", norm)
19     proc = normalize.create(QueryConfig().set_normalizer(normalizer))
20
21     return proc(query)
22
23
24 def test_normalize_simple():
25     norm = ':: lower();'
26     query = [qmod.Phrase(qmod.PHRASE_ANY, 'Hallo')]
27
28     out = run_preprocessor_on(query, norm)
29
30     assert len(out) == 1
31     assert out == [qmod.Phrase(qmod.PHRASE_ANY, 'hallo')]