]> git.openstreetmap.org Git - nominatim.git/blob - test/python/tools/test_freeze.py
Merge remote-tracking branch 'upstream/master'
[nominatim.git] / test / python / tools / test_freeze.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 freeze functions (removing unused database parts).
9 """
10 from nominatim_db.tools import freeze
11
12 NOMINATIM_RUNTIME_TABLES = [
13     'country_name', 'country_osm_grid',
14     'location_postcodes', 'location_property_osmline', 'location_property_tiger',
15     'placex', 'place_addressline',
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', 'place_associated_street',
25     'planet_osm_nodes', 'planet_osm_rels', 'planet_osm_ways',
26     'search_name_111',
27     'wikipedia_article', 'wikipedia_redirect'
28 ]
29
30
31 def test_drop_tables(temp_db_conn, temp_db_cursor, table_factory):
32     for table in NOMINATIM_RUNTIME_TABLES + NOMINATIM_DROP_TABLES:
33         table_factory(table)
34
35     assert not freeze.is_frozen(temp_db_conn)
36
37     freeze.drop_update_tables(temp_db_conn)
38
39     for table in NOMINATIM_RUNTIME_TABLES:
40         assert temp_db_cursor.table_exists(table)
41
42     for table in NOMINATIM_DROP_TABLES:
43         assert not temp_db_cursor.table_exists(table)
44
45     assert freeze.is_frozen(temp_db_conn)
46
47
48 def test_drop_flatnode_file_no_file():
49     freeze.drop_flatnode_file(None)
50
51
52 def test_drop_flatnode_file_file_already_gone(tmp_path):
53     freeze.drop_flatnode_file(tmp_path / 'something.store')
54
55
56 def test_drop_flatnode_file_delete(tmp_path):
57     flatfile = tmp_path / 'flatnode.store'
58     flatfile.write_text('Some content', encoding="utf-8")
59
60     freeze.drop_flatnode_file(flatfile)
61
62     assert not flatfile.exists()