]> git.openstreetmap.org Git - nominatim.git/blob - test/python/tools/test_freeze.py
Merge pull request #2770 from lonvia/typed-python
[nominatim.git] / test / python / tools / test_freeze.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 Tests for freeze functions (removing unused database parts).
9 """
10 from nominatim.tools import freeze
11
12 NOMINATIM_RUNTIME_TABLES = [
13     'country_name', 'country_osm_grid',
14     'location_postcode', 'location_property_osmline', 'location_property_tiger',
15     'placex', 'place_adressline',
16     'search_name',
17     'word'
18 ]
19
20 NOMINATIM_DROP_TABLES = [
21     'address_levels',
22     'location_area', 'location_area_country', 'location_area_large_100',
23     'location_road_1',
24     'place', 'planet_osm_nodes', 'planet_osm_rels', 'planet_osm_ways',
25     'search_name_111',
26     'wikipedia_article', 'wikipedia_redirect'
27 ]
28
29 def test_drop_tables(temp_db_conn, temp_db_cursor, table_factory):
30     for table in NOMINATIM_RUNTIME_TABLES + NOMINATIM_DROP_TABLES:
31         table_factory(table)
32
33     freeze.drop_update_tables(temp_db_conn)
34
35     for table in NOMINATIM_RUNTIME_TABLES:
36         assert temp_db_cursor.table_exists(table)
37
38     for table in NOMINATIM_DROP_TABLES:
39         assert not temp_db_cursor.table_exists(table)
40
41 def test_drop_flatnode_file_no_file():
42     freeze.drop_flatnode_file(None)
43
44
45 def test_drop_flatnode_file_file_already_gone(tmp_path):
46     freeze.drop_flatnode_file(tmp_path / 'something.store')
47
48
49 def test_drop_flatnode_file_delte(tmp_path):
50     flatfile = tmp_path / 'flatnode.store'
51     flatfile.write_text('Some content')
52
53     freeze.drop_flatnode_file(flatfile)
54
55     assert not flatfile.exists()