add unit tests for lookup function

This commit is contained in:
Sarah Hoffmann
2023-02-01 22:59:31 +01:00
parent 370c9b38c0
commit 189f74a40d
6 changed files with 338 additions and 7 deletions

View File

@@ -20,4 +20,11 @@ from .status import (StatusResult as StatusResult)
from .types import (PlaceID as PlaceID,
OsmID as OsmID,
PlaceRef as PlaceRef,
GeometryFormat as GeometryFormat,
LookupDetails as LookupDetails)
from .results import (SourceTable as SourceTable,
AddressLine as AddressLine,
AddressLines as AddressLines,
WordInfo as WordInfo,
WordInfos as WordInfos,
SearchResult as SearchResult)

View File

@@ -155,6 +155,12 @@ class NominatimAPI:
self._loop.close()
@property
def config(self) -> Configuration:
""" Return the configuration used by the API.
"""
return self._async_api.config
def status(self) -> StatusResult:
""" Return the status of the database.
"""

View File

@@ -23,8 +23,8 @@ def _select_column_geometry(column: SaColumn,
"""
if geometry_output & ntyp.GeometryFormat.GEOJSON:
return sa.literal_column(f"""
ST_AsGeoJSON(CASE WHEN ST_NPoints({0}) > 5000
THEN ST_SimplifyPreserveTopology({0}, 0.0001)
ST_AsGeoJSON(CASE WHEN ST_NPoints({column.name}) > 5000
THEN ST_SimplifyPreserveTopology({column.name}, 0.0001)
ELSE {column.name} END)
""").label('geometry_geojson')

View File

@@ -45,7 +45,7 @@ class AddressLine:
names: Dict[str, str]
extratags: Optional[Dict[str, str]]
admin_level: int
admin_level: Optional[int]
fromarea: bool
isaddress: bool
rank_address: int
@@ -187,10 +187,16 @@ def _result_row_to_address_row(row: SaRow) -> AddressLine:
if 'place_type' in row:
extratags['place_type'] = row.place_type
names = row.name
if getattr(row, 'housenumber', None) is not None:
if names is None:
names = {}
names['housenumber'] = row.housenumber
return AddressLine(place_id=row.place_id,
osm_object=(row.osm_type, row.osm_id),
osm_object=None if row.osm_type is None else (row.osm_type, row.osm_id),
category=(getattr(row, 'class'), row.type),
names=row.name,
names=names,
extratags=extratags,
admin_level=row.admin_level,
fromarea=row.fromarea,
@@ -235,7 +241,7 @@ def _placex_select_address_row(conn: SearchConnection,
t = conn.t.placex
return sa.select(t.c.place_id, t.c.osm_type, t.c.osm_id, t.c.name,
t.c.class_.label('class'), t.c.type,
t.c.admin_level,
t.c.admin_level, t.c.housenumber,
sa.literal_column("""ST_GeometryType(geometry) in
('ST_Polygon','ST_MultiPolygon')""").label('fromarea'),
t.c.rank_address,