From: Sarah Hoffmann Date: Sun, 9 Jun 2024 12:52:20 +0000 (+0200) Subject: port unit tests to new python package layout X-Git-Tag: deploy~4^2~15^2~16 X-Git-Url: https://git.openstreetmap.org/nominatim.git/commitdiff_plain/2bab0ca060ff224091b20a0ac808a3febaba04b1 port unit tests to new python package layout --- diff --git a/src/nominatim_api/__init__.py b/src/nominatim_api/__init__.py index 02cde0b2..3ffe0c27 100644 --- a/src/nominatim_api/__init__.py +++ b/src/nominatim_api/__init__.py @@ -36,3 +36,5 @@ from .results import (SourceTable as SourceTable, SearchResult as SearchResult, SearchResults as SearchResults) from .localization import (Locales as Locales) + +from .version import NOMINATIM_API_VERSION as __version__ diff --git a/src/nominatim_api/search/query_analyzer_factory.py b/src/nominatim_api/search/query_analyzer_factory.py index e10d7a7a..06443090 100644 --- a/src/nominatim_api/search/query_analyzer_factory.py +++ b/src/nominatim_api/search/query_analyzer_factory.py @@ -49,6 +49,6 @@ async def make_query_analyzer(conn: SearchConnection) -> AbstractQueryAnalyzer: 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)) diff --git a/src/nominatim_api/status.py b/src/nominatim_api/status.py index ea88a467..ec6ce5d6 100644 --- a/src/nominatim_api/status.py +++ b/src/nominatim_api/status.py @@ -14,7 +14,7 @@ import dataclasses 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: @@ -44,7 +44,7 @@ async def get_status(conn: SearchConnection) -> 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 diff --git a/src/nominatim_api/version.py b/src/nominatim_api/version.py index d275f4fc..5d932fc9 100644 --- a/src/nominatim_api/version.py +++ b/src/nominatim_api/version.py @@ -8,4 +8,6 @@ Version information for the Nominatim API. """ +from nominatim_core.version import NominatimVersion, parse_version + NOMINATIM_API_VERSION = '4.4.99' diff --git a/src/nominatim_core/paths.py b/src/nominatim_core/paths.py index 7cdd3678..aa289708 100644 --- a/src/nominatim_core/paths.py +++ b/src/nominatim_core/paths.py @@ -9,7 +9,7 @@ Path settings for extra data used by Nominatim. """ 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() diff --git a/src/nominatim_core/version.py b/src/nominatim_core/version.py index bf35aeb2..64e18b16 100644 --- a/src/nominatim_core/version.py +++ b/src/nominatim_core/version.py @@ -7,5 +7,50 @@ """ 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('-')]) diff --git a/src/nominatim_db/cli.py b/src/nominatim_db/cli.py index 7b55566c..746fbe32 100644 --- a/src/nominatim_db/cli.py +++ b/src/nominatim_db/cli.py @@ -180,7 +180,7 @@ class AdminServe: 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) diff --git a/src/nominatim_db/clicmd/api.py b/src/nominatim_db/clicmd/api.py index 7d9569e3..0f0d1ebd 100644 --- a/src/nominatim_db/clicmd/api.py +++ b/src/nominatim_db/clicmd/api.py @@ -7,7 +7,7 @@ """ 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 diff --git a/src/nominatim_db/version.py b/src/nominatim_db/version.py index ca383c85..82ae17e9 100644 --- a/src/nominatim_db/version.py +++ b/src/nominatim_db/version.py @@ -7,38 +7,9 @@ """ 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) @@ -50,13 +21,3 @@ POSTGIS_REQUIRED_VERSION = (2, 2) # 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('-')]) diff --git a/test/python/api/conftest.py b/test/python/api/conftest.py index 05eaddf5..08b7422c 100644 --- a/test/python/api/conftest.py +++ b/test/python/api/conftest.py @@ -1,8 +1,8 @@ -# SPDX-License-Identifier: GPL-2.0-only +# SPDX-License-Identifier: GPL-3.0-or-later # # This file is part of Nominatim. (https://nominatim.org) # -# Copyright (C) 2023 by the Nominatim developer community. +# Copyright (C) 2024 by the Nominatim developer community. # For a full list of authors see the git log. """ Helper fixtures for API call tests. @@ -14,11 +14,11 @@ import datetime as dt 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: diff --git a/test/python/api/fake_adaptor.py b/test/python/api/fake_adaptor.py index d886d34e..50fbbbbe 100644 --- a/test/python/api/fake_adaptor.py +++ b/test/python/api/fake_adaptor.py @@ -2,15 +2,15 @@ # # 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): diff --git a/test/python/api/search/test_api_search_query.py b/test/python/api/search/test_api_search_query.py index bfdceb41..7154ae08 100644 --- a/test/python/api/search/test_api_search_query.py +++ b/test/python/api/search/test_api_search_query.py @@ -2,14 +2,14 @@ # # 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): diff --git a/test/python/api/search/test_db_search_builder.py b/test/python/api/search/test_db_search_builder.py index 68f71298..5d984014 100644 --- a/test/python/api/search/test_db_search_builder.py +++ b/test/python/api/search/test_db_search_builder.py @@ -9,11 +9,11 @@ Tests for creating abstract searches from token assignments. """ 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): diff --git a/test/python/api/search/test_icu_query_analyzer.py b/test/python/api/search/test_icu_query_analyzer.py index 2ec3a7fe..8e5480fc 100644 --- a/test/python/api/search/test_icu_query_analyzer.py +++ b/test/python/api/search/test_icu_query_analyzer.py @@ -2,7 +2,7 @@ # # 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. @@ -12,10 +12,10 @@ from pathlib import Path 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'] diff --git a/test/python/api/search/test_legacy_query_analyzer.py b/test/python/api/search/test_legacy_query_analyzer.py index 507afaec..92de8706 100644 --- a/test/python/api/search/test_legacy_query_analyzer.py +++ b/test/python/api/search/test_legacy_query_analyzer.py @@ -2,7 +2,7 @@ # # 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. @@ -12,10 +12,10 @@ from pathlib import Path 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): diff --git a/test/python/api/search/test_query.py b/test/python/api/search/test_query.py index a4b32824..c39094f0 100644 --- a/test/python/api/search/test_query.py +++ b/test/python/api/search/test_query.py @@ -1,16 +1,15 @@ - # 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) diff --git a/test/python/api/search/test_query_analyzer_factory.py b/test/python/api/search/test_query_analyzer_factory.py index 2d113e3e..9545a88f 100644 --- a/test/python/api/search/test_query_analyzer_factory.py +++ b/test/python/api/search/test_query_analyzer_factory.py @@ -2,7 +2,7 @@ # # 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. @@ -11,9 +11,9 @@ from pathlib import Path 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): diff --git a/test/python/api/search/test_search_country.py b/test/python/api/search/test_search_country.py index dc87d313..2109ecb0 100644 --- a/test/python/api/search/test_search_country.py +++ b/test/python/api/search/test_search_country.py @@ -2,17 +2,17 @@ # # 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, diff --git a/test/python/api/search/test_search_near.py b/test/python/api/search/test_search_near.py index 5b60dd51..43098ddd 100644 --- a/test/python/api/search/test_search_near.py +++ b/test/python/api/search/test_search_near.py @@ -2,19 +2,19 @@ # # 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=[], diff --git a/test/python/api/search/test_search_places.py b/test/python/api/search/test_search_places.py index 5e06776d..c6ff16b8 100644 --- a/test/python/api/search/test_search_places.py +++ b/test/python/api/search/test_search_places.py @@ -2,7 +2,7 @@ # # 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. @@ -11,12 +11,12 @@ import json 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'] diff --git a/test/python/api/search/test_search_poi.py b/test/python/api/search/test_search_poi.py index a0b578ba..d4319a57 100644 --- a/test/python/api/search/test_search_poi.py +++ b/test/python/api/search/test_search_poi.py @@ -2,17 +2,17 @@ # # 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, diff --git a/test/python/api/search/test_search_postcode.py b/test/python/api/search/test_search_postcode.py index 6976b6a5..633e07bc 100644 --- a/test/python/api/search/test_search_postcode.py +++ b/test/python/api/search/test_search_postcode.py @@ -2,17 +2,17 @@ # # 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, diff --git a/test/python/api/search/test_token_assignment.py b/test/python/api/search/test_token_assignment.py index cde8495d..884d2932 100644 --- a/test/python/api/search/test_token_assignment.py +++ b/test/python/api/search/test_token_assignment.py @@ -2,15 +2,15 @@ # # 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): diff --git a/test/python/api/test_api_connection.py b/test/python/api/test_api_connection.py index 5609cb03..3c4fc61b 100644 --- a/test/python/api/test_api_connection.py +++ b/test/python/api/test_api_connection.py @@ -2,7 +2,7 @@ # # 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. @@ -13,7 +13,7 @@ import pytest_asyncio import sqlalchemy as sa -from nominatim.api import NominatimAPIAsync +from nominatim_api import NominatimAPIAsync @pytest_asyncio.fixture async def apiobj(temp_db): diff --git a/test/python/api/test_api_deletable_v1.py b/test/python/api/test_api_deletable_v1.py index 4c5d96b6..1b8dc34d 100644 --- a/test/python/api/test_api_deletable_v1.py +++ b/test/python/api/test_api_deletable_v1.py @@ -2,7 +2,7 @@ # # 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. @@ -17,8 +17,8 @@ import psycopg2.extras 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(): diff --git a/test/python/api/test_api_details.py b/test/python/api/test_api_details.py index 596876d4..7f405728 100644 --- a/test/python/api/test_api_details.py +++ b/test/python/api/test_api_details.py @@ -2,7 +2,7 @@ # # 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. @@ -11,7 +11,7 @@ import datetime as dt 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'))) diff --git a/test/python/api/test_api_lookup.py b/test/python/api/test_api_lookup.py index 48b07776..4281cd6c 100644 --- a/test/python/api/test_api_lookup.py +++ b/test/python/api/test_api_lookup.py @@ -2,7 +2,7 @@ # # 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. @@ -11,7 +11,7 @@ import json import pytest -import nominatim.api as napi +import nominatim_api as napi def test_lookup_empty_list(apiobj, frontend): api = frontend(apiobj, options={'details'}) diff --git a/test/python/api/test_api_polygons_v1.py b/test/python/api/test_api_polygons_v1.py index 6842f791..bf51cd17 100644 --- a/test/python/api/test_api_polygons_v1.py +++ b/test/python/api/test_api_polygons_v1.py @@ -2,7 +2,7 @@ # # 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. @@ -18,8 +18,8 @@ import psycopg2.extras 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(): diff --git a/test/python/api/test_api_reverse.py b/test/python/api/test_api_reverse.py index 8f8b2dba..ff7f402b 100644 --- a/test/python/api/test_api_reverse.py +++ b/test/python/api/test_api_reverse.py @@ -2,7 +2,7 @@ # # 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. @@ -14,7 +14,7 @@ import json import pytest -import nominatim.api as napi +import nominatim_api as napi API_OPTIONS = {'reverse'} diff --git a/test/python/api/test_api_search.py b/test/python/api/test_api_search.py index 25f63bb8..54138e24 100644 --- a/test/python/api/test_api_search.py +++ b/test/python/api/test_api_search.py @@ -2,7 +2,7 @@ # # 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. @@ -16,8 +16,8 @@ import pytest 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'} diff --git a/test/python/api/test_api_status.py b/test/python/api/test_api_status.py index 2acde2ec..2b211611 100644 --- a/test/python/api/test_api_status.py +++ b/test/python/api/test_api_status.py @@ -1,8 +1,8 @@ -# SPDX-License-Identifier: GPL-2.0-only +# SPDX-License-Identifier: GPL-3.0-or-later # # This file is part of Nominatim. (https://nominatim.org) # -# Copyright (C) 2023 by the Nominatim developer community. +# Copyright (C) 2024 by the Nominatim developer community. # For a full list of authors see the git log. """ Tests for the status API call. @@ -11,8 +11,9 @@ from pathlib import Path 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) @@ -20,7 +21,7 @@ def test_status_no_extra_info(apiobj, frontend): 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 @@ -37,7 +38,7 @@ def test_status_full(apiobj, frontend): 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 @@ -51,6 +52,6 @@ def test_status_database_not_found(monkeypatch): 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 diff --git a/test/python/api/test_api_types.py b/test/python/api/test_api_types.py index 6a095bcb..2faba33d 100644 --- a/test/python/api/test_api_types.py +++ b/test/python/api/test_api_types.py @@ -2,15 +2,15 @@ # # 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({}) diff --git a/test/python/api/test_export.py b/test/python/api/test_export.py index 0fd52748..1d9bf90f 100644 --- a/test/python/api/test_export.py +++ b/test/python/api/test_export.py @@ -2,22 +2,22 @@ # # 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 diff --git a/test/python/api/test_helpers_v1.py b/test/python/api/test_helpers_v1.py index e4862b0d..3a6a9a0b 100644 --- a/test/python/api/test_helpers_v1.py +++ b/test/python/api/test_helpers_v1.py @@ -2,14 +2,14 @@ # # 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', diff --git a/test/python/api/test_localization.py b/test/python/api/test_localization.py index b704e5a9..21fa72c8 100644 --- a/test/python/api/test_localization.py +++ b/test/python/api/test_localization.py @@ -2,14 +2,14 @@ # # 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']) diff --git a/test/python/api/test_result_formatting_v1.py b/test/python/api/test_result_formatting_v1.py index 0ff834a4..6ac1bb6d 100644 --- a/test/python/api/test_result_formatting_v1.py +++ b/test/python/api/test_result_formatting_v1.py @@ -1,8 +1,8 @@ -# SPDX-License-Identifier: GPL-2.0-only +# SPDX-License-Identifier: GPL-3.0-or-later # # This file is part of Nominatim. (https://nominatim.org) # -# Copyright (C) 2023 by the Nominatim developer community. +# Copyright (C) 2024 by the Nominatim developer community. # For a full list of authors see the git log. """ Tests for formatting results for the V1 API. @@ -15,9 +15,8 @@ import json 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'} @@ -49,7 +48,8 @@ def test_status_format_json_minimal(): 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(): @@ -59,7 +59,8 @@ 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 diff --git a/test/python/api/test_result_formatting_v1_reverse.py b/test/python/api/test_result_formatting_v1_reverse.py index d9d43953..1248fa9e 100644 --- a/test/python/api/test_result_formatting_v1_reverse.py +++ b/test/python/api/test_result_formatting_v1_reverse.py @@ -1,8 +1,8 @@ -# SPDX-License-Identifier: GPL-2.0-only +# SPDX-License-Identifier: GPL-3.0-or-later # # This file is part of Nominatim. (https://nominatim.org) # -# Copyright (C) 2023 by the Nominatim developer community. +# Copyright (C) 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. @@ -15,8 +15,8 @@ import xml.etree.ElementTree as ET 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'] diff --git a/test/python/api/test_results.py b/test/python/api/test_results.py index 54a54549..f0bfa163 100644 --- a/test/python/api/test_results.py +++ b/test/python/api/test_results.py @@ -2,7 +2,7 @@ # # 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. @@ -15,8 +15,8 @@ import pytest_asyncio 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') diff --git a/test/python/api/test_server_glue_v1.py b/test/python/api/test_server_glue_v1.py index 5a7430f4..5716f245 100644 --- a/test/python/api/test_server_glue_v1.py +++ b/test/python/api/test_server_glue_v1.py @@ -2,7 +2,7 @@ # # 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. @@ -15,9 +15,9 @@ import pytest 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() diff --git a/test/python/api/test_warm.py b/test/python/api/test_warm.py index af48732a..304943f1 100644 --- a/test/python/api/test_warm.py +++ b/test/python/api/test_warm.py @@ -2,14 +2,14 @@ # # 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): @@ -27,7 +27,7 @@ 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) diff --git a/test/python/cli/conftest.py b/test/python/cli/conftest.py index 28aba597..1e3ca8ab 100644 --- a/test/python/cli/conftest.py +++ b/test/python/cli/conftest.py @@ -1,12 +1,12 @@ -# 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 @@ -51,9 +51,9 @@ def cli_call(): 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 @@ -72,9 +72,9 @@ def mock_func_factory(monkeypatch): @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 diff --git a/test/python/cli/test_cli.py b/test/python/cli/test_cli.py index 12a58d07..688afb7c 100644 --- a/test/python/cli/test_cli.py +++ b/test/python/cli/test_cli.py @@ -1,8 +1,8 @@ -# SPDX-License-Identifier: GPL-2.0-only +# SPDX-License-Identifier: GPL-3.0-or-later # # This file is part of Nominatim. (https://nominatim.org) # -# Copyright (C) 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. @@ -14,9 +14,9 @@ the actual functions. 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): @@ -37,7 +37,7 @@ def test_cli_version(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 @@ -45,7 +45,7 @@ def test_cli_add_data_file_command(cli_call, mock_func_factory, name, oid): @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 @@ -53,7 +53,7 @@ def test_cli_add_data_object_command(cli_call, mock_func_factory, name, oid): 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 @@ -61,7 +61,7 @@ def test_cli_add_data_tiger_data(cli_call, cli_tokenizer_mock, mock_func_factory 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 @@ -110,8 +110,8 @@ class TestCliWithDb: 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 @@ -127,9 +127,9 @@ class TestCliWithDb: 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 @@ -139,7 +139,7 @@ class TestCliWithDb: 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') @@ -147,7 +147,7 @@ class TestCliWithDb: 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()) diff --git a/test/python/cli/test_cmd_admin.py b/test/python/cli/test_cmd_admin.py index cc80c19a..7b0b9cd4 100644 --- a/test/python/cli/test_cmd_admin.py +++ b/test/python/cli/test_cmd_admin.py @@ -1,8 +1,8 @@ -# SPDX-License-Identifier: GPL-2.0-only +# SPDX-License-Identifier: GPL-3.0-or-later # # This file is part of Nominatim. (https://nominatim.org) # -# Copyright (C) 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. @@ -13,34 +13,34 @@ the actual functions. """ 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 @@ -54,7 +54,7 @@ class TestCliAdminWithDb: @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 diff --git a/test/python/cli/test_cmd_api.py b/test/python/cli/test_cmd_api.py index ca160a35..811eadfe 100644 --- a/test/python/cli/test_cmd_api.py +++ b/test/python/cli/test_cmd_api.py @@ -1,8 +1,8 @@ -# SPDX-License-Identifier: GPL-2.0-only +# SPDX-License-Identifier: GPL-3.0-or-later # # This file is part of Nominatim. (https://nominatim.org) # -# Copyright (C) 2023 by the Nominatim developer community. +# Copyright (C) 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. @@ -10,8 +10,8 @@ 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: diff --git a/test/python/cli/test_cmd_import.py b/test/python/cli/test_cmd_import.py index d098e27e..9c2400c5 100644 --- a/test/python/cli/test_cmd_import.py +++ b/test/python/cli/test_cmd_import.py @@ -1,20 +1,20 @@ -# 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: @@ -36,31 +36,31 @@ 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 @@ -74,14 +74,14 @@ class TestCliImportWithDb: 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 @@ -94,11 +94,11 @@ class TestCliImportWithDb: 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 @@ -112,10 +112,10 @@ class TestCliImportWithDb: 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 diff --git a/test/python/cli/test_cmd_refresh.py b/test/python/cli/test_cmd_refresh.py index 1179f22c..01b1f6e0 100644 --- a/test/python/cli/test_cmd_refresh.py +++ b/test/python/cli/test_cmd_refresh.py @@ -1,17 +1,17 @@ -# 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: @@ -28,8 +28,8 @@ 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 @@ -46,8 +46,8 @@ class TestRefresh: 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 @@ -60,7 +60,7 @@ class TestRefresh: 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 @@ -78,8 +78,8 @@ class TestRefresh: 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 @@ -88,9 +88,9 @@ class TestRefresh: 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') @@ -105,7 +105,7 @@ class TestRefresh: ('--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 @@ -115,7 +115,7 @@ class TestRefresh: @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 diff --git a/test/python/cli/test_cmd_replication.py b/test/python/cli/test_cmd_replication.py index a22d077a..ff900e58 100644 --- a/test/python/cli/test_cmd_replication.py +++ b/test/python/cli/test_cmd_replication.py @@ -1,8 +1,8 @@ -# SPDX-License-Identifier: GPL-2.0-only +# SPDX-License-Identifier: GPL-3.0-or-later # # This file is part of Nominatim. (https://nominatim.org) # -# Copyright (C) 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. @@ -12,11 +12,11 @@ import time 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): @@ -32,9 +32,9 @@ 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 @@ -48,12 +48,12 @@ def init_status(temp_db_conn, status_table): @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: @@ -66,7 +66,7 @@ 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 @@ -78,10 +78,10 @@ class TestCliReplication: (('--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 @@ -121,7 +121,7 @@ class TestCliReplication: @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 @@ -133,8 +133,8 @@ class TestCliReplication: 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() @@ -144,8 +144,8 @@ class TestCliReplication: 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') diff --git a/test/python/config/test_config.py b/test/python/config/test_config.py index ff8b587d..bb649d23 100644 --- a/test/python/config/test_config.py +++ b/test/python/config/test_config.py @@ -1,8 +1,8 @@ -# SPDX-License-Identifier: GPL-2.0-only +# SPDX-License-Identifier: GPL-3.0-or-later # # This file is part of Nominatim. (https://nominatim.org) # -# Copyright (C) 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. @@ -10,8 +10,8 @@ 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(): diff --git a/test/python/config/test_config_load_module.py b/test/python/config/test_config_load_module.py index 7bc91fd7..06bfff06 100644 --- a/test/python/config/test_config_load_module.py +++ b/test/python/config/test_config_load_module.py @@ -1,8 +1,8 @@ -# SPDX-License-Identifier: GPL-2.0-only +# SPDX-License-Identifier: GPL-3.0-or-later # # This file is part of Nominatim. (https://nominatim.org) # -# Copyright (C) 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. @@ -12,7 +12,7 @@ import sys import pytest -from nominatim.config import Configuration +from nominatim_core.config import Configuration @pytest.fixture def test_config(src_dir, tmp_path): @@ -27,12 +27,12 @@ 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) diff --git a/test/python/conftest.py b/test/python/conftest.py index 31463746..c9e8f048 100644 --- a/test/python/conftest.py +++ b/test/python/conftest.py @@ -1,8 +1,8 @@ -# SPDX-License-Identifier: GPL-2.0-only +# SPDX-License-Identifier: GPL-3.0-or-later # # This file is part of Nominatim. (https://nominatim.org) # -# Copyright (C) 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 @@ -13,12 +13,12 @@ import pytest # 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 @@ -229,7 +229,8 @@ def tokenizer_mock(monkeypatch, property_table): 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(): diff --git a/test/python/cursor.py b/test/python/cursor.py index 73b83b1d..7d586b3c 100644 --- a/test/python/cursor.py +++ b/test/python/cursor.py @@ -1,8 +1,8 @@ -# SPDX-License-Identifier: GPL-2.0-only +# SPDX-License-Identifier: GPL-3.0-or-later # # This file is part of Nominatim. (https://nominatim.org) # -# Copyright (C) 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. diff --git a/test/python/data/test_country_info.py b/test/python/data/test_country_info.py index 2234f40d..14b306bb 100644 --- a/test/python/data/test_country_info.py +++ b/test/python/data/test_country_info.py @@ -1,8 +1,8 @@ -# SPDX-License-Identifier: GPL-2.0-only +# SPDX-License-Identifier: GPL-3.0-or-later # # This file is part of Nominatim. (https://nominatim.org) # -# Copyright (C) 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. @@ -10,7 +10,7 @@ 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): diff --git a/test/python/db/test_async_connection.py b/test/python/db/test_async_connection.py index 9765f279..019f53c1 100644 --- a/test/python/db/test_async_connection.py +++ b/test/python/db/test_async_connection.py @@ -1,8 +1,8 @@ -# SPDX-License-Identifier: GPL-2.0-only +# SPDX-License-Identifier: GPL-3.0-or-later # # This file is part of Nominatim. (https://nominatim.org) # -# Copyright (C) 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. @@ -13,7 +13,7 @@ import concurrent.futures import pytest import psycopg2 -from nominatim.db.async_connection import DBConnection, DeadlockHandler +from nominatim_core.db.async_connection import DBConnection, DeadlockHandler @pytest.fixture diff --git a/test/python/db/test_connection.py b/test/python/db/test_connection.py index dbba6109..7ecf3bb4 100644 --- a/test/python/db/test_connection.py +++ b/test/python/db/test_connection.py @@ -1,8 +1,8 @@ -# SPDX-License-Identifier: GPL-2.0-only +# SPDX-License-Identifier: GPL-3.0-or-later # # This file is part of Nominatim. (https://nominatim.org) # -# Copyright (C) 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. @@ -10,7 +10,7 @@ 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): diff --git a/test/python/db/test_properties.py b/test/python/db/test_properties.py index cdd1b7af..aca1b1f8 100644 --- a/test/python/db/test_properties.py +++ b/test/python/db/test_properties.py @@ -1,15 +1,15 @@ -# 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): diff --git a/test/python/db/test_sql_preprocessor.py b/test/python/db/test_sql_preprocessor.py index 9997367c..1ef6bc88 100644 --- a/test/python/db/test_sql_preprocessor.py +++ b/test/python/db/test_sql_preprocessor.py @@ -1,15 +1,15 @@ -# 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): diff --git a/test/python/db/test_status.py b/test/python/db/test_status.py index 05fb2c7f..67cd22e9 100644 --- a/test/python/db/test_status.py +++ b/test/python/db/test_status.py @@ -1,8 +1,8 @@ -# SPDX-License-Identifier: GPL-2.0-only +# SPDX-License-Identifier: GPL-3.0-or-later # # This file is part of Nominatim. (https://nominatim.org) # -# Copyright (C) 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. @@ -11,8 +11,8 @@ import datetime as dt 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 = """\ @@ -22,7 +22,7 @@ OSM_NODE_DATA = """\ """ 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) @@ -36,7 +36,7 @@ def test_compute_database_date_from_osm2pgsql(table_factory, temp_db_conn, offli 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') @@ -44,12 +44,12 @@ def test_compute_database_date_from_osm2pgsql_nodata(table_factory, temp_db_conn 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): @@ -60,9 +60,9 @@ 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') @@ -76,15 +76,15 @@ def test_compute_database_broken_api(monkeypatch, place_row, temp_db_conn): requested_url.append(url) return ' ' '; diff --git a/test/python/tokenizer/token_analysis/test_generic.py b/test/python/tokenizer/token_analysis/test_generic.py index 976bbd1b..277758e1 100644 --- a/test/python/tokenizer/token_analysis/test_generic.py +++ b/test/python/tokenizer/token_analysis/test_generic.py @@ -1,8 +1,8 @@ -# SPDX-License-Identifier: GPL-2.0-only +# SPDX-License-Identifier: GPL-3.0-or-later # # This file is part of Nominatim. (https://nominatim.org) # -# Copyright (C) 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. @@ -11,8 +11,8 @@ import pytest 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 (); '🜳' > ' '; diff --git a/test/python/tokenizer/token_analysis/test_generic_mutation.py b/test/python/tokenizer/token_analysis/test_generic_mutation.py index ff4c3a74..ea813bdc 100644 --- a/test/python/tokenizer/token_analysis/test_generic_mutation.py +++ b/test/python/tokenizer/token_analysis/test_generic_mutation.py @@ -1,8 +1,8 @@ -# SPDX-License-Identifier: GPL-2.0-only +# SPDX-License-Identifier: GPL-3.0-or-later # # This file is part of Nominatim. (https://nominatim.org) # -# Copyright (C) 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. @@ -11,8 +11,8 @@ import pytest 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:]] >; diff --git a/test/python/tools/conftest.py b/test/python/tools/conftest.py index 6dd5f2d6..60b25c3b 100644 --- a/test/python/tools/conftest.py +++ b/test/python/tools/conftest.py @@ -1,8 +1,8 @@ -# SPDX-License-Identifier: GPL-2.0-only +# SPDX-License-Identifier: GPL-3.0-or-later # # This file is part of Nominatim. (https://nominatim.org) # -# Copyright (C) 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 diff --git a/test/python/tools/test_add_osm_data.py b/test/python/tools/test_add_osm_data.py index a9bf9b2a..c5aaaaae 100644 --- a/test/python/tools/test_add_osm_data.py +++ b/test/python/tools/test_add_osm_data.py @@ -1,8 +1,8 @@ -# SPDX-License-Identifier: GPL-2.0-only +# SPDX-License-Identifier: GPL-3.0-or-later # # This file is part of Nominatim. (https://nominatim.org) # -# Copyright (C) 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. @@ -11,7 +11,7 @@ from pathlib import Path import pytest -from nominatim.tools import add_osm_data +from nominatim_db.tools import add_osm_data class CaptureGetUrl: diff --git a/test/python/tools/test_admin.py b/test/python/tools/test_admin.py index ae5944af..a59f3d9d 100644 --- a/test/python/tools/test_admin.py +++ b/test/python/tools/test_admin.py @@ -1,18 +1,18 @@ -# 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): diff --git a/test/python/tools/test_check_database.py b/test/python/tools/test_check_database.py index 65f05903..886bd75b 100644 --- a/test/python/tools/test_check_database.py +++ b/test/python/tools/test_check_database.py @@ -1,16 +1,16 @@ -# 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') @@ -32,7 +32,7 @@ def test_check_connection_bad(def_config): 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): diff --git a/test/python/tools/test_database_import.py b/test/python/tools/test_database_import.py index 68d19a07..a95f3d98 100644 --- a/test/python/tools/test_database_import.py +++ b/test/python/tools/test_database_import.py @@ -1,8 +1,8 @@ -# SPDX-License-Identifier: GPL-2.0-only +# SPDX-License-Identifier: GPL-3.0-or-later # # This file is part of Nominatim. (https://nominatim.org) # -# Copyright (C) 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. @@ -13,8 +13,8 @@ from contextlib import closing 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' diff --git a/test/python/tools/test_exec_utils.py b/test/python/tools/test_exec_utils.py index b4439c12..50bec7e6 100644 --- a/test/python/tools/test_exec_utils.py +++ b/test/python/tools/test_exec_utils.py @@ -1,8 +1,8 @@ -# SPDX-License-Identifier: GPL-2.0-only +# SPDX-License-Identifier: GPL-3.0-or-later # # This file is part of Nominatim. (https://nominatim.org) # -# Copyright (C) 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. @@ -12,12 +12,8 @@ import subprocess 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 diff --git a/test/python/tools/test_freeze.py b/test/python/tools/test_freeze.py index 0d44501a..f64850fb 100644 --- a/test/python/tools/test_freeze.py +++ b/test/python/tools/test_freeze.py @@ -1,13 +1,13 @@ -# 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', diff --git a/test/python/tools/test_import_special_phrases.py b/test/python/tools/test_import_special_phrases.py index 75a6a066..91c9fc15 100644 --- a/test/python/tools/test_import_special_phrases.py +++ b/test/python/tools/test_import_special_phrases.py @@ -1,8 +1,8 @@ -# SPDX-License-Identifier: GPL-2.0-only +# SPDX-License-Identifier: GPL-3.0-or-later # # This file is part of Nominatim. (https://nominatim.org) # -# Copyright (C) 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 @@ -10,10 +10,10 @@ """ 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 @@ -182,7 +182,7 @@ def test_import_phrases(monkeypatch, temp_db_conn, def_config, sp_importer, 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() diff --git a/test/python/tools/test_migration.py b/test/python/tools/test_migration.py index 88c7a4dd..d33ff422 100644 --- a/test/python/tools/test_migration.py +++ b/test/python/tools/test_migration.py @@ -1,8 +1,8 @@ -# SPDX-License-Identifier: GPL-2.0-only +# SPDX-License-Identifier: GPL-3.0-or-later # # This file is part of Nominatim. (https://nominatim.org) # -# Copyright (C) 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 @@ -10,9 +10,9 @@ 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 @@ -66,17 +66,17 @@ def test_set_up_migration_for_36(temp_db_with_extensions, temp_db_cursor, 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(**_): @@ -90,14 +90,13 @@ def test_run_single_migration(def_config, temp_db_cursor, property_table, 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 diff --git a/test/python/tools/test_postcodes.py b/test/python/tools/test_postcodes.py index f5e8f3de..febb2271 100644 --- a/test/python/tools/test_postcodes.py +++ b/test/python/tools/test_postcodes.py @@ -1,8 +1,8 @@ -# SPDX-License-Identifier: GPL-2.0-only +# SPDX-License-Identifier: GPL-3.0-or-later # # This file is part of Nominatim. (https://nominatim.org) # -# Copyright (C) 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. @@ -11,8 +11,8 @@ import subprocess 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: diff --git a/test/python/tools/test_refresh.py b/test/python/tools/test_refresh.py index f7621ab1..50ff6398 100644 --- a/test/python/tools/test_refresh.py +++ b/test/python/tools/test_refresh.py @@ -1,8 +1,8 @@ -# SPDX-License-Identifier: GPL-2.0-only +# SPDX-License-Identifier: GPL-3.0-or-later # # This file is part of Nominatim. (https://nominatim.org) # -# Copyright (C) 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. @@ -11,7 +11,7 @@ from pathlib import Path 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 diff --git a/test/python/tools/test_refresh_address_levels.py b/test/python/tools/test_refresh_address_levels.py index e35a8190..6e094cdc 100644 --- a/test/python/tools/test_refresh_address_levels.py +++ b/test/python/tools/test_refresh_address_levels.py @@ -1,8 +1,8 @@ -# SPDX-License-Identifier: GPL-2.0-only +# SPDX-License-Identifier: GPL-3.0-or-later # # This file is part of Nominatim. (https://nominatim.org) # -# Copyright (C) 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. @@ -12,7 +12,7 @@ from pathlib import Path 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) diff --git a/test/python/tools/test_refresh_create_functions.py b/test/python/tools/test_refresh_create_functions.py index 8d26e755..984a1610 100644 --- a/test/python/tools/test_refresh_create_functions.py +++ b/test/python/tools/test_refresh_create_functions.py @@ -1,15 +1,15 @@ -# 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) diff --git a/test/python/tools/test_refresh_setup_website.py b/test/python/tools/test_refresh_setup_website.py index 52b857c4..fe29dd52 100644 --- a/test/python/tools/test_refresh_setup_website.py +++ b/test/python/tools/test_refresh_setup_website.py @@ -1,8 +1,8 @@ -# SPDX-License-Identifier: GPL-2.0-only +# SPDX-License-Identifier: GPL-3.0-or-later # # This file is part of Nominatim. (https://nominatim.org) # -# Copyright (C) 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. @@ -11,7 +11,7 @@ import subprocess import pytest -from nominatim.tools import refresh +from nominatim_db.tools import refresh @pytest.fixture def test_script(tmp_path): diff --git a/test/python/tools/test_replication.py b/test/python/tools/test_replication.py index 7a7340ae..4cd53ae3 100644 --- a/test/python/tools/test_replication.py +++ b/test/python/tools/test_replication.py @@ -1,8 +1,8 @@ -# SPDX-License-Identifier: GPL-2.0-only +# SPDX-License-Identifier: GPL-3.0-or-later # # This file is part of Nominatim. (https://nominatim.org) # -# Copyright (C) 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. @@ -13,9 +13,9 @@ import time 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 = """\ @@ -33,21 +33,21 @@ def setup_status_table(status_table): 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) @@ -59,22 +59,22 @@ def test_init_replication_success(monkeypatch, place_row, temp_db_conn, temp_db_ ### 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)]) @@ -83,11 +83,11 @@ def test_check_for_updates_no_new_data(monkeypatch, temp_db_conn, 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 @@ -102,29 +102,29 @@ def update_options(tmpdir): 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 @@ -133,15 +133,15 @@ def test_update_no_data_sleep(monkeypatch, temp_db_conn, dsn, update_options): 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 diff --git a/test/python/tools/test_sp_csv_loader.py b/test/python/tools/test_sp_csv_loader.py index 49d5a853..e6185fd6 100644 --- a/test/python/tools/test_sp_csv_loader.py +++ b/test/python/tools/test_sp_csv_loader.py @@ -1,17 +1,17 @@ -# 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): diff --git a/test/python/tools/test_sp_wiki_loader.py b/test/python/tools/test_sp_wiki_loader.py index 2f47734e..5c37c32f 100644 --- a/test/python/tools/test_sp_wiki_loader.py +++ b/test/python/tools/test_sp_wiki_loader.py @@ -1,14 +1,14 @@ -# 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 @@ -23,7 +23,7 @@ def sp_wiki_loader(src_dir, monkeypatch, def_config): 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 diff --git a/test/python/tools/test_tiger_data.py b/test/python/tools/test_tiger_data.py index 4b1a1b89..396fe069 100644 --- a/test/python/tools/test_tiger_data.py +++ b/test/python/tools/test_tiger_data.py @@ -1,8 +1,8 @@ -# SPDX-License-Identifier: GPL-2.0-only +# SPDX-License-Identifier: GPL-3.0-or-later # # This file is part of Nominatim. (https://nominatim.org) # -# Copyright (C) 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 @@ -12,8 +12,8 @@ from textwrap import dedent 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: diff --git a/test/python/utils/test_centroid.py b/test/python/utils/test_centroid.py index 63d967e7..d91edae2 100644 --- a/test/python/utils/test_centroid.py +++ b/test/python/utils/test_centroid.py @@ -1,15 +1,15 @@ -# 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() diff --git a/test/python/utils/test_json_writer.py b/test/python/utils/test_json_writer.py index 08a091f4..ff542f04 100644 --- a/test/python/utils/test_json_writer.py +++ b/test/python/utils/test_json_writer.py @@ -2,7 +2,7 @@ # # 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. @@ -11,7 +11,7 @@ import json 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'),