]> git.openstreetmap.org Git - nominatim.git/blobdiff - test/python/api/test_result_formatting_v1_reverse.py
enable flake for Python tests
[nominatim.git] / test / python / api / test_result_formatting_v1_reverse.py
index d9d43953c3ed13607a05b30cac8254e53bc8586f..902f0e7939393b13434800a8106a8f3f2e9a1e4c 100644 (file)
@@ -1,8 +1,8 @@
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-3.0-or-later
 #
 # This file is part of Nominatim. (https://nominatim.org)
 #
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2025 by the Nominatim developer community.
 # For a full list of authors see the git log.
 """
 Tests for formatting reverse results for the V1 API.
@@ -15,18 +15,19 @@ import xml.etree.ElementTree as ET
 
 import pytest
 
-import nominatim.api.v1 as api_impl
-import nominatim.api as napi
+from nominatim_api.v1.format import dispatch as v1_format
+import nominatim_api as napi
 
 FORMATS = ['json', 'jsonv2', 'geojson', 'geocodejson', 'xml']
 
+
 @pytest.mark.parametrize('fmt', FORMATS)
 def test_format_reverse_minimal(fmt):
     reverse = napi.ReverseResult(napi.SourceTable.PLACEX,
                                  ('amenity', 'post_box'),
                                  napi.Point(0.3, -8.9))
 
-    raw = api_impl.format_result(napi.ReverseResults([reverse]), fmt, {})
+    raw = v1_format.format_result(napi.ReverseResults([reverse]), fmt, {})
 
     if fmt == 'xml':
         root = ET.fromstring(raw)
@@ -38,7 +39,7 @@ def test_format_reverse_minimal(fmt):
 
 @pytest.mark.parametrize('fmt', FORMATS)
 def test_format_reverse_no_result(fmt):
-    raw = api_impl.format_result(napi.ReverseResults(), fmt, {})
+    raw = v1_format.format_result(napi.ReverseResults(), fmt, {})
 
     if fmt == 'xml':
         root = ET.fromstring(raw)
@@ -55,7 +56,7 @@ def test_format_reverse_with_osm_id(fmt):
                                  place_id=5564,
                                  osm_object=('N', 23))
 
-    raw = api_impl.format_result(napi.ReverseResults([reverse]), fmt, {})
+    raw = v1_format.format_result(napi.ReverseResults([reverse]), fmt, {})
 
     if fmt == 'xml':
         root = ET.fromstring(raw).find('result')
@@ -103,9 +104,8 @@ def test_format_reverse_with_address(fmt):
                                  ]))
     reverse.localize(napi.Locales())
 
-    raw = api_impl.format_result(napi.ReverseResults([reverse]), fmt,
-                                 {'addressdetails': True})
-
+    raw = v1_format.format_result(napi.ReverseResults([reverse]), fmt,
+                                  {'addressdetails': True})
 
     if fmt == 'xml':
         root = ET.fromstring(raw)
@@ -167,8 +167,8 @@ def test_format_reverse_geocodejson_special_parts():
 
     reverse.localize(napi.Locales())
 
-    raw = api_impl.format_result(napi.ReverseResults([reverse]), 'geocodejson',
-                                 {'addressdetails': True})
+    raw = v1_format.format_result(napi.ReverseResults([reverse]), 'geocodejson',
+                                  {'addressdetails': True})
 
     props = json.loads(raw)['features'][0]['properties']['geocoding']
     assert props['housenumber'] == '1'
@@ -183,9 +183,8 @@ def test_format_reverse_with_address_none(fmt):
                                  napi.Point(1.0, 2.0),
                                  address_rows=napi.AddressLines())
 
-    raw = api_impl.format_result(napi.ReverseResults([reverse]), fmt,
-                                 {'addressdetails': True})
-
+    raw = v1_format.format_result(napi.ReverseResults([reverse]), fmt,
+                                  {'addressdetails': True})
 
     if fmt == 'xml':
         root = ET.fromstring(raw)
@@ -211,10 +210,10 @@ def test_format_reverse_with_extratags(fmt):
     reverse = napi.ReverseResult(napi.SourceTable.PLACEX,
                                  ('place', 'thing'),
                                  napi.Point(1.0, 2.0),
-                                 extratags={'one': 'A', 'two':'B'})
+                                 extratags={'one': 'A', 'two': 'B'})
 
-    raw = api_impl.format_result(napi.ReverseResults([reverse]), fmt,
-                                 {'extratags': True})
+    raw = v1_format.format_result(napi.ReverseResults([reverse]), fmt,
+                                  {'extratags': True})
 
     if fmt == 'xml':
         root = ET.fromstring(raw)
@@ -226,7 +225,7 @@ def test_format_reverse_with_extratags(fmt):
         else:
             extra = result['extratags']
 
-        assert extra == {'one': 'A', 'two':'B'}
+        assert extra == {'one': 'A', 'two': 'B'}
 
 
 @pytest.mark.parametrize('fmt', ['json', 'jsonv2', 'geojson', 'xml'])
@@ -235,8 +234,8 @@ def test_format_reverse_with_extratags_none(fmt):
                                  ('place', 'thing'),
                                  napi.Point(1.0, 2.0))
 
-    raw = api_impl.format_result(napi.ReverseResults([reverse]), fmt,
-                                 {'extratags': True})
+    raw = v1_format.format_result(napi.ReverseResults([reverse]), fmt,
+                                  {'extratags': True})
 
     if fmt == 'xml':
         root = ET.fromstring(raw)
@@ -256,10 +255,10 @@ def test_format_reverse_with_namedetails_with_name(fmt):
     reverse = napi.ReverseResult(napi.SourceTable.PLACEX,
                                  ('place', 'thing'),
                                  napi.Point(1.0, 2.0),
-                                 names={'name': 'A', 'ref':'1'})
+                                 names={'name': 'A', 'ref': '1'})
 
-    raw = api_impl.format_result(napi.ReverseResults([reverse]), fmt,
-                                 {'namedetails': True})
+    raw = v1_format.format_result(napi.ReverseResults([reverse]), fmt,
+                                  {'namedetails': True})
 
     if fmt == 'xml':
         root = ET.fromstring(raw)
@@ -271,7 +270,7 @@ def test_format_reverse_with_namedetails_with_name(fmt):
         else:
             extra = result['namedetails']
 
-        assert extra == {'name': 'A', 'ref':'1'}
+        assert extra == {'name': 'A', 'ref': '1'}
 
 
 @pytest.mark.parametrize('fmt', ['json', 'jsonv2', 'geojson', 'xml'])
@@ -280,8 +279,8 @@ def test_format_reverse_with_namedetails_without_name(fmt):
                                  ('place', 'thing'),
                                  napi.Point(1.0, 2.0))
 
-    raw = api_impl.format_result(napi.ReverseResults([reverse]), fmt,
-                                 {'namedetails': True})
+    raw = v1_format.format_result(napi.ReverseResults([reverse]), fmt,
+                                  {'namedetails': True})
 
     if fmt == 'xml':
         root = ET.fromstring(raw)
@@ -302,8 +301,8 @@ def test_search_details_with_icon_available(fmt):
                                  ('amenity', 'restaurant'),
                                  napi.Point(1.0, 2.0))
 
-    result = api_impl.format_result(napi.ReverseResults([reverse]), fmt,
-                                    {'icon_base_url': 'foo'})
+    result = v1_format.format_result(napi.ReverseResults([reverse]), fmt,
+                                     {'icon_base_url': 'foo'})
 
     js = json.loads(result)
 
@@ -316,8 +315,7 @@ def test_search_details_with_icon_not_available(fmt):
                                  ('amenity', 'tree'),
                                  napi.Point(1.0, 2.0))
 
-    result = api_impl.format_result(napi.ReverseResults([reverse]), fmt,
-                                    {'icon_base_url': 'foo'})
+    result = v1_format.format_result(napi.ReverseResults([reverse]), fmt,
+                                     {'icon_base_url': 'foo'})
 
     assert 'icon' not in json.loads(result)
-