mirror of
https://github.com/arcan1s/ahriman.git
synced 2026-11-22 09:39:30 +00:00
type: add type annotation pylint check
Also run pylint against tests tree
This commit is contained in:
1 parent
71c5d58264
commit
0bd22a049c
39 files changed
+190
-61
No files matched your search
@@ -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
|
||||
|
||||
@@ -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]
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import argparse
|
||||
import pytest
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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])
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
"""
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import configparser
|
||||
import pytest
|
||||
import os
|
||||
import pytest
|
||||
|
||||
from io import StringIO
|
||||
from pathlib import Path
|
||||
|
||||
@@ -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=[
|
||||
|
||||
@@ -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
|
||||
"""
|
||||
|
||||
@@ -69,7 +69,7 @@ def test_properties() -> None:
|
||||
"""
|
||||
must return empty properties list
|
||||
"""
|
||||
assert Printer().properties() == []
|
||||
assert not Printer().properties()
|
||||
|
||||
|
||||
def test_title() -> None:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import smtplib
|
||||
|
||||
import pytest
|
||||
import smtplib
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -33,4 +33,4 @@ def test_get_hashes_empty() -> None:
|
||||
"""
|
||||
must read empty body
|
||||
"""
|
||||
assert HttpUpload.get_hashes("") == {}
|
||||
assert not HttpUpload.get_hashes("")
|
||||
@@ -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)
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in new issue
Block a user