X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/bd2c64876f7ddc99da14ea78a652f797e17134f4..c70dfccacac90a90bfc193f49262abe7505d7d75:/test/python/api/test_helpers_v1.py diff --git a/test/python/api/test_helpers_v1.py b/test/python/api/test_helpers_v1.py index 45f538de..10f0921b 100644 --- a/test/python/api/test_helpers_v1.py +++ b/test/python/api/test_helpers_v1.py @@ -2,16 +2,21 @@ # # 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 the helper functions for v1 API. """ import pytest -import nominatim.api.v1.helpers as helper +import nominatim_api.v1.helpers as helper -@pytest.mark.parametrize('inp', ['', 'abc', '12 23', 'abc -78.90, 12.456 def']) + +@pytest.mark.parametrize('inp', ['', + 'abc', + '12 23', + 'abc -78.90, 12.456 def', + '40 N 60 W']) def test_extract_coords_no_coords(inp): query, x, y = helper.extract_coords_from_query(inp) @@ -31,40 +36,42 @@ def test_extract_coords_with_text_before(): def test_extract_coords_with_text_after(): assert ('abc', 12.456, -78.90) == helper.extract_coords_from_query('-78.90, 12.456 abc') + @pytest.mark.parametrize('inp', [' [12.456,-78.90] ', ' 12.456,-78.90 ']) def test_extract_coords_with_spaces(inp): assert ('', -78.90, 12.456) == helper.extract_coords_from_query(inp) + @pytest.mark.parametrize('inp', ['40 26.767 N 79 58.933 W', - '40° 26.767′ N 79° 58.933′ W', - "40° 26.767' N 79° 58.933' W", - "40° 26.767'\n" - " N 79° 58.933' W", - 'N 40 26.767, W 79 58.933', - 'N 40°26.767′, W 79°58.933′', - ' N 40°26.767′, W 79°58.933′', - "N 40°26.767', W 79°58.933'", - - '40 26 46 N 79 58 56 W', - '40° 26′ 46″ N 79° 58′ 56″ W', - '40° 26′ 46.00″ N 79° 58′ 56.00″ W', - '40°26′46″N 79°58′56″W', - 'N 40 26 46 W 79 58 56', - 'N 40° 26′ 46″, W 79° 58′ 56″', - 'N 40° 26\' 46", W 79° 58\' 56"', - 'N 40° 26\' 46", W 79° 58\' 56"', - - '40.446 -79.982', - '40.446,-79.982', - '40.446° N 79.982° W', - 'N 40.446° W 79.982°', - - '[40.446 -79.982]', - '[40.446, -79.982]', - ' 40.446 , -79.982 ', - ' 40.446 , -79.982 ', - ' 40.446 , -79.982 ', - ' 40.446 , -79.982 ']) + '40° 26.767′ N 79° 58.933′ W', + "40° 26.767' N 79° 58.933' W", + "40° 26.767'\n" + " N 79° 58.933' W", + 'N 40 26.767, W 79 58.933', + 'N 40°26.767′, W 79°58.933′', + ' N 40°26.767′, W 79°58.933′', + "N 40°26.767', W 79°58.933'", + + '40 26 46 N 79 58 56 W', + '40° 26′ 46″ N 79° 58′ 56″ W', + '40° 26′ 46.00″ N 79° 58′ 56.00″ W', + '40°26′46″N 79°58′56″W', + 'N 40 26 46 W 79 58 56', + 'N 40° 26′ 46″, W 79° 58′ 56″', + 'N 40° 26\' 46", W 79° 58\' 56"', + 'N 40° 26\' 46", W 79° 58\' 56"', + + '40.446 -79.982', + '40.446,-79.982', + '40.446° N 79.982° W', + 'N 40.446° W 79.982°', + + '[40.446 -79.982]', + '[40.446, -79.982]', + ' 40.446 , -79.982 ', + ' 40.446 , -79.982 ', + ' 40.446 , -79.982 ', + ' 40.446 , -79.982 ']) def test_extract_coords_formats(inp): query, x, y = helper.extract_coords_from_query(inp) @@ -104,9 +111,11 @@ def test_extract_category_good(inp): assert cls == 'shop' assert typ == 'fish' + def test_extract_category_only(): assert helper.extract_category_from_query('[shop=market]') == ('', 'shop', 'market') + @pytest.mark.parametrize('inp', ['house []', 'nothing', '[352]']) -def test_extract_category_no_match(inp): +def test_extract_category_no_match(inp): assert helper.extract_category_from_query(inp) == (inp, None, None)