diff --git a/.pylint.toml b/.pylint.toml index 06390614..3881fdc3 100644 --- a/.pylint.toml +++ b/.pylint.toml @@ -8,6 +8,7 @@ load-plugins = [ "pylint.extensions.typing", "pylint_plugins.definition_order", "pylint_plugins.import_order", + "pylint_plugins.type_annotations", ] [tool.pylint.classes] diff --git a/ahriman-core/src/ahriman/models/event.py b/ahriman-core/src/ahriman/models/event.py index ec8b97f9..bc873e09 100644 --- a/ahriman-core/src/ahriman/models/event.py +++ b/ahriman-core/src/ahriman/models/event.py @@ -61,7 +61,7 @@ class Event: """ def __init__(self, event: str | EventType, object_id: str, message: str | None = None, created: int | None = None, - **kwargs: Any): + **kwargs: Any) -> None: """ Args: event(str | EventType): event type diff --git a/ahriman-core/tests/ahriman/application/application/test_application.py b/ahriman-core/tests/ahriman/application/application/test_application.py index 5023dd4e..317c03b8 100644 --- a/ahriman-core/tests/ahriman/application/application/test_application.py +++ b/ahriman-core/tests/ahriman/application/application/test_application.py @@ -75,7 +75,7 @@ def test_with_dependencies(application: Application, package_ahriman: Package, p mock.packages_full = [package_base] return mock - def get_package(name: str | Path, *args: Any, **kwargs: Any) -> Package: + def get_package(name: str | Path, *_args: Any, **_kwargs: Any) -> Package: name = name if isinstance(name, str) else name.name return packages[name] diff --git a/ahriman-core/tests/ahriman/application/handlers/test_handler_hold.py b/ahriman-core/tests/ahriman/application/handlers/test_handler_hold.py index f63e3f8c..121f864b 100644 --- a/ahriman-core/tests/ahriman/application/handlers/test_handler_hold.py +++ b/ahriman-core/tests/ahriman/application/handlers/test_handler_hold.py @@ -1,5 +1,4 @@ import argparse -import pytest from pytest_mock import MockerFixture diff --git a/ahriman-core/tests/ahriman/application/handlers/test_handler_patch.py b/ahriman-core/tests/ahriman/application/handlers/test_handler_patch.py index 3e6c9ff6..750e5ee7 100644 --- a/ahriman-core/tests/ahriman/application/handlers/test_handler_patch.py +++ b/ahriman-core/tests/ahriman/application/handlers/test_handler_patch.py @@ -169,7 +169,7 @@ def test_patch_set_list(application: Application, mocker: MockerFixture) -> None Patch.patch_set_list(application, "ahriman", ["version"], False) get_mock.assert_called_once_with("ahriman", None) print_mock.assert_called_once_with(verbose=True, log_fn=pytest.helpers.anyvar(int), separator=" = ") - check_mock.assert_called_once_with(False, [PkgbuildPatch(key='version', value='value')]) + check_mock.assert_called_once_with(False, [PkgbuildPatch(key="version", value="value")]) def test_patch_set_list_all(application: Application, mocker: MockerFixture) -> None: @@ -184,7 +184,7 @@ def test_patch_set_list_all(application: Application, mocker: MockerFixture) -> Patch.patch_set_list(application, "ahriman", None, False) get_mock.assert_called_once_with("ahriman", None) print_mock.assert_called_once_with(verbose=True, log_fn=pytest.helpers.anyvar(int), separator=" = ") - check_mock.assert_called_once_with(False, [PkgbuildPatch(key=None, value='patch')]) + check_mock.assert_called_once_with(False, [PkgbuildPatch(key=None, value="patch")]) def test_patch_set_list_empty_exception(application: Application, mocker: MockerFixture) -> None: diff --git a/ahriman-core/tests/ahriman/application/handlers/test_handler_setup.py b/ahriman-core/tests/ahriman/application/handlers/test_handler_setup.py index b71e40b3..6cbd6e5b 100644 --- a/ahriman-core/tests/ahriman/application/handlers/test_handler_setup.py +++ b/ahriman-core/tests/ahriman/application/handlers/test_handler_setup.py @@ -244,7 +244,7 @@ def test_configuration_create_directory(configuration: Configuration, mocker: Mo """ must create writable directory for includes """ - configuration.set_option("settings", "include", f"/path1 /path2 /path3") + configuration.set_option("settings", "include", "/path1 /path2 /path3") mkdir_mock = mocker.patch("ahriman.models.repository_paths.RepositoryPaths.ensure_exists", side_effect=[OSError, "/path2", "/path3"]) access_mock = mocker.patch("os.access", side_effect=[False, True]) diff --git a/ahriman-core/tests/ahriman/application/handlers/test_handler_update.py b/ahriman-core/tests/ahriman/application/handlers/test_handler_update.py index fb92c71f..b0557215 100644 --- a/ahriman-core/tests/ahriman/application/handlers/test_handler_update.py +++ b/ahriman-core/tests/ahriman/application/handlers/test_handler_update.py @@ -8,8 +8,8 @@ from ahriman.application.application import Application from ahriman.application.handlers.update import Update from ahriman.core.configuration import Configuration from ahriman.core.repository import Repository -from ahriman.models.package import Package from ahriman.models.build_plan import BuildPlan, BuildPlanReason +from ahriman.models.package import Package from ahriman.models.packagers import Packagers from ahriman.models.result import Result diff --git a/ahriman-core/tests/ahriman/conftest.py b/ahriman-core/tests/ahriman/conftest.py index 7d81b71e..d2568ce4 100644 --- a/ahriman-core/tests/ahriman/conftest.py +++ b/ahriman-core/tests/ahriman/conftest.py @@ -107,10 +107,10 @@ def passwd() -> MagicMock: Returns: MagicMock: passwd structure test instance """ - passwd = MagicMock() - passwd.pw_dir = "home" - passwd.pw_name = "ahriman" - return passwd + mock = MagicMock() + mock.pw_dir = "home" + mock.pw_name = "ahriman" + return mock @pytest.fixture diff --git a/ahriman-core/tests/ahriman/core/alpm/conftest.py b/ahriman-core/tests/ahriman/core/alpm/conftest.py index 9447b9a6..5a7af0a2 100644 --- a/ahriman-core/tests/ahriman/core/alpm/conftest.py +++ b/ahriman-core/tests/ahriman/core/alpm/conftest.py @@ -1,7 +1,7 @@ import pytest -from ahriman.core.alpm.pacman_database import PacmanDatabase from ahriman.core.alpm.pacman import Pacman +from ahriman.core.alpm.pacman_database import PacmanDatabase from ahriman.core.configuration import Configuration diff --git a/ahriman-core/tests/ahriman/core/alpm/remote/test_remote.py b/ahriman-core/tests/ahriman/core/alpm/remote/test_remote.py index 2674a854..b34db647 100644 --- a/ahriman-core/tests/ahriman/core/alpm/remote/test_remote.py +++ b/ahriman-core/tests/ahriman/core/alpm/remote/test_remote.py @@ -76,7 +76,7 @@ def test_multisearch_empty(pacman: Pacman, mocker: MockerFixture) -> None: terms = ["it", "is"] search_mock = mocker.patch("ahriman.core.alpm.remote.Remote.package_search") - assert Remote.multisearch(*terms, pacman=pacman) == [] + assert not Remote.multisearch(*terms, pacman=pacman) search_mock.assert_not_called() diff --git a/ahriman-core/tests/ahriman/core/build_tools/test_sources.py b/ahriman-core/tests/ahriman/core/build_tools/test_sources.py index cecbf958..a10e50be 100644 --- a/ahriman-core/tests/ahriman/core/build_tools/test_sources.py +++ b/ahriman-core/tests/ahriman/core/build_tools/test_sources.py @@ -61,7 +61,7 @@ def test_extend_architectures_any(mocker: MockerFixture) -> None: """ mocker.patch("pathlib.Path.is_file", return_value=True) mocker.patch("ahriman.models.pkgbuild.Pkgbuild.supported_architectures", return_value={"any"}) - assert Sources.extend_architectures(Path("local"), "i686") == [] + assert not Sources.extend_architectures(Path("local"), "i686") def test_fetch_empty(remote_source: RemoteSource, mocker: MockerFixture) -> None: @@ -347,7 +347,7 @@ def test_add_skip(sources: Sources, mocker: MockerFixture) -> None: check_output_mock.assert_not_called() -def test_add_force(sources: Sources, tmp_path: Path, mocker: MockerFixture) -> None: +def test_add_force(sources: Sources, mocker: MockerFixture) -> None: """ must add files to git with --force flag """ diff --git a/ahriman-core/tests/ahriman/core/configuration/test_configuration.py b/ahriman-core/tests/ahriman/core/configuration/test_configuration.py index 6abf7fcf..7d095379 100644 --- a/ahriman-core/tests/ahriman/core/configuration/test_configuration.py +++ b/ahriman-core/tests/ahriman/core/configuration/test_configuration.py @@ -1,6 +1,6 @@ import configparser -import pytest import os +import pytest from io import StringIO from pathlib import Path diff --git a/ahriman-core/tests/ahriman/core/database/migrations/test_m016_archive.py b/ahriman-core/tests/ahriman/core/database/migrations/test_m016_archive.py index 1d7ac8b6..d80d8eef 100644 --- a/ahriman-core/tests/ahriman/core/database/migrations/test_m016_archive.py +++ b/ahriman-core/tests/ahriman/core/database/migrations/test_m016_archive.py @@ -1,5 +1,3 @@ -import pytest - from dataclasses import replace from pathlib import Path from pytest_mock import MockerFixture @@ -38,7 +36,7 @@ def test_move_packages(repository_paths: RepositoryPaths, package_ahriman: Packa must move packages to the archive directory """ - def is_file(self: Path, *args: Any, **kwargs: Any) -> bool: + def is_file(self: Path, **_: Any) -> bool: return "file" in self.name mocker.patch("pathlib.Path.iterdir", return_value=[ diff --git a/ahriman-core/tests/ahriman/core/database/operations/test_package_operations.py b/ahriman-core/tests/ahriman/core/database/operations/test_package_operations.py index 6cc1306c..9bae93b9 100644 --- a/ahriman-core/tests/ahriman/core/database/operations/test_package_operations.py +++ b/ahriman-core/tests/ahriman/core/database/operations/test_package_operations.py @@ -144,7 +144,7 @@ def test_package_remove(database: SQLite, package_ahriman: Package, mocker: Mock database._repository_id) -def test_package_update(database: SQLite, package_ahriman: Package, mocker: MockerFixture): +def test_package_update(database: SQLite, package_ahriman: Package, mocker: MockerFixture) -> None: """ must update package status """ diff --git a/ahriman-core/tests/ahriman/core/formatters/test_printer.py b/ahriman-core/tests/ahriman/core/formatters/test_printer.py index cad27b44..c6b295eb 100644 --- a/ahriman-core/tests/ahriman/core/formatters/test_printer.py +++ b/ahriman-core/tests/ahriman/core/formatters/test_printer.py @@ -69,7 +69,7 @@ def test_properties() -> None: """ must return empty properties list """ - assert Printer().properties() == [] + assert not Printer().properties() def test_title() -> None: diff --git a/ahriman-core/tests/ahriman/core/http/test_sync_http_client.py b/ahriman-core/tests/ahriman/core/http/test_sync_http_client.py index 86daae20..c0c5b7f9 100644 --- a/ahriman-core/tests/ahriman/core/http/test_sync_http_client.py +++ b/ahriman-core/tests/ahriman/core/http/test_sync_http_client.py @@ -98,7 +98,7 @@ def test_headers() -> None: """ must return empty additional headers """ - assert SyncHttpClient().headers() == {} + assert not SyncHttpClient().headers() def test_make_request(mocker: MockerFixture) -> None: diff --git a/ahriman-core/tests/ahriman/core/report/test_email.py b/ahriman-core/tests/ahriman/core/report/test_email.py index 06fcfa9c..bd1e89db 100644 --- a/ahriman-core/tests/ahriman/core/report/test_email.py +++ b/ahriman-core/tests/ahriman/core/report/test_email.py @@ -1,6 +1,5 @@ -import smtplib - import pytest +import smtplib from pytest_mock import MockerFixture diff --git a/ahriman-core/tests/ahriman/core/status/test_event_bus.py b/ahriman-core/tests/ahriman/core/status/test_event_bus.py index 2e44e3da..a04f5812 100644 --- a/ahriman-core/tests/ahriman/core/status/test_event_bus.py +++ b/ahriman-core/tests/ahriman/core/status/test_event_bus.py @@ -78,7 +78,7 @@ async def test_shutdown_queue_full(event_bus: EventBus, package_ahriman: Package must handle shutdown when queue is full """ event_bus.max_size = 1 - _, queue = await event_bus.subscribe() + await event_bus.subscribe() await event_bus.broadcast(EventType.PACKAGE_UPDATED, package_ahriman.base) await event_bus.shutdown() diff --git a/ahriman-core/tests/ahriman/core/test_module_loader.py b/ahriman-core/tests/ahriman/core/test_module_loader.py index a1d47682..5771a578 100644 --- a/ahriman-core/tests/ahriman/core/test_module_loader.py +++ b/ahriman-core/tests/ahriman/core/test_module_loader.py @@ -1,7 +1,7 @@ -import ahriman.web.views - from pathlib import Path +import ahriman.web.views + from ahriman.core.module_loader import _modules, implementations, optional_module from ahriman.web.views.base import BaseView diff --git a/ahriman-core/tests/ahriman/core/test_utils.py b/ahriman-core/tests/ahriman/core/test_utils.py index c48d0328..4d66944f 100644 --- a/ahriman-core/tests/ahriman/core/test_utils.py +++ b/ahriman-core/tests/ahriman/core/test_utils.py @@ -11,7 +11,6 @@ from unittest.mock import MagicMock, call as MockCall from ahriman.core.exceptions import BuildError, CalledProcessError, OptionError, UnsafeRunError from ahriman.core.utils import * from ahriman.models.package import Package -from ahriman.models.package_source import PackageSource from ahriman.models.repository_id import RepositoryId from ahriman.models.repository_paths import RepositoryPaths diff --git a/ahriman-core/tests/ahriman/core/triggers/test_trigger.py b/ahriman-core/tests/ahriman/core/triggers/test_trigger.py index 2070d902..0b0ccb3d 100644 --- a/ahriman-core/tests/ahriman/core/triggers/test_trigger.py +++ b/ahriman-core/tests/ahriman/core/triggers/test_trigger.py @@ -44,7 +44,7 @@ def test_configuration_schema_no_section(configuration: Configuration) -> None: """ section = "abracadabra" configuration.set_option("report", "target", section) - assert ReportTrigger.configuration_schema(configuration) == {} + assert not ReportTrigger.configuration_schema(configuration) def test_configuration_schema_no_schema(configuration: Configuration) -> None: @@ -55,7 +55,7 @@ def test_configuration_schema_no_schema(configuration: Configuration) -> None: configuration.set_option("report", "target", section) configuration.set_option(section, "key", "value") - assert ReportTrigger.configuration_schema(configuration) == {} + assert not ReportTrigger.configuration_schema(configuration) def test_configuration_schema_empty() -> None: @@ -69,14 +69,14 @@ def test_configuration_schema_variables() -> None: """ must return empty schema """ - assert Trigger.CONFIGURATION_SCHEMA == {} + assert not Trigger.CONFIGURATION_SCHEMA def test_configuration_sections(configuration: Configuration) -> None: """ must return empty section list """ - assert Trigger.configuration_sections(configuration) == [] + assert not Trigger.configuration_sections(configuration) def test_on_result(trigger: Trigger) -> None: diff --git a/ahriman-core/tests/ahriman/core/upload/test_http_upload.py b/ahriman-core/tests/ahriman/core/upload/test_http_upload.py index b57b0fa4..cacfa747 100644 --- a/ahriman-core/tests/ahriman/core/upload/test_http_upload.py +++ b/ahriman-core/tests/ahriman/core/upload/test_http_upload.py @@ -33,4 +33,4 @@ def test_get_hashes_empty() -> None: """ must read empty body """ - assert HttpUpload.get_hashes("") == {} + assert not HttpUpload.get_hashes("") diff --git a/ahriman-core/tests/ahriman/core/upload/test_s3.py b/ahriman-core/tests/ahriman/core/upload/test_s3.py index 6655af7d..5a6b0c74 100644 --- a/ahriman-core/tests/ahriman/core/upload/test_s3.py +++ b/ahriman-core/tests/ahriman/core/upload/test_s3.py @@ -8,7 +8,7 @@ from ahriman.core.upload.s3 import S3 from ahriman.models.repository_paths import RepositoryPaths -_chunk_size = 8 * 1024 * 1024 +_CHUNK_SIZE = 8 * 1024 * 1024 def test_object_path(configuration: Configuration, mocker: MockerFixture) -> None: @@ -34,7 +34,7 @@ def test_calculate_etag_big(resource_path_root: Path) -> None: must calculate checksum for path which is more than one chunk """ path = resource_path_root / "models" / "big_file_checksum" - assert S3.calculate_etag(path, _chunk_size) == "3b15154eaeed22ae19ae4667d4b98d28-2" + assert S3.calculate_etag(path, _CHUNK_SIZE) == "3b15154eaeed22ae19ae4667d4b98d28-2" def test_calculate_etag_empty(resource_path_root: Path) -> None: @@ -42,7 +42,7 @@ def test_calculate_etag_empty(resource_path_root: Path) -> None: must calculate checksum for empty file correctly """ path = resource_path_root / "models" / "empty_file_checksum" - assert S3.calculate_etag(path, _chunk_size) == "d41d8cd98f00b204e9800998ecf8427e" + assert S3.calculate_etag(path, _CHUNK_SIZE) == "d41d8cd98f00b204e9800998ecf8427e" def test_calculate_etag_small(resource_path_root: Path) -> None: @@ -50,7 +50,7 @@ def test_calculate_etag_small(resource_path_root: Path) -> None: must calculate checksum for path which is single chunk """ path = resource_path_root / "models" / "package_ahriman_pkgbuild" - assert S3.calculate_etag(path, _chunk_size) == "7136fc388980dc043f9f869d57c5ce0c" + assert S3.calculate_etag(path, _CHUNK_SIZE) == "7136fc388980dc043f9f869d57c5ce0c" def test_files_remove(s3_remote_objects: list[Any]) -> None: @@ -78,7 +78,6 @@ def test_files_upload(s3: S3, s3_remote_objects: list[Any], mocker: MockerFixtur Path(item.key[:-1] + item.key[-1].replace("a", "d")): item.e_tag.replace("b", "d").replace("\"", "") for item in s3_remote_objects } - print(local_files) remote_objects = {Path(item.key): item for item in s3_remote_objects} mocker.patch("mimetypes.guess_type", side_effect=mimetype) diff --git a/ahriman-core/tests/ahriman/models/test_build_plan.py b/ahriman-core/tests/ahriman/models/test_build_plan.py index 32c8d719..3fe225a9 100644 --- a/ahriman-core/tests/ahriman/models/test_build_plan.py +++ b/ahriman-core/tests/ahriman/models/test_build_plan.py @@ -54,10 +54,12 @@ def test_eq(package_ahriman: Package) -> None: must compare two plans """ plan1 = BuildPlan().update([package_ahriman], BuildPlanReason.REGULAR_UPDATE) - assert plan1 == plan1 - plan2 = BuildPlan().update([package_ahriman], BuildPlanReason.MANUAL_REQUEST) - assert plan1 != plan2 + plan2 = BuildPlan().update([package_ahriman], BuildPlanReason.REGULAR_UPDATE) + assert plan1 == plan2 + + plan3 = BuildPlan().update([package_ahriman], BuildPlanReason.MANUAL_REQUEST) + assert plan1 != plan3 def test_eq_other() -> None: diff --git a/ahriman-core/tests/ahriman/models/test_event.py b/ahriman-core/tests/ahriman/models/test_event.py index 216ad855..07049426 100644 --- a/ahriman-core/tests/ahriman/models/test_event.py +++ b/ahriman-core/tests/ahriman/models/test_event.py @@ -44,10 +44,12 @@ def test_eq() -> None: must compare two events """ event1 = Event("1", "1", "1", 1, key="value") - assert event1 == event1 - event2 = Event("2", "2", "2", 2, key="value") - assert event1 != event2 + event2 = Event("1", "1", "1", 1, key="value") + assert event1 == event2 + + event3 = Event("2", "2", "2", 2, key="value") + assert event1 != event3 def test_eq_other() -> None: diff --git a/ahriman-triggers/tests/ahriman/core/archive/test_archive_tree.py b/ahriman-triggers/tests/ahriman/core/archive/test_archive_tree.py index c6dc2381..1c7670f2 100644 --- a/ahriman-triggers/tests/ahriman/core/archive/test_archive_tree.py +++ b/ahriman-triggers/tests/ahriman/core/archive/test_archive_tree.py @@ -147,7 +147,7 @@ def test_symlinks_fix_foreign_repository(archive_tree: ArchiveTree, mocker: Mock ]) remove_mock = mocker.patch("ahriman.core.alpm.repo.Repo.remove") - assert list(archive_tree.symlinks_fix()) == [] + assert not list(archive_tree.symlinks_fix()) remove_mock.assert_not_called() diff --git a/ahriman-triggers/tests/ahriman/core/support/conftest.py b/ahriman-triggers/tests/ahriman/core/support/conftest.py index 905b9053..65d5cbe6 100644 --- a/ahriman-triggers/tests/ahriman/core/support/conftest.py +++ b/ahriman-triggers/tests/ahriman/core/support/conftest.py @@ -27,7 +27,7 @@ def package_creator(configuration: Configuration, mirrorlist_generator: Mirrorli Args: configuration(Configuration): configuration fixture - mirrorlist_generator(MirrorlistGenerator): + mirrorlist_generator(MirrorlistGenerator): mirrorlist pkgbuild generator fixture Returns: PackageCreator: package creator test instance diff --git a/ahriman-web/tests/ahriman/application/handlers/web/test_handler_web.py b/ahriman-web/tests/ahriman/application/handlers/web/test_handler_web.py index 419be941..e14fe201 100644 --- a/ahriman-web/tests/ahriman/application/handlers/web/test_handler_web.py +++ b/ahriman-web/tests/ahriman/application/handlers/web/test_handler_web.py @@ -55,7 +55,7 @@ def test_run(args: argparse.Namespace, configuration: Configuration, repository: join_mock.assert_called_once_with() -def test_extract_arguments(args: argparse.Namespace, configuration: Configuration): +def test_extract_arguments(args: argparse.Namespace, configuration: Configuration) -> None: """ must extract correct args """ @@ -87,7 +87,7 @@ def test_extract_arguments(args: argparse.Namespace, configuration: Configuratio assert list(Web.extract_arguments(probe, configuration)) == expected -def test_extract_arguments_full(parser: argparse.ArgumentParser, configuration: Configuration): +def test_extract_arguments_full(parser: argparse.ArgumentParser, configuration: Configuration) -> None: """ must extract all available args except for blacklisted """ diff --git a/ahriman-web/tests/ahriman/web/apispec/test_info.py b/ahriman-web/tests/ahriman/web/apispec/test_info.py index 8c281fb7..eca58aa4 100644 --- a/ahriman-web/tests/ahriman/web/apispec/test_info.py +++ b/ahriman-web/tests/ahriman/web/apispec/test_info.py @@ -13,9 +13,9 @@ def test_info() -> None: """ must generate info object for swagger """ - info = _info() - assert info["title"] == "ahriman" - assert info["version"] == __version__ + text = _info() + assert text["title"] == "ahriman" + assert text["version"] == __version__ def test_security() -> None: diff --git a/ahriman-web/tests/ahriman/web/middlewares/test_request_id_handler.py b/ahriman-web/tests/ahriman/web/middlewares/test_request_id_handler.py index a0ef8957..304f7abd 100644 --- a/ahriman-web/tests/ahriman/web/middlewares/test_request_id_handler.py +++ b/ahriman-web/tests/ahriman/web/middlewares/test_request_id_handler.py @@ -1,8 +1,8 @@ import logging import pytest -from unittest.mock import AsyncMock, MagicMock from typing import Any +from unittest.mock import AsyncMock, MagicMock from ahriman.web.middlewares.request_id_handler import request_id_handler diff --git a/ahriman-web/tests/ahriman/web/views/api/test_view_api_docs.py b/ahriman-web/tests/ahriman/web/views/api/test_view_api_docs.py index d4d46352..b9a7a691 100644 --- a/ahriman-web/tests/ahriman/web/views/api/test_view_api_docs.py +++ b/ahriman-web/tests/ahriman/web/views/api/test_view_api_docs.py @@ -36,7 +36,7 @@ def test_routes_dynamic_not_found(configuration: Configuration, mocker: MockerFi must disable docs route if no apispec package found """ mocker.patch("ahriman.web.views.api.docs.aiohttp_apispec", None) - assert DocsView.routes(configuration) == [] + assert not DocsView.routes(configuration) async def test_get(client: TestClient) -> None: diff --git a/ahriman-web/tests/ahriman/web/views/api/test_view_api_swagger.py b/ahriman-web/tests/ahriman/web/views/api/test_view_api_swagger.py index 2df12575..ba1f122e 100644 --- a/ahriman-web/tests/ahriman/web/views/api/test_view_api_swagger.py +++ b/ahriman-web/tests/ahriman/web/views/api/test_view_api_swagger.py @@ -106,7 +106,7 @@ def test_routes_dynamic_not_found(configuration: Configuration, mocker: MockerFi must disable openapi route if no apispec package found """ mocker.patch("ahriman.web.views.api.swagger.aiohttp_apispec", None) - assert SwaggerView.routes(configuration) == [] + assert not SwaggerView.routes(configuration) async def test_get(client: TestClient, mocker: MockerFixture) -> None: diff --git a/ahriman-web/tests/ahriman/web/views/test_status_view_guard.py b/ahriman-web/tests/ahriman/web/views/test_status_view_guard.py index d2e0e730..736939f7 100644 --- a/ahriman-web/tests/ahriman/web/views/test_status_view_guard.py +++ b/ahriman-web/tests/ahriman/web/views/test_status_view_guard.py @@ -16,4 +16,4 @@ def test_routes_empty(configuration: Configuration) -> None: """ StatusViewGuard.ROUTES = ["route1", "route2"] configuration.set_option("web", "service_only", "yes") - assert StatusViewGuard.routes(configuration) == [] + assert not StatusViewGuard.routes(configuration) diff --git a/ahriman-web/tests/ahriman/web/views/test_view_base.py b/ahriman-web/tests/ahriman/web/views/test_view_base.py index 4b913f46..41674e42 100644 --- a/ahriman-web/tests/ahriman/web/views/test_view_base.py +++ b/ahriman-web/tests/ahriman/web/views/test_view_base.py @@ -17,7 +17,7 @@ def test_routes() -> None: """ must return correct routes """ - assert BaseView.ROUTES == [] + assert not BaseView.ROUTES def test_configuration(base: BaseView) -> None: diff --git a/ahriman-web/tests/ahriman/web/views/v1/service/test_view_v1_service_upload.py b/ahriman-web/tests/ahriman/web/views/v1/service/test_view_v1_service_upload.py index ca9a96de..38763e40 100644 --- a/ahriman-web/tests/ahriman/web/views/v1/service/test_view_v1_service_upload.py +++ b/ahriman-web/tests/ahriman/web/views/v1/service/test_view_v1_service_upload.py @@ -42,7 +42,7 @@ def test_routes_dynamic_not_found(configuration: Configuration) -> None: must disable upload route if option is not set """ configuration.set_option("web", "enable_archive_upload", "no") - assert UploadView.routes(configuration) == [] + assert not UploadView.routes(configuration) async def test_save_file(mocker: MockerFixture) -> None: diff --git a/tests/test_tests.py b/tests/test_tests.py index 0221078b..905876b2 100644 --- a/tests/test_tests.py +++ b/tests/test_tests.py @@ -27,8 +27,7 @@ def _test_path(source_root: Path, source_file: Path) -> Path: case ("ahriman", "web", "views", *_, source_name): if source_name.endswith("_guard.py"): return relative_path.parent / f"test_{source_name}" - else: - return relative_path.parent / f"test_view_{source_name}" + return relative_path.parent / f"test_view_{source_name}" case (*_, source_name) if source_name.startswith("__"): return relative_path.parent / f"test_{source_name.replace("__", "")}" case _: diff --git a/tools/pylint_plugins/import_order/__init__.py b/tools/pylint_plugins/import_order/__init__.py index 34488971..7a22ffa4 100644 --- a/tools/pylint_plugins/import_order/__init__.py +++ b/tools/pylint_plugins/import_order/__init__.py @@ -206,13 +206,12 @@ class ImportOrder(BaseRawFileChecker): Args: node(nodes.Module): module node to check """ - root_module, *_ = node.qname().split(".") contexts: dict[tuple[nodes.NodeNG, str], list[nodes.Import | nodes.ImportFrom]] = {} for statement in self.imports(node.values()): contexts.setdefault(self.import_context(statement), []).append(statement) for imports in contexts.values(): - self.check_imports(imports, root_module) + self.check_imports(imports, self.linter.config.root_module) def register(linter: PyLinter) -> None: diff --git a/tools/pylint_plugins/type_annotations/__init__.py b/tools/pylint_plugins/type_annotations/__init__.py new file mode 100644 index 00000000..f3de974f --- /dev/null +++ b/tools/pylint_plugins/type_annotations/__init__.py @@ -0,0 +1,106 @@ +# +# Copyright (c) 2021-2026 ahriman team. +# +# This file is part of ahriman +# (see https://github.com/arcan1s/ahriman). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +from astroid import nodes +from enum import StrEnum +from pylint.checkers import BaseChecker +from pylint.lint import PyLinter + + +class MethodType(StrEnum): + """ + method type enumeration + + Attributes: + CLASS_METHOD(MethodType): (class attribute) class method + METHOD(MethodType): (class attribute) class method + """ + CLASS_METHOD = "classmethod" + METHOD = "method" + + +class TypeAnnotations(BaseChecker): + """ + require explicit annotations on function parameters and return values + """ + + msgs = { + "E5301": ( + "Missing type annotation for parameter %s", + "missing-parameter-annotation", + "Function parameters must have explicit type annotations, except method receivers.", + ), + "E5302": ( + "Missing return type annotation for function %s", + "missing-return-annotation", + "Functions must have explicit return annotations, including constructors and local functions.", + ), + } + name = "type-annotations" + + def visit_asyncfunctiondef(self, node: nodes.AsyncFunctionDef) -> None: + """ + check an asynchronous function signature + + Args: + node(nodes.AsyncFunctionDef): function to check + """ + self.visit_functiondef(node) + + def visit_functiondef(self, node: nodes.FunctionDef) -> None: + """ + check a function signature + + Args: + node(nodes.FunctionDef): function to check + """ + args = node.args + arguments = [*args.posonlyargs, *args.args, *args.kwonlyargs] + annotations = [*args.posonlyargs_annotations, *args.annotations, *args.kwonlyargs_annotations] + + # remove receiver argument + if arguments: + match node.type: + case MethodType.CLASS_METHOD | MethodType.METHOD: + arguments.pop(0) + annotations.pop(0) + + for argument, annotation in zip(arguments, annotations): + if annotation is None: + self.add_message("missing-parameter-annotation", node=argument, args=(argument.name,)) + + for name, annotation in ( + (args.vararg, args.varargannotation), + (args.kwarg, args.kwargannotation), + ): + if name is not None and annotation is None: + self.add_message("missing-parameter-annotation", node=node, args=(name,)) + + if node.returns is None: + self.add_message("missing-return-annotation", node=node, args=(node.name,)) + + +def register(linter: PyLinter) -> None: + """ + register custom checker + + Args: + linter(PyLinter): linter in which checker should be registered + """ + linter.register_checker(TypeAnnotations(linter)) diff --git a/tox.toml b/tox.toml index 5963579a..2ebf46b5 100644 --- a/tox.toml +++ b/tox.toml @@ -148,6 +148,31 @@ commands = [ { replace = "ref", of = ["flags", "pylint"], extend = true }, "{[project]name}", ], + [ + "pylint", + { replace = "ref", of = ["flags", "pylint"], extend = true }, + "--disable", + """broad-exception-raised,\ +consider-using-f-string,\ +consider-using-from-import,\ +import-error,\ +methods-out-of-order,\ +no-member,\ +protected-access,\ +redefined-outer-name,\ +too-many-lines,\ +too-many-locals,\ +too-many-return-statements,\ +unnecessary-dunder-call,\ +unused-wildcard-import,\ +wildcard-import""", + "--recursive", + "y", + "ahriman-core/tests/{[project]name}", + "ahriman-triggers/tests/{[project]name}", + "ahriman-web/tests/{[project]name}", + "tests", + ], [ "bandit", { replace = "ref", of = ["flags", "bandit"], extend = true }, @@ -165,6 +190,7 @@ commands = [ "ahriman-core/tests/{[project]name}", "ahriman-triggers/tests/{[project]name}", "ahriman-web/tests/{[project]name}", + "tests", ], [ "mypy",