From 70b7fcf47a6b680864bebadf39dc2497035222f6 Mon Sep 17 00:00:00 2001 From: Evgenii Alekseev Date: Fri, 5 Jan 2024 16:40:38 +0200 Subject: [PATCH] refactor: fix pylint warnings in tests --- .../application/application/test_application_packages.py | 2 +- .../application/application/test_updates_iterator.py | 4 ++-- tests/ahriman/application/handlers/test_handler_setup.py | 2 +- tests/ahriman/conftest.py | 3 +-- tests/ahriman/core/alpm/remote/test_remote.py | 4 ++-- tests/ahriman/core/auth/test_helpers.py | 4 ++-- tests/ahriman/core/build_tools/test_sources.py | 2 +- .../core/database/migrations/test_migrations_init.py | 2 +- tests/ahriman/core/gitremote/test_remote_push.py | 5 +---- tests/ahriman/core/repository/test_package_info.py | 2 +- tests/ahriman/core/triggers/test_trigger.py | 2 +- tests/ahriman/core/triggers/test_trigger_loader.py | 4 ++-- tests/ahriman/models/test_aur_package.py | 2 +- tests/ahriman/models/test_package.py | 6 +++--- tests/ahriman/web/conftest.py | 5 ++--- tests/ahriman/web/middlewares/conftest.py | 4 +--- tests/ahriman/web/middlewares/test_auth_handler.py | 4 ++-- 17 files changed, 25 insertions(+), 32 deletions(-) diff --git a/tests/ahriman/application/application/test_application_packages.py b/tests/ahriman/application/application/test_application_packages.py index 0a75b742..17d0b541 100644 --- a/tests/ahriman/application/application/test_application_packages.py +++ b/tests/ahriman/application/application/test_application_packages.py @@ -100,7 +100,7 @@ def test_add_local_cache(application_packages: ApplicationPackages, package_ahri """ mocker.patch("ahriman.models.package.Package.from_build", return_value=package_ahriman) mocker.patch("pathlib.Path.is_dir", autospec=True, - side_effect=lambda p: True if p.is_relative_to(application_packages.repository.paths.cache) else False) + side_effect=lambda p: p.is_relative_to(application_packages.repository.paths.cache)) init_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.init") copytree_mock = mocker.patch("shutil.copytree") build_queue_mock = mocker.patch("ahriman.core.database.SQLite.build_queue_insert") diff --git a/tests/ahriman/application/application/test_updates_iterator.py b/tests/ahriman/application/application/test_updates_iterator.py index 7e6bc74b..ca80a6fc 100644 --- a/tests/ahriman/application/application/test_updates_iterator.py +++ b/tests/ahriman/application/application/test_updates_iterator.py @@ -47,7 +47,7 @@ def test_iter(updates_iterator: UpdatesIterator) -> None: """ must return self as iterator """ - assert updates_iterator.__iter__() == updates_iterator + assert iter(updates_iterator) == updates_iterator def test_next(updates_iterator: UpdatesIterator, package_ahriman: Package, mocker: MockerFixture) -> None: @@ -58,7 +58,7 @@ def test_next(updates_iterator: UpdatesIterator, package_ahriman: Package, mocke side_effect=[([package_ahriman.base], 2), (None, 2), StopIteration]) sleep_mock = mocker.patch("time.sleep") - updates = [packages for packages in updates_iterator] + updates = list(updates_iterator) assert updates == [[package_ahriman.base], None] sleep_mock.assert_has_calls([MockCall(0.5), MockCall(0.5)]) diff --git a/tests/ahriman/application/handlers/test_handler_setup.py b/tests/ahriman/application/handlers/test_handler_setup.py index 4a94602d..3c2603a1 100644 --- a/tests/ahriman/application/handlers/test_handler_setup.py +++ b/tests/ahriman/application/handlers/test_handler_setup.py @@ -156,7 +156,7 @@ def test_configuration_create_ahriman(args: argparse.Namespace, configuration: C def test_configuration_create_ahriman_no_multilib(args: argparse.Namespace, configuration: Configuration, - repository_paths: RepositoryPaths, mocker: MockerFixture) -> None: + mocker: MockerFixture) -> None: """ must create configuration for the service without multilib repository """ diff --git a/tests/ahriman/conftest.py b/tests/ahriman/conftest.py index 904e213c..07cbc14f 100644 --- a/tests/ahriman/conftest.py +++ b/tests/ahriman/conftest.py @@ -558,14 +558,13 @@ def user() -> User: @pytest.fixture -def watcher(repository_id: RepositoryId, database: SQLite, repository: Repository) -> Watcher: +def watcher(repository_id: RepositoryId, database: SQLite) -> Watcher: """ package status watcher fixture Args: repository_id(RepositoryId): repository identifier fixture database(SQLite): database fixture - repository(Repository): repository fixture Returns: Watcher: package status watcher test instance diff --git a/tests/ahriman/core/alpm/remote/test_remote.py b/tests/ahriman/core/alpm/remote/test_remote.py index 7653558f..e390fd28 100644 --- a/tests/ahriman/core/alpm/remote/test_remote.py +++ b/tests/ahriman/core/alpm/remote/test_remote.py @@ -48,7 +48,7 @@ def test_multisearch_single(aur_package_ahriman: AURPackage, pacman: Pacman, moc search_mock.assert_called_once_with("ahriman", pacman=pacman) -def test_remote_git_url(remote: Remote, pacman: Pacman) -> None: +def test_remote_git_url(remote: Remote) -> None: """ must raise NotImplemented for missing remote git url """ @@ -56,7 +56,7 @@ def test_remote_git_url(remote: Remote, pacman: Pacman) -> None: remote.remote_git_url("package", "repositorys") -def test_remote_web_url(remote: Remote, pacman: Pacman) -> None: +def test_remote_web_url(remote: Remote) -> None: """ must raise NotImplemented for missing remote web url """ diff --git a/tests/ahriman/core/auth/test_helpers.py b/tests/ahriman/core/auth/test_helpers.py index e83f531e..b258ab1d 100644 --- a/tests/ahriman/core/auth/test_helpers.py +++ b/tests/ahriman/core/auth/test_helpers.py @@ -1,10 +1,10 @@ import importlib import sys -import ahriman.core.auth.helpers as helpers - from pytest_mock import MockerFixture +from ahriman.core.auth import helpers + def test_import_aiohttp_security() -> None: """ diff --git a/tests/ahriman/core/build_tools/test_sources.py b/tests/ahriman/core/build_tools/test_sources.py index 61356a66..c1e8e1d7 100644 --- a/tests/ahriman/core/build_tools/test_sources.py +++ b/tests/ahriman/core/build_tools/test_sources.py @@ -27,7 +27,7 @@ def test_changes(mocker: MockerFixture) -> None: diff_mock.assert_called_once_with(local, last_commit_sha) -def test_changes_skip(package_ahriman: Package, mocker: MockerFixture) -> None: +def test_changes_skip(mocker: MockerFixture) -> None: """ must return none in case if commit sha is not available """ diff --git a/tests/ahriman/core/database/migrations/test_migrations_init.py b/tests/ahriman/core/database/migrations/test_migrations_init.py index 508a55df..bbbefb93 100644 --- a/tests/ahriman/core/database/migrations/test_migrations_init.py +++ b/tests/ahriman/core/database/migrations/test_migrations_init.py @@ -19,7 +19,7 @@ def test_migrate(connection: Connection, configuration: Configuration, mocker: M run_mock.assert_called_once_with() -def test_migration(migrations: Migrations, connection: Connection) -> None: +def test_migration(migrations: Migrations) -> None: """ must perform single migration """ diff --git a/tests/ahriman/core/gitremote/test_remote_push.py b/tests/ahriman/core/gitremote/test_remote_push.py index 205efebc..a0ff93cf 100644 --- a/tests/ahriman/core/gitremote/test_remote_push.py +++ b/tests/ahriman/core/gitremote/test_remote_push.py @@ -22,10 +22,7 @@ def test_package_update(database: SQLite, configuration: Configuration, package_ patch2 = PkgbuildPatch("key", "value") local = Path("local") - mocker.patch( - "pathlib.Path.is_file", - autospec=True, - side_effect=lambda p: True if p == Path(".gitignore") else False) + mocker.patch("pathlib.Path.is_file", autospec=True, side_effect=lambda p: p == Path(".gitignore")) glob_mock = mocker.patch("pathlib.Path.glob", return_value=[Path(".git"), Path(".gitignore")]) rmtree_mock = mocker.patch("shutil.rmtree") unlink_mock = mocker.patch("pathlib.Path.unlink") diff --git a/tests/ahriman/core/repository/test_package_info.py b/tests/ahriman/core/repository/test_package_info.py index ab4b9a3a..705b657c 100644 --- a/tests/ahriman/core/repository/test_package_info.py +++ b/tests/ahriman/core/repository/test_package_info.py @@ -29,7 +29,7 @@ def test_load_archives(package_ahriman: Package, package_python_schedule: Packag assert len(packages) == 2 assert {package.base for package in packages} == {package_ahriman.base, package_python_schedule.base} - archives = sum([list(package.packages.keys()) for package in packages], start=[]) + archives = sum((list(package.packages.keys()) for package in packages), start=[]) assert len(archives) == 3 expected = set(package_ahriman.packages.keys()) expected.update(package_python_schedule.packages.keys()) diff --git a/tests/ahriman/core/triggers/test_trigger.py b/tests/ahriman/core/triggers/test_trigger.py index 57a0ef05..7d1f0f22 100644 --- a/tests/ahriman/core/triggers/test_trigger.py +++ b/tests/ahriman/core/triggers/test_trigger.py @@ -56,7 +56,7 @@ def test_configuration_schema_empty(configuration: Configuration) -> None: assert ReportTrigger.configuration_schema(repository_id, None) == ReportTrigger.CONFIGURATION_SCHEMA -def test_configuration_schema_variables(configuration: Configuration) -> None: +def test_configuration_schema_variables() -> None: """ must return empty schema """ diff --git a/tests/ahriman/core/triggers/test_trigger_loader.py b/tests/ahriman/core/triggers/test_trigger_loader.py index 940041d2..f3d5efe8 100644 --- a/tests/ahriman/core/triggers/test_trigger_loader.py +++ b/tests/ahriman/core/triggers/test_trigger_loader.py @@ -147,7 +147,7 @@ def test_on_result_exception(trigger_loader: TriggerLoader, package_ahriman: Pac log_mock.assert_called_once() -def test_on_start(trigger_loader: TriggerLoader, package_ahriman: Package, mocker: MockerFixture) -> None: +def test_on_start(trigger_loader: TriggerLoader, mocker: MockerFixture) -> None: """ must run triggers on start """ @@ -187,7 +187,7 @@ def test_on_stop_without_on_start(configuration: Configuration, mocker: MockerFi on_stop_mock.assert_not_called() -def test_on_stop(trigger_loader: TriggerLoader, package_ahriman: Package, mocker: MockerFixture) -> None: +def test_on_stop(trigger_loader: TriggerLoader, mocker: MockerFixture) -> None: """ must run triggers on stop """ diff --git a/tests/ahriman/models/test_aur_package.py b/tests/ahriman/models/test_aur_package.py index b224e8db..8936f219 100644 --- a/tests/ahriman/models/test_aur_package.py +++ b/tests/ahriman/models/test_aur_package.py @@ -78,7 +78,7 @@ def test_from_repo(aur_package_akonadi: AURPackage, resource_path_root: Path) -> assert AURPackage.from_repo(model) == aur_package_akonadi -def test_convert(aur_package_ahriman: AURPackage, resource_path_root: Path) -> None: +def test_convert(resource_path_root: Path) -> None: """ must convert fields to snakecase and also apply converters """ diff --git a/tests/ahriman/models/test_package.py b/tests/ahriman/models/test_package.py index 229f37a0..7596787d 100644 --- a/tests/ahriman/models/test_package.py +++ b/tests/ahriman/models/test_package.py @@ -249,7 +249,7 @@ def test_from_build_architecture(mocker: MockerFixture, resource_path_root: Path } -def test_from_build_failed(package_ahriman: Package, mocker: MockerFixture) -> None: +def test_from_build_failed(mocker: MockerFixture) -> None: """ must raise exception if there are errors during srcinfo load """ @@ -317,7 +317,7 @@ def test_local_files_empty(mocker: MockerFixture, resource_path_root: Path) -> N mocker.patch("ahriman.models.package.check_output", return_value=srcinfo) mocker.patch("ahriman.models.package.Package.supported_architectures", return_value=["any"]) - assert list(Package.local_files(Path("path"))) == [] + assert not list(Package.local_files(Path("path"))) def test_local_files_error(mocker: MockerFixture) -> None: @@ -342,7 +342,7 @@ def test_local_files_schema(mocker: MockerFixture, resource_path_root: Path) -> mocker.patch("ahriman.models.package.check_output", return_value="") mocker.patch("ahriman.models.package.Package.supported_architectures", return_value=["any"]) - assert list(Package.local_files(Path("path"))) == [] + assert not list(Package.local_files(Path("path"))) def test_local_files_with_install(mocker: MockerFixture, resource_path_root: Path) -> None: diff --git a/tests/ahriman/web/conftest.py b/tests/ahriman/web/conftest.py index 3e232d63..8078ce80 100644 --- a/tests/ahriman/web/conftest.py +++ b/tests/ahriman/web/conftest.py @@ -73,7 +73,7 @@ def request(application: Application, path: str, method: str, params: Any = None request_mock.match_info = UrlMappingMatchInfo({}, route_mock) extra = extra or {} - request_mock.get_extra_info.side_effect = lambda key: extra.get(key) + request_mock.get_extra_info.side_effect = extra.get return request_mock @@ -167,14 +167,13 @@ def application_with_auth(configuration: Configuration, user: User, spawner: Spa @pytest.fixture -def application_with_debug(configuration: Configuration, user: User, spawner: Spawn, database: SQLite, +def application_with_debug(configuration: Configuration, spawner: Spawn, database: SQLite, mocker: MockerFixture) -> Application: """ application fixture with debug enabled Args: configuration(Configuration): configuration fixture - user(User): user descriptor fixture spawner(Spawn): spawner fixture database(SQLite): database fixture mocker(MockerFixture): mocker object diff --git a/tests/ahriman/web/middlewares/conftest.py b/tests/ahriman/web/middlewares/conftest.py index faed3ddf..02779cff 100644 --- a/tests/ahriman/web/middlewares/conftest.py +++ b/tests/ahriman/web/middlewares/conftest.py @@ -3,19 +3,17 @@ import pytest from ahriman.core.auth import Auth from ahriman.core.configuration import Configuration from ahriman.core.database import SQLite -from ahriman.models.user import User from ahriman.web.middlewares.auth_handler import _AuthorizationPolicy @pytest.fixture -def authorization_policy(configuration: Configuration, database: SQLite, user: User) -> _AuthorizationPolicy: +def authorization_policy(configuration: Configuration, database: SQLite) -> _AuthorizationPolicy: """ fixture for authorization policy Args: configuration(Configuration): configuration fixture database(SQLite): database fixture - user(User): user fixture Returns: AuthorizationPolicy: authorization policy fixture diff --git a/tests/ahriman/web/middlewares/test_auth_handler.py b/tests/ahriman/web/middlewares/test_auth_handler.py index 2f6bc0ca..fb6b83f1 100644 --- a/tests/ahriman/web/middlewares/test_auth_handler.py +++ b/tests/ahriman/web/middlewares/test_auth_handler.py @@ -24,7 +24,7 @@ async def test_authorized_userid(authorization_policy: _AuthorizationPolicy, use assert await authorization_policy.authorized_userid(user.username) == user.username -async def test_authorized_userid_unknown(authorization_policy: _AuthorizationPolicy, user: User) -> None: +async def test_authorized_userid_unknown(authorization_policy: _AuthorizationPolicy) -> None: """ must not allow unknown user id for authorization """ @@ -51,7 +51,7 @@ async def test_permits(authorization_policy: _AuthorizationPolicy, user: User) - ]) -async def test_auth_handler_unix_socket(client_with_auth: TestClient, mocker: MockerFixture) -> None: +async def test_auth_handler_unix_socket(mocker: MockerFixture) -> None: """ must allow calls via unix sockets """