1 # SPDX-License-Identifier: GPL-3.0-or-later
 
   3 # This file is part of Nominatim. (https://nominatim.org)
 
   5 # Copyright (C) 2025 by the Nominatim developer community.
 
   6 # For a full list of authors see the git log.
 
   8 Tests for result datatype helper functions.
 
  11 from binascii import hexlify
 
  15 from nominatim_api import SourceTable, DetailedResult, Point
 
  16 import nominatim_api.results as nresults
 
  20     return hexlify(struct.pack("=biidd", 1, 0x20000001, 4326, x, y)).decode('utf-8')
 
  24     def __init__(self, **kwargs):
 
  25         if 'parent_place_id' not in kwargs:
 
  26             kwargs['parent_place_id'] = None
 
  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.00001)
 
  42 def test_detailed_result_custom_importance():
 
  43     res = DetailedResult(SourceTable.PLACEX,
 
  44                          ('amenity', 'post_box'),
 
  48     assert res.calculated_importance() == 0.4563
 
  51 @pytest.mark.parametrize('func', (nresults.create_from_osmline_row,
 
  52                                   nresults.create_from_tiger_row))
 
  53 def test_create_row_with_housenumber(func):
 
  54     row = FakeRow(place_id=2345, osm_type='W', osm_id=111, housenumber=4,
 
  55                   address=None, postcode='99900', country_code='xd',
 
  56                   centroid=mkpoint(0, 0))
 
  58     res = func(row, DetailedResult)
 
  60     assert res.housenumber == '4'
 
  61     assert res.extratags is None
 
  62     assert res.category == ('place', 'house')
 
  65 @pytest.mark.parametrize('func', (nresults.create_from_osmline_row,
 
  66                                   nresults.create_from_tiger_row))
 
  67 def test_create_row_without_housenumber(func):
 
  68     row = FakeRow(place_id=2345, osm_type='W', osm_id=111,
 
  69                   startnumber=1, endnumber=11, step=2,
 
  70                   address=None, postcode='99900', country_code='xd',
 
  71                   centroid=mkpoint(0, 0))
 
  73     res = func(row, DetailedResult)
 
  75     assert res.housenumber is None
 
  76     assert res.extratags == {'startnumber': '1', 'endnumber': '11', 'step': '2'}
 
  77     assert res.category == ('place', 'houses')