SearchResult as SearchResult,
SearchResults as SearchResults)
from .localization import (Locales as Locales)
+
+from .version import NOMINATIM_API_VERSION as __version__
log().comment(f"No tokenizer named '{name}' available. Database not set up properly.")
raise RuntimeError('Tokenizer not found')
- module = importlib.import_module(f'nominatim_api.api.search.{name}_tokenizer')
+ module = importlib.import_module(f'nominatim_api.search.{name}_tokenizer')
return cast(AbstractQueryAnalyzer, await module.create_query_analyzer(conn))
import sqlalchemy as sa
from .connection import SearchConnection
-from .version import NOMINATIM_API_VERSION
+from .version import NOMINATIM_API_VERSION, parse_version
@dataclasses.dataclass
class StatusResult:
# Database version
try:
- status.database_version = await conn.get_property('database_version')
+ status.database_version = parse_version(await conn.get_property('database_version'))
except ValueError:
pass
Version information for the Nominatim API.
"""
+from nominatim_core.version import NominatimVersion, parse_version
+
NOMINATIM_API_VERSION = '4.4.99'
"""
from pathlib import Path
-PHPLIB_DIR = None
+PHPLIB_DIR = (Path(__file__) / '..' / '..' / '..' / 'lib-php').resolve()
SQLLIB_DIR = (Path(__file__) / '..' / '..' / '..' / 'lib-sql').resolve()
DATA_DIR = (Path(__file__) / '..' / '..' / '..' / 'data').resolve()
CONFIG_DIR = (Path(__file__) / '..' / '..' / '..' / 'settings').resolve()
"""
Version information for the Nominatim core package.
"""
+from typing import NamedTuple, Optional
NOMINATIM_CORE_VERSION = '4.4.99'
+
+class NominatimVersion(NamedTuple):
+ """ Version information for Nominatim. We follow semantic versioning.
+
+ Major, minor and patch_level refer to the last released version.
+ The database patch level tracks important changes between releases
+ and must always be increased when there is a change to the database or code
+ that requires a migration.
+
+ When adding a migration on the development branch, raise the patch level
+ to 99 to make sure that the migration is applied when updating from a
+ patch release to the next minor version. Patch releases usually shouldn't
+ have migrations in them. When they are needed, then make sure that the
+ migration can be reapplied and set the migration version to the appropriate
+ patch level when cherry-picking the commit with the migration.
+ """
+
+ major: int
+ minor: int
+ patch_level: int
+ db_patch_level: Optional[int]
+
+ def __str__(self) -> str:
+ if self.db_patch_level is None:
+ return f"{self.major}.{self.minor}.{self.patch_level}"
+
+ return f"{self.major}.{self.minor}.{self.patch_level}-{self.db_patch_level}"
+
+ def release_version(self) -> str:
+ """ Return the release version in semantic versioning format.
+
+ The release version does not include the database patch version.
+ """
+ return f"{self.major}.{self.minor}.{self.patch_level}"
+
+
+def parse_version(version: str) -> NominatimVersion:
+ """ Parse a version string into a version consisting of a tuple of
+ four ints: major, minor, patch level, database patch level
+
+ This is the reverse operation of `version_str()`.
+ """
+ parts = version.split('.')
+ return NominatimVersion(*[int(x) for x in parts[:2] + parts[2].split('-')])
else:
port = 8088
- server_module = importlib.import_module(f'nominatim_db.server.{args.engine}.server')
+ server_module = importlib.import_module(f'nominatim_api.server.{args.engine}.server')
app = server_module.get_application(args.project_dir)
uvicorn.run(app, host=host, port=port)
"""
Subcommand definitions for API calls from the command line.
"""
-from typing import Dict, Any
+from typing import Dict, Any, Optional
import argparse
import logging
import json
"""
Version information for Nominatim.
"""
-from typing import Optional, NamedTuple
+from typing import Optional
-class NominatimVersion(NamedTuple):
- """ Version information for Nominatim. We follow semantic versioning.
-
- Major, minor and patch_level refer to the last released version.
- The database patch level tracks important changes between releases
- and must always be increased when there is a change to the database or code
- that requires a migration.
-
- When adding a migration on the development branch, raise the patch level
- to 99 to make sure that the migration is applied when updating from a
- patch release to the next minor version. Patch releases usually shouldn't
- have migrations in them. When they are needed, then make sure that the
- migration can be reapplied and set the migration version to the appropriate
- patch level when cherry-picking the commit with the migration.
- """
-
- major: int
- minor: int
- patch_level: int
- db_patch_level: int
-
- def __str__(self) -> str:
- return f"{self.major}.{self.minor}.{self.patch_level}-{self.db_patch_level}"
-
- def release_version(self) -> str:
- """ Return the release version in semantic versioning format.
-
- The release version does not include the database patch version.
- """
- return f"{self.major}.{self.minor}.{self.patch_level}"
+from nominatim_core.version import NominatimVersion, parse_version
NOMINATIM_VERSION = NominatimVersion(4, 4, 99, 1)
# cmake/tool-installed.tmpl is used to build the binary 'nominatim'. Inside
# there is a call to set the variable value below.
GIT_COMMIT_HASH : Optional[str] = None
-
-
-def parse_version(version: str) -> NominatimVersion:
- """ Parse a version string into a version consisting of a tuple of
- four ints: major, minor, patch level, database patch level
-
- This is the reverse operation of `version_str()`.
- """
- parts = version.split('.')
- return NominatimVersion(*[int(x) for x in parts[:2] + parts[2].split('-')])
-# 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) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Helper fixtures for API call tests.
import sqlalchemy as sa
-import nominatim.api as napi
-from nominatim.db.sql_preprocessor import SQLPreprocessor
-from nominatim.api.search.query_analyzer_factory import make_query_analyzer
-from nominatim.tools import convert_sqlite
-import nominatim.api.logging as loglib
+import nominatim_api as napi
+from nominatim_core.db.sql_preprocessor import SQLPreprocessor
+from nominatim_api.search.query_analyzer_factory import make_query_analyzer
+from nominatim_db.tools import convert_sqlite
+import nominatim_api.logging as loglib
class APITester:
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Provides dummy implementations of ASGIAdaptor for testing.
"""
from collections import namedtuple
-import nominatim.api.v1.server_glue as glue
-from nominatim.config import Configuration
+import nominatim_api.v1.server_glue as glue
+from nominatim_core.config import Configuration
class FakeError(BaseException):
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for tokenized query data structures.
"""
import pytest
-from nominatim.api.search import query
+from nominatim_api.search import query
class MyToken(query.Token):
"""
import pytest
-from nominatim.api.search.query import Token, TokenRange, BreakType, PhraseType, TokenType, QueryStruct, Phrase
-from nominatim.api.search.db_search_builder import SearchBuilder
-from nominatim.api.search.token_assignment import TokenAssignment
-from nominatim.api.types import SearchDetails
-import nominatim.api.search.db_searches as dbs
+from nominatim_api.search.query import Token, TokenRange, BreakType, PhraseType, TokenType, QueryStruct, Phrase
+from nominatim_api.search.db_search_builder import SearchBuilder
+from nominatim_api.search.token_assignment import TokenAssignment
+from nominatim_api.types import SearchDetails
+import nominatim_api.search.db_searches as dbs
class MyToken(Token):
def get_category(self):
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for query analyzer for ICU tokenizer.
import pytest
import pytest_asyncio
-from nominatim.api import NominatimAPIAsync
-from nominatim.api.search.query import Phrase, PhraseType, TokenType, BreakType
-import nominatim.api.search.icu_tokenizer as tok
-from nominatim.api.logging import set_log_output, get_and_disable
+from nominatim_api import NominatimAPIAsync
+from nominatim_api.search.query import Phrase, PhraseType, TokenType, BreakType
+import nominatim_api.search.icu_tokenizer as tok
+from nominatim_api.logging import set_log_output, get_and_disable
async def add_word(conn, word_id, word_token, wtype, word, info = None):
t = conn.t.meta.tables['word']
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for query analyzer for legacy tokenizer.
import pytest
import pytest_asyncio
-from nominatim.api import NominatimAPIAsync
-from nominatim.api.search.query import Phrase, PhraseType, TokenType, BreakType
-import nominatim.api.search.legacy_tokenizer as tok
-from nominatim.api.logging import set_log_output, get_and_disable
+from nominatim_api import NominatimAPIAsync
+from nominatim_api.search.query import Phrase, PhraseType, TokenType, BreakType
+import nominatim_api.search.legacy_tokenizer as tok
+from nominatim_api.logging import set_log_output, get_and_disable
async def add_word(conn, word_id, word_token, word, count):
-
# 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) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Test data types for search queries.
"""
import pytest
-import nominatim.api.search.query as nq
+import nominatim_api.search.query as nq
def test_token_range_equal():
assert nq.TokenRange(2, 3) == nq.TokenRange(2, 3)
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for query analyzer creation.
import pytest
-from nominatim.api import NominatimAPIAsync
-from nominatim.api.search.query_analyzer_factory import make_query_analyzer
-from nominatim.api.search.icu_tokenizer import ICUQueryAnalyzer
+from nominatim_api import NominatimAPIAsync
+from nominatim_api.search.query_analyzer_factory import make_query_analyzer
+from nominatim_api.search.icu_tokenizer import ICUQueryAnalyzer
@pytest.mark.asyncio
async def test_import_icu_tokenizer(table_factory):
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for running the country searcher.
"""
import pytest
-import nominatim.api as napi
-from nominatim.api.types import SearchDetails
-from nominatim.api.search.db_searches import CountrySearch
-from nominatim.api.search.db_search_fields import WeightedStrings
+import nominatim_api as napi
+from nominatim_api.types import SearchDetails
+from nominatim_api.search.db_searches import CountrySearch
+from nominatim_api.search.db_search_fields import WeightedStrings
def run_search(apiobj, frontend, global_penalty, ccodes,
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for running the near searcher.
"""
import pytest
-import nominatim.api as napi
-from nominatim.api.types import SearchDetails
-from nominatim.api.search.db_searches import NearSearch, PlaceSearch
-from nominatim.api.search.db_search_fields import WeightedStrings, WeightedCategories,\
+import nominatim_api as napi
+from nominatim_api.types import SearchDetails
+from nominatim_api.search.db_searches import NearSearch, PlaceSearch
+from nominatim_api.search.db_search_fields import WeightedStrings, WeightedCategories,\
FieldLookup, FieldRanking, RankedTokens
-from nominatim.api.search.db_search_lookups import LookupAll
+from nominatim_api.search.db_search_lookups import LookupAll
def run_search(apiobj, frontend, global_penalty, cat, cat_penalty=None, ccodes=[],
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for running the generic place searcher.
import pytest
-import nominatim.api as napi
-from nominatim.api.types import SearchDetails
-from nominatim.api.search.db_searches import PlaceSearch
-from nominatim.api.search.db_search_fields import WeightedStrings, WeightedCategories,\
+import nominatim_api as napi
+from nominatim_api.types import SearchDetails
+from nominatim_api.search.db_searches import PlaceSearch
+from nominatim_api.search.db_search_fields import WeightedStrings, WeightedCategories,\
FieldLookup, FieldRanking, RankedTokens
-from nominatim.api.search.db_search_lookups import LookupAll, LookupAny, Restrict
+from nominatim_api.search.db_search_lookups import LookupAll, LookupAny, Restrict
APIOPTIONS = ['search']
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for running the POI searcher.
"""
import pytest
-import nominatim.api as napi
-from nominatim.api.types import SearchDetails
-from nominatim.api.search.db_searches import PoiSearch
-from nominatim.api.search.db_search_fields import WeightedStrings, WeightedCategories
+import nominatim_api as napi
+from nominatim_api.types import SearchDetails
+from nominatim_api.search.db_searches import PoiSearch
+from nominatim_api.search.db_search_fields import WeightedStrings, WeightedCategories
def run_search(apiobj, frontend, global_penalty, poitypes, poi_penalties=None,
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for running the postcode searcher.
"""
import pytest
-import nominatim.api as napi
-from nominatim.api.types import SearchDetails
-from nominatim.api.search.db_searches import PostcodeSearch
-from nominatim.api.search.db_search_fields import WeightedStrings, FieldLookup, \
+import nominatim_api as napi
+from nominatim_api.types import SearchDetails
+from nominatim_api.search.db_searches import PostcodeSearch
+from nominatim_api.search.db_search_fields import WeightedStrings, FieldLookup, \
FieldRanking, RankedTokens
def run_search(apiobj, frontend, global_penalty, pcs, pc_penalties=None,
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Test for creation of token assignments from tokenized queries.
"""
import pytest
-from nominatim.api.search.query import QueryStruct, Phrase, PhraseType, BreakType, TokenType, TokenRange, Token
-from nominatim.api.search.token_assignment import yield_token_assignments, TokenAssignment, PENALTY_TOKENCHANGE
+from nominatim_api.search.query import QueryStruct, Phrase, PhraseType, BreakType, TokenType, TokenRange, Token
+from nominatim_api.search.token_assignment import yield_token_assignments, TokenAssignment, PENALTY_TOKENCHANGE
class MyToken(Token):
def get_category(self):
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for enhanced connection class for API functions.
import sqlalchemy as sa
-from nominatim.api import NominatimAPIAsync
+from nominatim_api import NominatimAPIAsync
@pytest_asyncio.fixture
async def apiobj(temp_db):
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for the deletable v1 API call.
from fake_adaptor import FakeAdaptor, FakeError, FakeResponse
-import nominatim.api.v1.server_glue as glue
-import nominatim.api as napi
+import nominatim_api.v1.server_glue as glue
+import nominatim_api as napi
@pytest_asyncio.fixture
async def api():
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for details API call.
import pytest
-import nominatim.api as napi
+import nominatim_api as napi
@pytest.mark.parametrize('idobj', (napi.PlaceID(332), napi.OsmID('W', 4),
napi.OsmID('W', 4, 'highway')))
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for lookup API call.
import pytest
-import nominatim.api as napi
+import nominatim_api as napi
def test_lookup_empty_list(apiobj, frontend):
api = frontend(apiobj, options={'details'})
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for the deletable v1 API call.
from fake_adaptor import FakeAdaptor, FakeError, FakeResponse
-import nominatim.api.v1.server_glue as glue
-import nominatim.api as napi
+import nominatim_api.v1.server_glue as glue
+import nominatim_api as napi
@pytest_asyncio.fixture
async def api():
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for reverse API call.
import pytest
-import nominatim.api as napi
+import nominatim_api as napi
API_OPTIONS = {'reverse'}
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for search API calls.
import sqlalchemy as sa
-import nominatim.api as napi
-import nominatim.api.logging as loglib
+import nominatim_api as napi
+import nominatim_api.logging as loglib
API_OPTIONS = {'search'}
-# 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) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for the status API call.
import datetime as dt
import pytest
-from nominatim.version import NOMINATIM_VERSION, NominatimVersion
-import nominatim.api as napi
+from nominatim_db.version import NominatimVersion
+from nominatim_api.version import NOMINATIM_API_VERSION
+import nominatim_api as napi
def test_status_no_extra_info(apiobj, frontend):
api = frontend(apiobj)
assert result.status == 0
assert result.message == 'OK'
- assert result.software_version == NOMINATIM_VERSION
+ assert result.software_version == NOMINATIM_API_VERSION
assert result.database_version is None
assert result.data_updated is None
assert result.status == 0
assert result.message == 'OK'
- assert result.software_version == NOMINATIM_VERSION
+ assert result.software_version == NOMINATIM_API_VERSION
assert result.database_version == NominatimVersion(99, 5, 4, 2)
assert result.data_updated == import_date
assert result.status == 700
assert result.message == 'Database connection failed'
- assert result.software_version == NOMINATIM_VERSION
+ assert result.software_version == NOMINATIM_API_VERSION
assert result.database_version is None
assert result.data_updated is None
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for loading of parameter dataclasses.
"""
import pytest
-from nominatim.errors import UsageError
-import nominatim.api.types as typ
+from nominatim_core.errors import UsageError
+import nominatim_api.types as typ
def test_no_params_defaults():
params = typ.LookupDetails.from_kwargs({})
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for export CLI function.
"""
import pytest
-import nominatim.cli
+import nominatim_db.cli
@pytest.fixture
def run_export(tmp_path, capsys):
def _exec(args):
- assert 0 == nominatim.cli.nominatim(module_dir='MODULE NOT AVAILABLE',
- osm2pgsql_path='OSM2PGSQL NOT AVAILABLE',
- cli_args=['export', '--project-dir', str(tmp_path)]
- + args)
+ assert 0 == nominatim_db.cli.nominatim(module_dir='MODULE NOT AVAILABLE',
+ osm2pgsql_path='OSM2PGSQL NOT AVAILABLE',
+ cli_args=['export', '--project-dir', str(tmp_path)]
+ + args)
return capsys.readouterr().out.split('\r\n')
return _exec
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 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',
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Test functions for adapting results to the user's locale.
"""
import pytest
-from nominatim.api import Locales
+from nominatim_api import Locales
def test_display_name_empty_names():
l = Locales(['en', 'de'])
-# 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) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for formatting results for the V1 API.
import pytest
-import nominatim.api.v1 as api_impl
-import nominatim.api as napi
-from nominatim.version import NOMINATIM_VERSION
+import nominatim_api.v1 as api_impl
+import nominatim_api as napi
STATUS_FORMATS = {'text', 'json'}
result = api_impl.format_result(status, 'json', {})
- assert result == '{"status":700,"message":"Bad format.","software_version":"%s"}' % (NOMINATIM_VERSION, )
+ assert result == \
+ f'{{"status":700,"message":"Bad format.","software_version":"{napi.__version__}"}}'
def test_status_format_json_full():
result = api_impl.format_result(status, 'json', {})
- assert result == '{"status":0,"message":"OK","data_updated":"2010-02-07T20:20:03+00:00","software_version":"%s","database_version":"5.6"}' % (NOMINATIM_VERSION, )
+ assert result == \
+ f'{{"status":0,"message":"OK","data_updated":"2010-02-07T20:20:03+00:00","software_version":"{napi.__version__}","database_version":"5.6"}}'
# DetailedResult
-# 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) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for formatting reverse results for the V1 API.
import pytest
-import nominatim.api.v1 as api_impl
-import nominatim.api as napi
+import nominatim_api.v1 as api_impl
+import nominatim_api as napi
FORMATS = ['json', 'jsonv2', 'geojson', 'geocodejson', 'xml']
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for result datatype helper functions.
import sqlalchemy as sa
-from nominatim.api import SourceTable, DetailedResult, Point
-import nominatim.api.results as nresults
+from nominatim_api import SourceTable, DetailedResult, Point
+import nominatim_api.results as nresults
def mkpoint(x, y):
return hexlify(struct.pack("=biidd", 1, 0x20000001, 4326, x, y)).decode('utf-8')
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for the Python web frameworks adaptor, v1 API.
from fake_adaptor import FakeAdaptor, FakeError, FakeResponse
-import nominatim.api.v1.server_glue as glue
-import nominatim.api as napi
-import nominatim.api.logging as loglib
+import nominatim_api.v1.server_glue as glue
+import nominatim_api as napi
+import nominatim_api.logging as loglib
# ASGIAdaptor.get_int/bool()
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for warm-up CLI function.
"""
import pytest
-import nominatim.cli
+import nominatim_db.cli
@pytest.fixture(autouse=True)
def setup_database_with_context(apiobj, table_factory):
@pytest.mark.parametrize('args', [['--search-only'], ['--reverse-only']])
def test_warm_all(tmp_path, args):
- assert 0 == nominatim.cli.nominatim(module_dir='MODULE NOT AVAILABLE',
- osm2pgsql_path='OSM2PGSQL NOT AVAILABLE',
- cli_args=['admin', '--project-dir', str(tmp_path),
- '--warm'] + args)
+ assert 0 == nominatim_db.cli.nominatim(module_dir='MODULE NOT AVAILABLE',
+ osm2pgsql_path='OSM2PGSQL NOT AVAILABLE',
+ cli_args=['admin', '--project-dir', str(tmp_path),
+ '--warm'] + args)
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
import pytest
-import nominatim.cli
+import nominatim_db.cli
class MockParamCapture:
""" Mock that records the parameters with which a function was called
Returns a function that can be called with the desired CLI arguments.
"""
def _call_nominatim(*args):
- return nominatim.cli.nominatim(module_dir='MODULE NOT AVAILABLE',
- osm2pgsql_path='OSM2PGSQL NOT AVAILABLE',
- cli_args=args)
+ return nominatim_db.cli.nominatim(module_dir='MODULE NOT AVAILABLE',
+ osm2pgsql_path='OSM2PGSQL NOT AVAILABLE',
+ cli_args=args)
return _call_nominatim
@pytest.fixture
def cli_tokenizer_mock(monkeypatch):
tok = DummyTokenizer()
- monkeypatch.setattr(nominatim.tokenizer.factory, 'get_tokenizer_for_db',
+ monkeypatch.setattr(nominatim_db.tokenizer.factory, 'get_tokenizer_for_db',
lambda *args: tok)
- monkeypatch.setattr(nominatim.tokenizer.factory, 'create_tokenizer',
+ monkeypatch.setattr(nominatim_db.tokenizer.factory, 'create_tokenizer',
lambda *args: tok)
return tok
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for command line interface wrapper.
import importlib
import pytest
-import nominatim.indexer.indexer
-import nominatim.tools.add_osm_data
-import nominatim.tools.freeze
+import nominatim_db.indexer.indexer
+import nominatim_db.tools.add_osm_data
+import nominatim_db.tools.freeze
def test_cli_help(cli_call, capsys):
@pytest.mark.parametrize("name,oid", [('file', 'foo.osm'), ('diff', 'foo.osc')])
def test_cli_add_data_file_command(cli_call, mock_func_factory, name, oid):
- mock_run_legacy = mock_func_factory(nominatim.tools.add_osm_data, 'add_data_from_file')
+ mock_run_legacy = mock_func_factory(nominatim_db.tools.add_osm_data, 'add_data_from_file')
assert cli_call('add-data', '--' + name, str(oid)) == 0
assert mock_run_legacy.called == 1
@pytest.mark.parametrize("name,oid", [('node', 12), ('way', 8), ('relation', 32)])
def test_cli_add_data_object_command(cli_call, mock_func_factory, name, oid):
- mock_run_legacy = mock_func_factory(nominatim.tools.add_osm_data, 'add_osm_object')
+ mock_run_legacy = mock_func_factory(nominatim_db.tools.add_osm_data, 'add_osm_object')
assert cli_call('add-data', '--' + name, str(oid)) == 0
assert mock_run_legacy.called == 1
def test_cli_add_data_tiger_data(cli_call, cli_tokenizer_mock, mock_func_factory):
- mock = mock_func_factory(nominatim.tools.tiger_data, 'add_tiger_data')
+ mock = mock_func_factory(nominatim_db.tools.tiger_data, 'add_tiger_data')
assert cli_call('add-data', '--tiger-data', 'somewhere') == 0
def test_cli_serve_php(cli_call, mock_func_factory):
- func = mock_func_factory(nominatim.cli, 'run_php_server')
+ func = mock_func_factory(nominatim_db.cli, 'run_php_server')
cli_call('serve', '--engine', 'php') == 0
def test_freeze_command(self, mock_func_factory):
- mock_drop = mock_func_factory(nominatim.tools.freeze, 'drop_update_tables')
- mock_flatnode = mock_func_factory(nominatim.tools.freeze, 'drop_flatnode_file')
+ mock_drop = mock_func_factory(nominatim_db.tools.freeze, 'drop_update_tables')
+ mock_flatnode = mock_func_factory(nominatim_db.tools.freeze, 'drop_flatnode_file')
assert self.call_nominatim('freeze') == 0
def test_index_command(self, mock_func_factory, table_factory,
params, do_bnds, do_ranks):
table_factory('import_status', 'indexed bool')
- bnd_mock = mock_func_factory(nominatim.indexer.indexer.Indexer, 'index_boundaries')
- rank_mock = mock_func_factory(nominatim.indexer.indexer.Indexer, 'index_by_rank')
- postcode_mock = mock_func_factory(nominatim.indexer.indexer.Indexer, 'index_postcodes')
+ bnd_mock = mock_func_factory(nominatim_db.indexer.indexer.Indexer, 'index_boundaries')
+ rank_mock = mock_func_factory(nominatim_db.indexer.indexer.Indexer, 'index_by_rank')
+ postcode_mock = mock_func_factory(nominatim_db.indexer.indexer.Indexer, 'index_postcodes')
assert self.call_nominatim('index', *params) == 0
def test_special_phrases_wiki_command(self, mock_func_factory):
- func = mock_func_factory(nominatim.clicmd.special_phrases.SPImporter, 'import_phrases')
+ func = mock_func_factory(nominatim_db.clicmd.special_phrases.SPImporter, 'import_phrases')
self.call_nominatim('special-phrases', '--import-from-wiki', '--no-replace')
def test_special_phrases_csv_command(self, src_dir, mock_func_factory):
- func = mock_func_factory(nominatim.clicmd.special_phrases.SPImporter, 'import_phrases')
+ func = mock_func_factory(nominatim_db.clicmd.special_phrases.SPImporter, 'import_phrases')
testdata = src_dir / 'test' / 'testdb'
csv_path = str((testdata / 'full_en_phrases_test.csv').resolve())
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Test for the command line interface wrapper admin subcommand.
"""
import pytest
-import nominatim.tools.admin
-import nominatim.tools.check_database
-import nominatim.tools.migration
-import nominatim.clicmd.admin
+import nominatim_db.tools.admin
+import nominatim_db.tools.check_database
+import nominatim_db.tools.migration
+import nominatim_db.clicmd.admin
def test_admin_command_check_database(cli_call, mock_func_factory):
- mock = mock_func_factory(nominatim.tools.check_database, 'check_database')
+ mock = mock_func_factory(nominatim_db.tools.check_database, 'check_database')
assert cli_call('admin', '--check-database') == 0
assert mock.called == 1
def test_admin_migrate(cli_call, mock_func_factory):
- mock = mock_func_factory(nominatim.tools.migration, 'migrate')
+ mock = mock_func_factory(nominatim_db.tools.migration, 'migrate')
assert cli_call('admin', '--migrate') == 0
assert mock.called == 1
def test_admin_clean_deleted_relations(cli_call, mock_func_factory):
- mock = mock_func_factory(nominatim.tools.admin, 'clean_deleted_relations')
+ mock = mock_func_factory(nominatim_db.tools.admin, 'clean_deleted_relations')
assert cli_call('admin', '--clean-deleted', '1 month') == 0
assert mock.called == 1
def test_admin_clean_deleted_relations_no_age(cli_call, mock_func_factory):
- mock = mock_func_factory(nominatim.tools.admin, 'clean_deleted_relations')
+ mock = mock_func_factory(nominatim_db.tools.admin, 'clean_deleted_relations')
assert cli_call('admin', '--clean-deleted') == 1
@pytest.mark.parametrize("func, params", [('analyse_indexing', ('--analyse-indexing', ))])
def test_analyse_indexing(self, mock_func_factory, func, params):
- mock = mock_func_factory(nominatim.tools.admin, func)
+ mock = mock_func_factory(nominatim_db.tools.admin, func)
assert self.call_nominatim('admin', *params) == 0
assert mock.called == 1
-# 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) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for API access commands of command-line interface wrapper.
import json
import pytest
-import nominatim.clicmd.api
-import nominatim.api as napi
+import nominatim_db.clicmd.api
+import nominatim_api as napi
class TestCliStatusCall:
-# SPDX-License-Identifier: GPL-2.0-only
+# SPDX-License-Identifier: GPL-2.0-or-later
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for import command of the command-line interface wrapper.
"""
import pytest
-import nominatim.tools.database_import
-import nominatim.data.country_info
-import nominatim.tools.refresh
-import nominatim.tools.postcodes
-import nominatim.indexer.indexer
-import nominatim.db.properties
+import nominatim_db.tools.database_import
+import nominatim_db.data.country_info
+import nominatim_db.tools.refresh
+import nominatim_db.tools.postcodes
+import nominatim_db.indexer.indexer
+import nominatim_core.db.properties
class TestCliImportWithDb:
@pytest.mark.parametrize('with_updates', [True, False])
def test_import_full(self, mock_func_factory, with_updates, place_table, property_table):
mocks = [
- mock_func_factory(nominatim.tools.database_import, 'setup_database_skeleton'),
- mock_func_factory(nominatim.data.country_info, 'setup_country_tables'),
- mock_func_factory(nominatim.tools.database_import, 'import_osm_data'),
- mock_func_factory(nominatim.tools.refresh, 'import_wikipedia_articles'),
- mock_func_factory(nominatim.tools.refresh, 'import_secondary_importance'),
- mock_func_factory(nominatim.tools.database_import, 'truncate_data_tables'),
- mock_func_factory(nominatim.tools.database_import, 'load_data'),
- mock_func_factory(nominatim.tools.database_import, 'create_tables'),
- mock_func_factory(nominatim.tools.database_import, 'create_table_triggers'),
- mock_func_factory(nominatim.tools.database_import, 'create_partition_tables'),
- mock_func_factory(nominatim.tools.database_import, 'create_search_indices'),
- mock_func_factory(nominatim.data.country_info, 'create_country_names'),
- mock_func_factory(nominatim.tools.refresh, 'load_address_levels_from_config'),
- mock_func_factory(nominatim.tools.postcodes, 'update_postcodes'),
- mock_func_factory(nominatim.indexer.indexer.Indexer, 'index_full'),
- mock_func_factory(nominatim.tools.refresh, 'setup_website'),
+ mock_func_factory(nominatim_db.tools.database_import, 'setup_database_skeleton'),
+ mock_func_factory(nominatim_db.data.country_info, 'setup_country_tables'),
+ mock_func_factory(nominatim_db.tools.database_import, 'import_osm_data'),
+ mock_func_factory(nominatim_db.tools.refresh, 'import_wikipedia_articles'),
+ mock_func_factory(nominatim_db.tools.refresh, 'import_secondary_importance'),
+ mock_func_factory(nominatim_db.tools.database_import, 'truncate_data_tables'),
+ mock_func_factory(nominatim_db.tools.database_import, 'load_data'),
+ mock_func_factory(nominatim_db.tools.database_import, 'create_tables'),
+ mock_func_factory(nominatim_db.tools.database_import, 'create_table_triggers'),
+ mock_func_factory(nominatim_db.tools.database_import, 'create_partition_tables'),
+ mock_func_factory(nominatim_db.tools.database_import, 'create_search_indices'),
+ mock_func_factory(nominatim_db.data.country_info, 'create_country_names'),
+ mock_func_factory(nominatim_db.tools.refresh, 'load_address_levels_from_config'),
+ mock_func_factory(nominatim_db.tools.postcodes, 'update_postcodes'),
+ mock_func_factory(nominatim_db.indexer.indexer.Indexer, 'index_full'),
+ mock_func_factory(nominatim_db.tools.refresh, 'setup_website'),
]
params = ['import', '--osm-file', __file__]
if with_updates:
- mocks.append(mock_func_factory(nominatim.tools.freeze, 'drop_update_tables'))
+ mocks.append(mock_func_factory(nominatim_db.tools.freeze, 'drop_update_tables'))
params.append('--no-updates')
- cf_mock = mock_func_factory(nominatim.tools.refresh, 'create_functions')
+ cf_mock = mock_func_factory(nominatim_db.tools.refresh, 'create_functions')
assert self.call_nominatim(*params) == 0
def test_import_continue_load_data(self, mock_func_factory):
mocks = [
- mock_func_factory(nominatim.tools.database_import, 'truncate_data_tables'),
- mock_func_factory(nominatim.tools.database_import, 'load_data'),
- mock_func_factory(nominatim.tools.database_import, 'create_search_indices'),
- mock_func_factory(nominatim.data.country_info, 'create_country_names'),
- mock_func_factory(nominatim.tools.postcodes, 'update_postcodes'),
- mock_func_factory(nominatim.indexer.indexer.Indexer, 'index_full'),
- mock_func_factory(nominatim.tools.refresh, 'setup_website'),
- mock_func_factory(nominatim.db.properties, 'set_property')
+ mock_func_factory(nominatim_db.tools.database_import, 'truncate_data_tables'),
+ mock_func_factory(nominatim_db.tools.database_import, 'load_data'),
+ mock_func_factory(nominatim_db.tools.database_import, 'create_search_indices'),
+ mock_func_factory(nominatim_db.data.country_info, 'create_country_names'),
+ mock_func_factory(nominatim_db.tools.postcodes, 'update_postcodes'),
+ mock_func_factory(nominatim_db.indexer.indexer.Indexer, 'index_full'),
+ mock_func_factory(nominatim_db.tools.refresh, 'setup_website'),
+ mock_func_factory(nominatim_core.db.properties, 'set_property')
]
assert self.call_nominatim('import', '--continue', 'load-data') == 0
def test_import_continue_indexing(self, mock_func_factory, placex_table,
temp_db_conn):
mocks = [
- mock_func_factory(nominatim.tools.database_import, 'create_search_indices'),
- mock_func_factory(nominatim.data.country_info, 'create_country_names'),
- mock_func_factory(nominatim.indexer.indexer.Indexer, 'index_full'),
- mock_func_factory(nominatim.tools.refresh, 'setup_website'),
- mock_func_factory(nominatim.db.properties, 'set_property')
+ mock_func_factory(nominatim_db.tools.database_import, 'create_search_indices'),
+ mock_func_factory(nominatim_db.data.country_info, 'create_country_names'),
+ mock_func_factory(nominatim_db.indexer.indexer.Indexer, 'index_full'),
+ mock_func_factory(nominatim_db.tools.refresh, 'setup_website'),
+ mock_func_factory(nominatim_core.db.properties, 'set_property')
]
assert self.call_nominatim('import', '--continue', 'indexing') == 0
def test_import_continue_postprocess(self, mock_func_factory):
mocks = [
- mock_func_factory(nominatim.tools.database_import, 'create_search_indices'),
- mock_func_factory(nominatim.data.country_info, 'create_country_names'),
- mock_func_factory(nominatim.tools.refresh, 'setup_website'),
- mock_func_factory(nominatim.db.properties, 'set_property')
+ mock_func_factory(nominatim_db.tools.database_import, 'create_search_indices'),
+ mock_func_factory(nominatim_db.data.country_info, 'create_country_names'),
+ mock_func_factory(nominatim_db.tools.refresh, 'setup_website'),
+ mock_func_factory(nominatim_core.db.properties, 'set_property')
]
assert self.call_nominatim('import', '--continue', 'db-postprocess') == 0
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for command line interface wrapper for refresk command.
"""
import pytest
-import nominatim.tools.refresh
-import nominatim.tools.postcodes
-import nominatim.indexer.indexer
+import nominatim_db.tools.refresh
+import nominatim_db.tools.postcodes
+import nominatim_db.indexer.indexer
class TestRefresh:
('website', 'setup_website'),
])
def test_refresh_command(self, mock_func_factory, command, func):
- mock_func_factory(nominatim.tools.refresh, 'create_functions')
- func_mock = mock_func_factory(nominatim.tools.refresh, func)
+ mock_func_factory(nominatim_db.tools.refresh, 'create_functions')
+ func_mock = mock_func_factory(nominatim_db.tools.refresh, func)
assert self.call_nominatim('refresh', '--' + command) == 0
assert func_mock.called == 1
def test_refresh_postcodes(self, mock_func_factory, place_table):
- func_mock = mock_func_factory(nominatim.tools.postcodes, 'update_postcodes')
- idx_mock = mock_func_factory(nominatim.indexer.indexer.Indexer, 'index_postcodes')
+ func_mock = mock_func_factory(nominatim_db.tools.postcodes, 'update_postcodes')
+ idx_mock = mock_func_factory(nominatim_db.indexer.indexer.Indexer, 'index_postcodes')
assert self.call_nominatim('refresh', '--postcodes') == 0
assert func_mock.called == 1
def test_refresh_create_functions(self, mock_func_factory):
- func_mock = mock_func_factory(nominatim.tools.refresh, 'create_functions')
+ func_mock = mock_func_factory(nominatim_db.tools.refresh, 'create_functions')
assert self.call_nominatim('refresh', '--functions') == 0
assert func_mock.called == 1
def test_refresh_secondary_importance_new_table(self, mock_func_factory):
- mocks = [mock_func_factory(nominatim.tools.refresh, 'import_secondary_importance'),
- mock_func_factory(nominatim.tools.refresh, 'create_functions')]
+ mocks = [mock_func_factory(nominatim_db.tools.refresh, 'import_secondary_importance'),
+ mock_func_factory(nominatim_db.tools.refresh, 'create_functions')]
assert self.call_nominatim('refresh', '--secondary-importance') == 0
assert mocks[0].called == 1
def test_refresh_importance_computed_after_wiki_import(self, monkeypatch, mock_func_factory):
calls = []
- monkeypatch.setattr(nominatim.tools.refresh, 'import_wikipedia_articles',
+ monkeypatch.setattr(nominatim_db.tools.refresh, 'import_wikipedia_articles',
lambda *args, **kwargs: calls.append('import') or 0)
- monkeypatch.setattr(nominatim.tools.refresh, 'recompute_importance',
+ monkeypatch.setattr(nominatim_db.tools.refresh, 'recompute_importance',
lambda *args, **kwargs: calls.append('update'))
func_mock = mock_func_factory(nominatim.tools.refresh, 'create_functions')
('--data-area', 'r7723', '--data-area', 'r2'),
('--data-area', 'R9284425', '--data-object', 'n1234567894567')])
def test_refresh_objects(self, params, mock_func_factory):
- func_mock = mock_func_factory(nominatim.tools.refresh, 'invalidate_osm_object')
+ func_mock = mock_func_factory(nominatim_db.tools.refresh, 'invalidate_osm_object')
assert self.call_nominatim('refresh', *params) == 0
@pytest.mark.parametrize('func', ('--data-object', '--data-area'))
@pytest.mark.parametrize('param', ('234', 'a55', 'R 453', 'Rel'))
def test_refresh_objects_bad_param(self, func, param, mock_func_factory):
- func_mock = mock_func_factory(nominatim.tools.refresh, 'invalidate_osm_object')
+ func_mock = mock_func_factory(nominatim_db.tools.refresh, 'invalidate_osm_object')
self.call_nominatim('refresh', func, param) == 1
assert func_mock.called == 0
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2023 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for replication command of command-line interface wrapper.
import pytest
-import nominatim.cli
-import nominatim.indexer.indexer
-import nominatim.tools.replication
-import nominatim.tools.refresh
-from nominatim.db import status
+import nominatim_db.cli
+import nominatim_db.indexer.indexer
+import nominatim_db.tools.replication
+import nominatim_db.tools.refresh
+from nominatim_core.db import status
@pytest.fixture
def tokenizer_mock(monkeypatch):
self.finalize_import_called = True
tok = DummyTokenizer()
- monkeypatch.setattr(nominatim.tokenizer.factory, 'get_tokenizer_for_db',
+ monkeypatch.setattr(nominatim_db.tokenizer.factory, 'get_tokenizer_for_db',
lambda *args: tok)
- monkeypatch.setattr(nominatim.tokenizer.factory, 'create_tokenizer',
+ monkeypatch.setattr(nominatim_db.tokenizer.factory, 'create_tokenizer',
lambda *args: tok)
return tok
@pytest.fixture
def index_mock(mock_func_factory, tokenizer_mock, init_status):
- return mock_func_factory(nominatim.indexer.indexer.Indexer, 'index_full')
+ return mock_func_factory(nominatim_db.indexer.indexer.Indexer, 'index_full')
@pytest.fixture
def update_mock(mock_func_factory, init_status, tokenizer_mock):
- return mock_func_factory(nominatim.tools.replication, 'update')
+ return mock_func_factory(nominatim_db.tools.replication, 'update')
class TestCliReplication:
@pytest.fixture(autouse=True)
def setup_update_function(self, monkeypatch):
def _mock_updates(states):
- monkeypatch.setattr(nominatim.tools.replication, 'update',
+ monkeypatch.setattr(nominatim_db.tools.replication, 'update',
lambda *args, **kwargs: states.pop())
self.update_states = _mock_updates
(('--check-for-updates',), 'check_for_updates')
])
def test_replication_command(self, mock_func_factory, params, func):
- func_mock = mock_func_factory(nominatim.tools.replication, func)
+ func_mock = mock_func_factory(nominatim_db.tools.replication, func)
if params == ('--init',):
- umock = mock_func_factory(nominatim.tools.refresh, 'create_functions')
+ umock = mock_func_factory(nominatim_db.tools.refresh, 'create_functions')
assert self.call_nominatim(*params) == 0
assert func_mock.called == 1
@pytest.mark.parametrize("update_interval", [60, 3600])
def test_replication_catchup(self, placex_table, monkeypatch, index_mock, update_interval):
monkeypatch.setenv('NOMINATIM_REPLICATION_UPDATE_INTERVAL', str(update_interval))
- self.update_states([nominatim.tools.replication.UpdateState.NO_CHANGES])
+ self.update_states([nominatim_db.tools.replication.UpdateState.NO_CHANGES])
assert self.call_nominatim('--catch-up') == 0
def test_replication_update_continuous(self, index_mock):
- self.update_states([nominatim.tools.replication.UpdateState.UP_TO_DATE,
- nominatim.tools.replication.UpdateState.UP_TO_DATE])
+ self.update_states([nominatim_db.tools.replication.UpdateState.UP_TO_DATE,
+ nominatim_db.tools.replication.UpdateState.UP_TO_DATE])
with pytest.raises(IndexError):
self.call_nominatim()
def test_replication_update_continuous_no_change(self, mock_func_factory,
index_mock):
- self.update_states([nominatim.tools.replication.UpdateState.NO_CHANGES,
- nominatim.tools.replication.UpdateState.UP_TO_DATE])
+ self.update_states([nominatim_db.tools.replication.UpdateState.NO_CHANGES,
+ nominatim_db.tools.replication.UpdateState.UP_TO_DATE])
sleep_mock = mock_func_factory(time, 'sleep')
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Test for loading dotenv configuration.
from pathlib import Path
import pytest
-from nominatim.config import Configuration, flatten_config_list
-from nominatim.errors import UsageError
+from nominatim_core.config import Configuration, flatten_config_list
+from nominatim_core.errors import UsageError
@pytest.fixture
def make_config():
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Test for loading extra Python modules.
import pytest
-from nominatim.config import Configuration
+from nominatim_core.config import Configuration
@pytest.fixture
def test_config(src_dir, tmp_path):
def test_load_default_module(test_config):
- module = test_config.load_plugin_module('version', 'nominatim')
+ module = test_config.load_plugin_module('version', 'nominatim_db')
assert isinstance(module.NOMINATIM_VERSION, tuple)
def test_load_default_module_with_hyphen(test_config):
- module = test_config.load_plugin_module('place-info', 'nominatim.data')
+ module = test_config.load_plugin_module('place-info', 'nominatim_db.data')
assert isinstance(module.PlaceInfo, object)
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
import itertools
import sys
# always test against the source
SRC_DIR = (Path(__file__) / '..' / '..' / '..').resolve()
-sys.path.insert(0, str(SRC_DIR))
+sys.path.insert(0, str(SRC_DIR / 'src'))
-from nominatim.config import Configuration
-from nominatim.db import connection
-from nominatim.db.sql_preprocessor import SQLPreprocessor
-import nominatim.tokenizer.factory
+from nominatim_core.config import Configuration
+from nominatim_core.db import connection
+from nominatim_core.db.sql_preprocessor import SQLPreprocessor
+import nominatim_db.tokenizer.factory
import dummy_tokenizer
import mocks
def _import_dummy(*args, **kwargs):
return dummy_tokenizer
- monkeypatch.setattr(nominatim.tokenizer.factory, "_import_tokenizer", _import_dummy)
+ monkeypatch.setattr(nominatim_db.tokenizer.factory,
+ "_import_tokenizer", _import_dummy)
property_table.set('tokenizer', 'dummy')
def _create_tokenizer():
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Specialised psycopg2 cursor with shortcut functions useful for testing.
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for function that handle country properties.
from textwrap import dedent
import pytest
-from nominatim.data import country_info
+from nominatim_db.data import country_info
@pytest.fixture
def loaded_country(def_config):
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for function providing a non-blocking query interface towards PostgreSQL.
import pytest
import psycopg2
-from nominatim.db.async_connection import DBConnection, DeadlockHandler
+from nominatim_core.db.async_connection import DBConnection, DeadlockHandler
@pytest.fixture
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for specialised connection and cursor classes.
import pytest
import psycopg2
-from nominatim.db.connection import connect, get_pg_env
+from nominatim_core.db.connection import connect, get_pg_env
@pytest.fixture
def db(dsn):
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for property table manpulation.
"""
import pytest
-from nominatim.db import properties
+from nominatim_core.db import properties
@pytest.fixture
def property_factory(property_table, temp_db_cursor):
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for SQL preprocessing.
"""
import pytest
-from nominatim.db.sql_preprocessor import SQLPreprocessor
+from nominatim_core.db.sql_preprocessor import SQLPreprocessor
@pytest.fixture
def sql_factory(tmp_path):
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for status table manipulation.
import pytest
-import nominatim.db.status
-from nominatim.errors import UsageError
+import nominatim_core.db.status
+from nominatim_core.errors import UsageError
OSM_NODE_DATA = """\
<osm version="0.6" generator="OpenStreetMap server" copyright="OpenStreetMap and contributors" attribution="http://www.openstreetmap.org/copyright" license="http://opendatacommons.org/licenses/odbl/1-0/">
"""
def iso_date(date):
- return dt.datetime.strptime(date, nominatim.db.status.ISODATE_FORMAT)\
+ return dt.datetime.strptime(date, nominatim_core.db.status.ISODATE_FORMAT)\
.replace(tzinfo=dt.timezone.utc)
table_factory('osm2pgsql_properties', 'property TEXT, value TEXT',
content=(('current_timestamp', '2024-01-03T23:45:54Z'), ))
- date = nominatim.db.status.compute_database_date(temp_db_conn, offline=offline)
+ date = nominatim_core.db.status.compute_database_date(temp_db_conn, offline=offline)
assert date == iso_date('2024-01-03T23:45:54')
table_factory('osm2pgsql_properties', 'property TEXT, value TEXT')
with pytest.raises(UsageError, match='Cannot determine database date from data in offline mode'):
- nominatim.db.status.compute_database_date(temp_db_conn, offline=True)
+ nominatim_core.db.status.compute_database_date(temp_db_conn, offline=True)
def test_compute_database_date_place_empty(place_table, temp_db_conn):
with pytest.raises(UsageError):
- nominatim.db.status.compute_database_date(temp_db_conn)
+ nominatim_core.db.status.compute_database_date(temp_db_conn)
def test_compute_database_date_valid(monkeypatch, place_row, temp_db_conn):
requested_url.append(url)
return OSM_NODE_DATA
- monkeypatch.setattr(nominatim.db.status, "get_url", mock_url)
+ monkeypatch.setattr(nominatim_core.db.status, "get_url", mock_url)
- date = nominatim.db.status.compute_database_date(temp_db_conn)
+ date = nominatim_core.db.status.compute_database_date(temp_db_conn)
assert requested_url == ['https://www.openstreetmap.org/api/0.6/node/45673/1']
assert date == iso_date('2006-01-27T22:09:10')
requested_url.append(url)
return '<osm version="0.6" generator="OpenStre'
- monkeypatch.setattr(nominatim.db.status, "get_url", mock_url)
+ monkeypatch.setattr(nominatim_core.db.status, "get_url", mock_url)
with pytest.raises(UsageError):
- nominatim.db.status.compute_database_date(temp_db_conn)
+ nominatim_core.db.status.compute_database_date(temp_db_conn)
def test_set_status_empty_table(temp_db_conn, temp_db_cursor):
date = dt.datetime.fromordinal(1000000).replace(tzinfo=dt.timezone.utc)
- nominatim.db.status.set_status(temp_db_conn, date=date)
+ nominatim_core.db.status.set_status(temp_db_conn, date=date)
assert temp_db_cursor.row_set("SELECT * FROM import_status") == \
{(date, None, True)}
def test_set_status_filled_table(temp_db_conn, temp_db_cursor):
date = dt.datetime.fromordinal(1000000).replace(tzinfo=dt.timezone.utc)
- nominatim.db.status.set_status(temp_db_conn, date=date)
+ nominatim_core.db.status.set_status(temp_db_conn, date=date)
assert temp_db_cursor.table_rows('import_status') == 1
date = dt.datetime.fromordinal(1000100).replace(tzinfo=dt.timezone.utc)
- nominatim.db.status.set_status(temp_db_conn, date=date, seq=456, indexed=False)
+ nominatim_core.db.status.set_status(temp_db_conn, date=date, seq=456, indexed=False)
assert temp_db_cursor.row_set("SELECT * FROM import_status") == \
{(date, 456, False)}
def test_set_status_missing_date(temp_db_conn, temp_db_cursor):
date = dt.datetime.fromordinal(1000000).replace(tzinfo=dt.timezone.utc)
- nominatim.db.status.set_status(temp_db_conn, date=date)
+ nominatim_core.db.status.set_status(temp_db_conn, date=date)
assert temp_db_cursor.table_rows('import_status') == 1
- nominatim.db.status.set_status(temp_db_conn, date=None, seq=456, indexed=False)
+ nominatim_core.db.status.set_status(temp_db_conn, date=None, seq=456, indexed=False)
assert temp_db_cursor.row_set("SELECT * FROM import_status") == \
{(date, 456, False)}
def test_get_status_empty_table(temp_db_conn):
- assert nominatim.db.status.get_status(temp_db_conn) == (None, None, None)
+ assert nominatim_core.db.status.get_status(temp_db_conn) == (None, None, None)
def test_get_status_success(temp_db_conn):
date = dt.datetime.fromordinal(1000000).replace(tzinfo=dt.timezone.utc)
- nominatim.db.status.set_status(temp_db_conn, date=date, seq=667, indexed=False)
+ nominatim_core.db.status.set_status(temp_db_conn, date=date, seq=667, indexed=False)
- assert nominatim.db.status.get_status(temp_db_conn) == \
+ assert nominatim_core.db.status.get_status(temp_db_conn) == \
(date, 667, False)
@pytest.mark.parametrize("new_state", [True, False])
def test_set_indexed(temp_db_conn, temp_db_cursor, old_state, new_state):
date = dt.datetime.fromordinal(1000000).replace(tzinfo=dt.timezone.utc)
- nominatim.db.status.set_status(temp_db_conn, date=date, indexed=old_state)
- nominatim.db.status.set_indexed(temp_db_conn, new_state)
+ nominatim_core.db.status.set_status(temp_db_conn, date=date, indexed=old_state)
+ nominatim_core.db.status.set_indexed(temp_db_conn, new_state)
assert temp_db_cursor.scalar("SELECT indexed FROM import_status") == new_state
def test_set_indexed_empty_status(temp_db_conn, temp_db_cursor):
- nominatim.db.status.set_indexed(temp_db_conn, True)
+ nominatim_core.db.status.set_indexed(temp_db_conn, True)
assert temp_db_cursor.table_rows("import_status") == 0
date = dt.datetime.fromordinal(1000000).replace(tzinfo=dt.timezone.utc)
start = dt.datetime.now() - dt.timedelta(hours=1)
- nominatim.db.status.set_status(temp_db_conn, date=date, seq=56)
- nominatim.db.status.log_status(temp_db_conn, start, 'index')
+ nominatim_core.db.status.set_status(temp_db_conn, date=date, seq=56)
+ nominatim_core.db.status.log_status(temp_db_conn, start, 'index')
temp_db_conn.commit()
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for DB utility functions in db.utils
import pytest
-import nominatim.db.utils as db_utils
-from nominatim.errors import UsageError
+import nominatim_core.db.utils as db_utils
+from nominatim_core.errors import UsageError
def test_execute_file_success(dsn, temp_db_cursor, tmp_path):
tmpfile = tmp_path / 'test.sql'
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tokenizer for testing.
"""
-from nominatim.data.place_info import PlaceInfo
-from nominatim.config import Configuration
+from nominatim_db.data.place_info import PlaceInfo
+from nominatim_core.config import Configuration
def create(dsn, data_dir):
""" Create a new instance of the tokenizer provided by this module.
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for running the indexing.
import itertools
import pytest
-from nominatim.indexer import indexer
-from nominatim.tokenizer import factory
+from nominatim_db.indexer import indexer
+from nominatim_db.tokenizer import factory
class IndexerTestDB:
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Legacy word table for testing with functions to prefil and test contents
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Legacy word table for testing with functions to prefil and test contents
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Custom mocks for testing.
import psycopg2.extras
-from nominatim.db import properties
+from nominatim_core.db import properties
# This must always point to the mock word table for the default tokenizer.
from mock_icu_word_table import MockIcuWordTable as MockWordTable
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for the sanitizer that normalizes housenumbers.
"""
import pytest
-from nominatim.tokenizer.place_sanitizer import PlaceSanitizer
-from nominatim.data.place_info import PlaceInfo
+from nominatim_db.tokenizer.place_sanitizer import PlaceSanitizer
+from nominatim_db.data.place_info import PlaceInfo
@pytest.fixture
def sanitize(request, def_config):
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for the sanitizer that normalizes postcodes.
"""
import pytest
-from nominatim.tokenizer.place_sanitizer import PlaceSanitizer
-from nominatim.data.place_info import PlaceInfo
-from nominatim.data import country_info
+from nominatim_db.tokenizer.place_sanitizer import PlaceSanitizer
+from nominatim_db.data.place_info import PlaceInfo
+from nominatim_db.data import country_info
@pytest.fixture
def sanitize(def_config, request):
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for sanitizer that clean up TIGER tags.
"""
import pytest
-from nominatim.tokenizer.place_sanitizer import PlaceSanitizer
-from nominatim.data.place_info import PlaceInfo
+from nominatim_db.tokenizer.place_sanitizer import PlaceSanitizer
+from nominatim_db.data.place_info import PlaceInfo
class TestCleanTigerTags:
-# SPDX-License-Identifier: GPL-2.0-only\r
+# SPDX-License-Identifier: GPL-3.0-or-later\r
#\r
# This file is part of Nominatim. (https://nominatim.org)\r
#\r
-# Copyright (C) 2023 by the Nominatim developer community.\r
+# Copyright (C) 2024 by the Nominatim developer community.\r
# For a full list of authors see the git log.\r
"""\r
Tests for the sanitizer that normalizes housenumbers.\r
"""\r
import pytest\r
\r
-\r
-from nominatim.data.place_info import PlaceInfo\r
-from nominatim.tokenizer.place_sanitizer import PlaceSanitizer\r
+from nominatim_db.data.place_info import PlaceInfo\r
+from nominatim_db.tokenizer.place_sanitizer import PlaceSanitizer\r
\r
\r
class TestWithDefault:\r
name='foo', ref='foo', name_pqr='bar', ref_pqr='baz')\r
\r
assert res == [('bar', 'name', 'pqr'), ('baz', 'ref', 'pqr'),\r
- ('foo', 'name', ''), ('foo', 'ref', '')]
\ No newline at end of file
+ ('foo', 'name', ''), ('foo', 'ref', '')]\r
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for sanitizer configuration helper functions.
"""
import pytest
-from nominatim.errors import UsageError
-from nominatim.tokenizer.sanitizers.config import SanitizerConfig
+from nominatim_core.errors import UsageError
+from nominatim_db.tokenizer.sanitizers.config import SanitizerConfig
def test_string_list_default_empty():
assert SanitizerConfig().get_string_list('op') == []
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for the sanitizer that splits multivalue lists.
"""
import pytest
-from nominatim.tokenizer.place_sanitizer import PlaceSanitizer
-from nominatim.data.place_info import PlaceInfo
+from nominatim_db.tokenizer.place_sanitizer import PlaceSanitizer
+from nominatim_db.data.place_info import PlaceInfo
-from nominatim.errors import UsageError
+from nominatim_core.errors import UsageError
class TestSplitName:
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for the sanitizer that handles braced suffixes.
"""
import pytest
-from nominatim.tokenizer.place_sanitizer import PlaceSanitizer
-from nominatim.data.place_info import PlaceInfo
+from nominatim_db.tokenizer.place_sanitizer import PlaceSanitizer
+from nominatim_db.data.place_info import PlaceInfo
class TestStripBrace:
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for the sanitizer that enables language-dependent analyzers.
"""
import pytest
-from nominatim.data.place_info import PlaceInfo
-from nominatim.tokenizer.place_sanitizer import PlaceSanitizer
-from nominatim.data.country_info import setup_country_config
+from nominatim_db.data.place_info import PlaceInfo
+from nominatim_db.tokenizer.place_sanitizer import PlaceSanitizer
+from nominatim_db.data.country_info import setup_country_config
class TestWithDefaults:
-from nominatim.data.place_info import PlaceInfo
-from nominatim.data.place_name import PlaceName
-from nominatim.tokenizer.place_sanitizer import PlaceSanitizer
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+# This file is part of Nominatim. (https://nominatim.org)
+#
+# Copyright (C) 2024 by the Nominatim developer community.
+# For a full list of authors see the git log.
from typing import Mapping, Optional, List
import pytest
+from nominatim_db.data.place_info import PlaceInfo
+from nominatim_db.data.place_name import PlaceName
+from nominatim_db.tokenizer.place_sanitizer import PlaceSanitizer
+
class TestTagJapanese:
@pytest.fixture(autouse=True)
def setup_country(self, def_config):
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for creating new tokenizers.
"""
import pytest
-from nominatim.db import properties
-from nominatim.tokenizer import factory
-from nominatim.errors import UsageError
+from nominatim_core.db import properties
+from nominatim_db.tokenizer import factory
+from nominatim_core.errors import UsageError
from dummy_tokenizer import DummyTokenizer
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for ICU tokenizer.
import pytest
-from nominatim.tokenizer import icu_tokenizer
-import nominatim.tokenizer.icu_rule_loader
-from nominatim.db import properties
-from nominatim.db.sql_preprocessor import SQLPreprocessor
-from nominatim.data.place_info import PlaceInfo
+from nominatim_db.tokenizer import icu_tokenizer
+import nominatim_db.tokenizer.icu_rule_loader
+from nominatim_core.db import properties
+from nominatim_core.db.sql_preprocessor import SQLPreprocessor
+from nominatim_db.data.place_info import PlaceInfo
from mock_icu_word_table import MockIcuWordTable
cfgstr['token-analysis'].append({'id': '@postcode',
'analyzer': 'postcodes'})
(test_config.project_dir / 'icu_tokenizer.yaml').write_text(yaml.dump(cfgstr))
- tok.loader = nominatim.tokenizer.icu_rule_loader.ICURuleLoader(test_config)
+ tok.loader = nominatim_db.tokenizer.icu_rule_loader.ICURuleLoader(test_config)
return tok.name_analyzer()
tok = tokenizer_factory()
tok.init_new_db(test_config)
- assert db_prop(nominatim.tokenizer.icu_rule_loader.DBCFG_IMPORT_NORM_RULES) \
+ assert db_prop(nominatim_db.tokenizer.icu_rule_loader.DBCFG_IMPORT_NORM_RULES) \
.startswith(':: lower ();')
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for converting a config file to ICU rules.
import pytest
import yaml
-from nominatim.tokenizer.icu_rule_loader import ICURuleLoader
-from nominatim.errors import UsageError
+from nominatim_db.tokenizer.icu_rule_loader import ICURuleLoader
+from nominatim_core.errors import UsageError
from icu import Transliterator
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Test for legacy tokenizer.
import pytest
-from nominatim.data.place_info import PlaceInfo
-from nominatim.tokenizer import legacy_tokenizer
-from nominatim.db import properties
-from nominatim.errors import UsageError
+from nominatim_db.data.place_info import PlaceInfo
+from nominatim_db.tokenizer import legacy_tokenizer
+from nominatim_core.db import properties
+from nominatim_core.errors import UsageError
from mock_legacy_word_table import MockLegacyWordTable
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for execution of the sanitztion step.
"""
import pytest
-from nominatim.errors import UsageError
-import nominatim.tokenizer.place_sanitizer as sanitizer
-from nominatim.data.place_info import PlaceInfo
+from nominatim_core.errors import UsageError
+import nominatim_db.tokenizer.place_sanitizer as sanitizer
+from nominatim_db.data.place_info import PlaceInfo
def test_placeinfo_clone_new_name():
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for special postcode analysis and variant generation.
from icu import Transliterator
-import nominatim.tokenizer.token_analysis.postcodes as module
-from nominatim.data.place_name import PlaceName
-from nominatim.errors import UsageError
+import nominatim_db.tokenizer.token_analysis.postcodes as module
+from nominatim_db.data.place_name import PlaceName
+from nominatim_core.errors import UsageError
DEFAULT_NORMALIZATION = """ :: NFD ();
'🜳' > ' ';
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for import name normalisation and variant generation.
from icu import Transliterator
-import nominatim.tokenizer.token_analysis.generic as module
-from nominatim.errors import UsageError
+import nominatim_db.tokenizer.token_analysis.generic as module
+from nominatim_core.errors import UsageError
DEFAULT_NORMALIZATION = """ :: NFD ();
'🜳' > ' ';
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for generic token analysis, mutation part.
from icu import Transliterator
-import nominatim.tokenizer.token_analysis.generic as module
-from nominatim.errors import UsageError
+import nominatim_db.tokenizer.token_analysis.generic as module
+from nominatim_core.errors import UsageError
DEFAULT_NORMALIZATION = """ '🜳' > ' ';
[[:Nonspacing Mark:] [:Cf:]] >;
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
import pytest
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for functions to add additional data to the database.
import pytest
-from nominatim.tools import add_osm_data
+from nominatim_db.tools import add_osm_data
class CaptureGetUrl:
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for maintenance and analysis functions.
"""
import pytest
-from nominatim.errors import UsageError
-from nominatim.tools import admin
-from nominatim.tokenizer import factory
-from nominatim.db.sql_preprocessor import SQLPreprocessor
+from nominatim_core.errors import UsageError
+from nominatim_db.tools import admin
+from nominatim_db.tokenizer import factory
+from nominatim_core.db.sql_preprocessor import SQLPreprocessor
@pytest.fixture(autouse=True)
def create_placex_table(project_env, tokenizer_mock, temp_db_cursor, placex_table):
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for database integrity checks.
"""
import pytest
-from nominatim.tools import check_database as chkdb
-import nominatim.version
+from nominatim_db.tools import check_database as chkdb
+import nominatim_db.version
def test_check_database_unknown_db(def_config, monkeypatch):
monkeypatch.setenv('NOMINATIM_DATABASE_DSN', 'pgsql:dbname=fjgkhughwgh2423gsags')
def test_check_database_version_good(property_table, temp_db_conn, def_config):
property_table.set('database_version',
- '{0[0]}.{0[1]}.{0[2]}-{0[3]}'.format(nominatim.version.NOMINATIM_VERSION))
+ str(nominatim_db.version.NOMINATIM_VERSION))
assert chkdb.check_database_version(temp_db_conn, def_config) == chkdb.CheckState.OK
def test_check_database_version_bad(property_table, temp_db_conn, def_config):
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for functions to import a new database.
import pytest
import psycopg2
-from nominatim.tools import database_import
-from nominatim.errors import UsageError
+from nominatim_db.tools import database_import
+from nominatim_core.errors import UsageError
class TestDatabaseSetup:
DBNAME = 'test_nominatim_python_unittest'
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for tools.exec_utils module.
import pytest
-from nominatim.config import Configuration
-import nominatim.tools.exec_utils as exec_utils
-import nominatim.paths
-
-
-### run_osm2pgsql
+from nominatim_core.config import Configuration
+import nominatim_db.tools.exec_utils as exec_utils
def test_run_osm2pgsql(osm2pgsql_options):
osm2pgsql_options['append'] = False
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for freeze functions (removing unused database parts).
"""
-from nominatim.tools import freeze
+from nominatim_db.tools import freeze
NOMINATIM_RUNTIME_TABLES = [
'country_name', 'country_osm_grid',
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for import special phrases methods
"""
from shutil import copyfile
import pytest
-from nominatim.tools.special_phrases.sp_importer import SPImporter
-from nominatim.tools.special_phrases.sp_wiki_loader import SPWikiLoader
-from nominatim.tools.special_phrases.special_phrase import SpecialPhrase
-from nominatim.errors import UsageError
+from nominatim_db.tools.special_phrases.sp_importer import SPImporter
+from nominatim_db.tools.special_phrases.sp_wiki_loader import SPWikiLoader
+from nominatim_db.tools.special_phrases.special_phrase import SpecialPhrase
+from nominatim_core.errors import UsageError
from cursor import CursorForTesting
table_factory('place_classtype_amenity_animal_shelter')
table_factory('place_classtype_wrongclass_wrongtype')
- monkeypatch.setattr('nominatim.tools.special_phrases.sp_wiki_loader._get_wiki_content',
+ monkeypatch.setattr('nominatim_db.tools.special_phrases.sp_wiki_loader._get_wiki_content',
lambda lang: xml_wiki_content)
tokenizer = tokenizer_mock()
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for migration functions
import pytest
import psycopg2.extras
-from nominatim.tools import migration
-from nominatim.errors import UsageError
-import nominatim.version
+from nominatim_db.tools import migration
+from nominatim_core.errors import UsageError
+import nominatim_db.version
from mock_legacy_word_table import MockLegacyWordTable
def test_already_at_version(def_config, property_table):
property_table.set('database_version',
- '{0[0]}.{0[1]}.{0[2]}-{0[3]}'.format(nominatim.version.NOMINATIM_VERSION))
+ str(nominatim_db.version.NOMINATIM_VERSION))
assert migration.migrate(def_config, {}) == 0
def test_run_single_migration(def_config, temp_db_cursor, property_table,
monkeypatch, postprocess_mock):
- oldversion = [x for x in nominatim.version.NOMINATIM_VERSION]
+ oldversion = [x for x in nominatim_db.version.NOMINATIM_VERSION]
oldversion[0] -= 1
property_table.set('database_version',
- '{0[0]}.{0[1]}.{0[2]}-{0[3]}'.format(oldversion))
+ str(nominatim_db.version.NominatimVersion(*oldversion)))
done = {'old': False, 'new': False}
def _migration(**_):
oldversion[0] = 0
monkeypatch.setattr(migration, '_MIGRATION_FUNCTIONS',
[(tuple(oldversion), _old_migration),
- (nominatim.version.NOMINATIM_VERSION, _migration)])
+ (nominatim_db.version.NOMINATIM_VERSION, _migration)])
assert migration.migrate(def_config, {}) == 0
assert done['new']
assert not done['old']
- assert property_table.get('database_version') == \
- '{0[0]}.{0[1]}.{0[2]}-{0[3]}'.format(nominatim.version.NOMINATIM_VERSION)
+ assert property_table.get('database_version') == str(nominatim_db.version.NOMINATIM_VERSION)
###### Tests for specific migrations
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for functions to maintain the artificial postcode table.
import pytest
-from nominatim.tools import postcodes
-from nominatim.data import country_info
+from nominatim_db.tools import postcodes
+from nominatim_db.data import country_info
import dummy_tokenizer
class MockPostcodeTable:
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Test for various refresh functions.
import pytest
-from nominatim.tools import refresh
+from nominatim_db.tools import refresh
def test_refresh_import_wikipedia_not_existing(dsn):
assert refresh.import_wikipedia_articles(dsn, Path('.')) == 1
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for function for importing address ranks.
import pytest
-from nominatim.tools.refresh import load_address_levels, load_address_levels_from_config
+from nominatim_db.tools.refresh import load_address_levels, load_address_levels_from_config
def test_load_ranks_def_config(temp_db_conn, temp_db_cursor, def_config):
load_address_levels_from_config(temp_db_conn, def_config)
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for creating PL/pgSQL functions for Nominatim.
"""
import pytest
-from nominatim.tools.refresh import create_functions
+from nominatim_db.tools.refresh import create_functions
class TestCreateFunctions:
@pytest.fixture(autouse=True)
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for setting up the website scripts.
import pytest
-from nominatim.tools import refresh
+from nominatim_db.tools import refresh
@pytest.fixture
def test_script(tmp_path):
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for replication functionality.
import pytest
from osmium.replication.server import OsmosisState
-import nominatim.tools.replication
-import nominatim.db.status as status
-from nominatim.errors import UsageError
+import nominatim_db.tools.replication
+import nominatim_core.db.status as status
+from nominatim_core.errors import UsageError
OSM_NODE_DATA = """\
<osm version="0.6" generator="OpenStreetMap server" copyright="OpenStreetMap and contributors" attribution="http://www.openstreetmap.org/copyright" license="http://opendatacommons.org/licenses/odbl/1-0/">
def test_init_replication_bad_base_url(monkeypatch, place_row, temp_db_conn):
place_row(osm_type='N', osm_id=100)
- monkeypatch.setattr(nominatim.db.status, "get_url", lambda u: OSM_NODE_DATA)
+ monkeypatch.setattr(status, "get_url", lambda u: OSM_NODE_DATA)
with pytest.raises(UsageError, match="Failed to reach replication service"):
- nominatim.tools.replication.init_replication(temp_db_conn, 'https://test.io')
+ nominatim_db.tools.replication.init_replication(temp_db_conn, 'https://test.io')
def test_init_replication_success(monkeypatch, place_row, temp_db_conn, temp_db_cursor):
place_row(osm_type='N', osm_id=100)
- monkeypatch.setattr(nominatim.db.status, "get_url", lambda u: OSM_NODE_DATA)
- monkeypatch.setattr(nominatim.tools.replication.ReplicationServer,
+ monkeypatch.setattr(status, "get_url", lambda u: OSM_NODE_DATA)
+ monkeypatch.setattr(nominatim_db.tools.replication.ReplicationServer,
"timestamp_to_sequence",
lambda self, date: 234)
- nominatim.tools.replication.init_replication(temp_db_conn, 'https://test.io')
+ nominatim_db.tools.replication.init_replication(temp_db_conn, 'https://test.io')
expected_date = dt.datetime.strptime('2006-01-27T19:09:10', status.ISODATE_FORMAT)\
.replace(tzinfo=dt.timezone.utc)
### checking for updates
def test_check_for_updates_empty_status_table(temp_db_conn):
- assert nominatim.tools.replication.check_for_updates(temp_db_conn, 'https://test.io') == 254
+ assert nominatim_db.tools.replication.check_for_updates(temp_db_conn, 'https://test.io') == 254
def test_check_for_updates_seq_not_set(temp_db_conn):
status.set_status(temp_db_conn, dt.datetime.now(dt.timezone.utc))
- assert nominatim.tools.replication.check_for_updates(temp_db_conn, 'https://test.io') == 254
+ assert nominatim_db.tools.replication.check_for_updates(temp_db_conn, 'https://test.io') == 254
def test_check_for_updates_no_state(monkeypatch, temp_db_conn):
status.set_status(temp_db_conn, dt.datetime.now(dt.timezone.utc), seq=345)
- monkeypatch.setattr(nominatim.tools.replication.ReplicationServer,
+ monkeypatch.setattr(nominatim_db.tools.replication.ReplicationServer,
"get_state_info", lambda self: None)
- assert nominatim.tools.replication.check_for_updates(temp_db_conn, 'https://test.io') == 253
+ assert nominatim_db.tools.replication.check_for_updates(temp_db_conn, 'https://test.io') == 253
@pytest.mark.parametrize("server_sequence,result", [(344, 2), (345, 2), (346, 0)])
date = dt.datetime.now(dt.timezone.utc)
status.set_status(temp_db_conn, date, seq=345)
- monkeypatch.setattr(nominatim.tools.replication.ReplicationServer,
+ monkeypatch.setattr(nominatim_db.tools.replication.ReplicationServer,
"get_state_info",
lambda self: OsmosisState(server_sequence, date))
- assert nominatim.tools.replication.check_for_updates(temp_db_conn, 'https://test.io') == result
+ assert nominatim_db.tools.replication.check_for_updates(temp_db_conn, 'https://test.io') == result
### updating
def test_update_empty_status_table(dsn):
with pytest.raises(UsageError):
- nominatim.tools.replication.update(dsn, {})
+ nominatim_db.tools.replication.update(dsn, {})
def test_update_already_indexed(temp_db_conn, dsn):
status.set_status(temp_db_conn, dt.datetime.now(dt.timezone.utc), seq=34, indexed=False)
- assert nominatim.tools.replication.update(dsn, dict(indexed_only=True)) \
- == nominatim.tools.replication.UpdateState.MORE_PENDING
+ assert nominatim_db.tools.replication.update(dsn, dict(indexed_only=True)) \
+ == nominatim_db.tools.replication.UpdateState.MORE_PENDING
def test_update_no_data_no_sleep(monkeypatch, temp_db_conn, dsn, update_options):
date = dt.datetime.now(dt.timezone.utc) - dt.timedelta(days=1)
status.set_status(temp_db_conn, date, seq=34)
- monkeypatch.setattr(nominatim.tools.replication.ReplicationServer,
+ monkeypatch.setattr(nominatim_db.tools.replication.ReplicationServer,
"apply_diffs",
lambda *args, **kwargs: None)
sleeptime = []
monkeypatch.setattr(time, 'sleep', sleeptime.append)
- assert nominatim.tools.replication.update(dsn, update_options) \
- == nominatim.tools.replication.UpdateState.NO_CHANGES
+ assert nominatim_db.tools.replication.update(dsn, update_options) \
+ == nominatim_db.tools.replication.UpdateState.NO_CHANGES
assert not sleeptime
date = dt.datetime.now(dt.timezone.utc) - dt.timedelta(minutes=30)
status.set_status(temp_db_conn, date, seq=34)
- monkeypatch.setattr(nominatim.tools.replication.ReplicationServer,
+ monkeypatch.setattr(nominatim_db.tools.replication.ReplicationServer,
"apply_diffs",
lambda *args, **kwargs: None)
sleeptime = []
monkeypatch.setattr(time, 'sleep', sleeptime.append)
- assert nominatim.tools.replication.update(dsn, update_options) \
- == nominatim.tools.replication.UpdateState.NO_CHANGES
+ assert nominatim_db.tools.replication.update(dsn, update_options) \
+ == nominatim_db.tools.replication.UpdateState.NO_CHANGES
assert len(sleeptime) == 1
assert sleeptime[0] < 3600
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for methods of the SPCsvLoader class.
"""
import pytest
-from nominatim.errors import UsageError
-from nominatim.tools.special_phrases.sp_csv_loader import SPCsvLoader
-from nominatim.tools.special_phrases.special_phrase import SpecialPhrase
+from nominatim_core.errors import UsageError
+from nominatim_db.tools.special_phrases.sp_csv_loader import SPCsvLoader
+from nominatim_db.tools.special_phrases.special_phrase import SpecialPhrase
@pytest.fixture
def sp_csv_loader(src_dir):
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for methods of the SPWikiLoader class.
"""
import pytest
-from nominatim.tools.special_phrases.sp_wiki_loader import SPWikiLoader
+from nominatim_db.tools.special_phrases.sp_wiki_loader import SPWikiLoader
@pytest.fixture
xml_test_content = src_dir / 'test' / 'testdata' / 'special_phrases_test_content.txt'
return xml_test_content.read_text()
- monkeypatch.setattr('nominatim.tools.special_phrases.sp_wiki_loader._get_wiki_content',
+ monkeypatch.setattr('nominatim_db.tools.special_phrases.sp_wiki_loader._get_wiki_content',
_mock_wiki_content)
return loader
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Test for tiger data function
import pytest
-from nominatim.tools import tiger_data, freeze
-from nominatim.errors import UsageError
+from nominatim_db.tools import tiger_data, freeze
+from nominatim_core.errors import UsageError
class MockTigerTable:
-# 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) 2022 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for centroid computation.
"""
import pytest
-from nominatim.utils.centroid import PointsCentroid
+from nominatim_core.utils.centroid import PointsCentroid
def test_empty_set():
c = PointsCentroid()
#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2024 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for the streaming JSON writer.
import pytest
-from nominatim.utils.json_writer import JsonWriter
+from nominatim_core.utils.json_writer import JsonWriter
@pytest.mark.parametrize("inval,outstr", [(None, 'null'),
(True, 'true'), (False, 'false'),