]> git.openstreetmap.org Git - nominatim.git/blob - test/python/tools/test_sp_importer.py
reorganise fixtures for placex table
[nominatim.git] / test / python / tools / test_sp_importer.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) 2026 by the Nominatim developer community.
6 # For a full list of authors see the git log.
7
8 from nominatim_db.tools.special_phrases.sp_importer import SPImporter
9
10
11 # Testing Database Class Pair Retrival using Conftest.py and placex
12 def test_get_classtype_pair_data(placex_row, def_config, temp_db_conn):
13     for _ in range(100):
14         placex_row(cls='highway', typ='motorway')  # edge case 100
15
16     for _ in range(99):
17         placex_row(cls='amenity', typ='prison')  # edge case 99
18
19     for _ in range(150):
20         placex_row(cls='tourism', typ='hotel')
21
22     importer = SPImporter(config=def_config, conn=temp_db_conn, sp_loader=None)
23
24     result = importer.get_classtype_pairs(min=100)
25
26     assert result == {
27         ("highway", "motorway"),
28         ("tourism", "hotel")
29     }
30
31
32 def test_get_classtype_pair_data_more(placex_row, def_config, temp_db_conn):
33     for _ in range(99):
34         placex_row(cls='emergency', typ='firehydrant')  # edge case 99, not included
35
36     for _ in range(199):
37         placex_row(cls='amenity', typ='prison')
38
39     for _ in range(3478):
40         placex_row(cls='tourism', typ='hotel')
41
42     importer = SPImporter(config=def_config, conn=temp_db_conn, sp_loader=None)
43
44     result = importer.get_classtype_pairs(min=100)
45
46     assert result == {
47         ("amenity", "prison"),
48         ("tourism", "hotel")
49     }
50
51
52 def test_get_classtype_pair_data_default(placex_row, def_config, temp_db_conn):
53     for _ in range(1):
54         placex_row(cls='emergency', typ='firehydrant')
55
56     for _ in range(199):
57         placex_row(cls='amenity', typ='prison')
58
59     for _ in range(3478):
60         placex_row(cls='tourism', typ='hotel')
61
62     importer = SPImporter(config=def_config, conn=temp_db_conn, sp_loader=None)
63
64     result = importer.get_classtype_pairs()
65
66     assert result == {
67         ("amenity", "prison"),
68         ("tourism", "hotel"),
69         ("emergency", "firehydrant")
70     }