]> git.openstreetmap.org Git - nominatim.git/blob - test/python/dummy_tokenizer.py
reintroduce file logging for Python frontend
[nominatim.git] / test / python / dummy_tokenizer.py
1 # SPDX-License-Identifier: GPL-2.0-only
2 #
3 # This file is part of Nominatim. (https://nominatim.org)
4 #
5 # Copyright (C) 2022 by the Nominatim developer community.
6 # For a full list of authors see the git log.
7 """
8 Tokenizer for testing.
9 """
10 from nominatim.data.place_info import PlaceInfo
11 from nominatim.config import Configuration
12
13 def create(dsn, data_dir):
14     """ Create a new instance of the tokenizer provided by this module.
15     """
16     return DummyTokenizer(dsn, data_dir)
17
18 class DummyTokenizer:
19
20     def __init__(self, dsn, data_dir):
21         self.dsn = dsn
22         self.data_dir = data_dir
23         self.init_state = None
24         self.analyser_cache = {}
25
26
27     def init_new_db(self, *args, **kwargs):
28         assert self.init_state is None
29         self.init_state = "new"
30
31
32     def init_from_project(self, config):
33         assert isinstance(config, Configuration)
34         assert self.init_state is None
35         self.init_state = "loaded"
36
37
38     @staticmethod
39     def finalize_import(_):
40         pass
41
42
43     def name_analyzer(self):
44         return DummyNameAnalyzer(self.analyser_cache)
45
46
47 class DummyNameAnalyzer:
48
49     def __enter__(self):
50         return self
51
52     def __exit__(self, exc_type, exc_value, traceback):
53         self.close()
54
55
56     def __init__(self, cache):
57         self.analyser_cache = cache
58         cache['countries'] = []
59
60
61     def close(self):
62         pass
63
64     @staticmethod
65     def normalize_postcode(postcode):
66         return postcode
67
68     @staticmethod
69     def update_postcodes_from_db():
70         pass
71
72     def update_special_phrases(self, phrases, should_replace):
73         self.analyser_cache['special_phrases'] = phrases
74
75     def add_country_names(self, code, names):
76         self.analyser_cache['countries'].append((code, names))
77
78     @staticmethod
79     def process_place(place):
80         assert isinstance(place, PlaceInfo)
81         return {}