1 # SPDX-License-Identifier: GPL-3.0-or-later
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2023 by the Nominatim developer community.
6 # For a full list of authors see the git log.
8 Tests for result datatype helper functions.
14 import sqlalchemy as sa
17 from nominatim.api import SourceTable, DetailedResult, Point
18 import nominatim.api.results as nresults
21 def __init__(self, x, y):
22 self.data = struct.pack("=biidd", 1, 0x20000001, 4326,
26 def __init__(self, **kwargs):
27 for k, v in kwargs.items():
29 self._mapping = kwargs
32 def test_minimal_detailed_result():
33 res = DetailedResult(SourceTable.PLACEX,
34 ('amenity', 'post_box'),
37 assert res.lon == 23.1
39 assert res.calculated_importance() == pytest.approx(0.0000001)
41 def test_detailed_result_custom_importance():
42 res = DetailedResult(SourceTable.PLACEX,
43 ('amenity', 'post_box'),
47 assert res.calculated_importance() == 0.4563
50 @pytest.mark.parametrize('func', (nresults.create_from_placex_row,
51 nresults.create_from_osmline_row,
52 nresults.create_from_tiger_row,
53 nresults.create_from_postcode_row))
54 def test_create_row_none(func):
55 assert func(None, DetailedResult) is None
58 @pytest.mark.parametrize('func', (nresults.create_from_osmline_row,
59 nresults.create_from_tiger_row))
60 def test_create_row_with_housenumber(func):
61 row = FakeRow(place_id=2345, osm_type='W', osm_id=111, housenumber=4,
62 address=None, postcode='99900', country_code='xd',
63 centroid=FakeCentroid(0, 0))
65 res = func(row, DetailedResult)
67 assert res.housenumber == '4'
68 assert res.extratags is None
69 assert res.category == ('place', 'house')
72 @pytest.mark.parametrize('func', (nresults.create_from_osmline_row,
73 nresults.create_from_tiger_row))
74 def test_create_row_without_housenumber(func):
75 row = FakeRow(place_id=2345, osm_type='W', osm_id=111,
76 startnumber=1, endnumber=11, step=2,
77 address=None, postcode='99900', country_code='xd',
78 centroid=FakeCentroid(0, 0))
80 res = func(row, DetailedResult)
82 assert res.housenumber is None
83 assert res.extratags == {'startnumber': '1', 'endnumber': '11', 'step': '2'}
84 assert res.category == ('place', 'houses')