diff --git a/tests/ahriman/application/test_lock.py b/tests/ahriman/application/test_lock.py index 29606abe..1a0b3b03 100644 --- a/tests/ahriman/application/test_lock.py +++ b/tests/ahriman/application/test_lock.py @@ -27,7 +27,7 @@ def test_path(args: argparse.Namespace, configuration: Configuration) -> None: with pytest.raises(ValueError): args.lock = Path("/") - Lock(args, repository_id, configuration).path # special case + assert Lock(args, repository_id, configuration).path # special case def test_check_user(lock: Lock, mocker: MockerFixture) -> None: @@ -205,7 +205,7 @@ def test_exit_with_exception(lock: Lock, mocker: MockerFixture) -> None: mocker.patch("ahriman.application.lock.Lock.create") update_status_mock = mocker.patch("ahriman.core.status.Client.status_update") - with pytest.raises(Exception): + with pytest.raises(ValueError): with lock: - raise Exception() + raise ValueError() update_status_mock.assert_has_calls([MockCall(BuildStatusEnum.Building), MockCall(BuildStatusEnum.Failed)]) diff --git a/tests/ahriman/core/alpm/test_pacman.py b/tests/ahriman/core/alpm/test_pacman.py index a3a832b6..33d9b2b7 100644 --- a/tests/ahriman/core/alpm/test_pacman.py +++ b/tests/ahriman/core/alpm/test_pacman.py @@ -128,7 +128,7 @@ def test_database_copy_database_exist(pacman: Pacman, mocker: MockerFixture) -> copy_mock.assert_not_called() -def test_database_init(pacman: Pacman, configuration: Configuration) -> None: +def test_database_init(pacman: Pacman) -> None: """ must init database with settings """ @@ -184,14 +184,15 @@ def test_files(pacman: Pacman, package_ahriman: Package, mocker: MockerFixture, pacman.handle = handle_mock tarball = resource_path_root / "core" / "arcanisrepo.files.tar.gz" - mocker.patch("pathlib.Path.is_file", return_value=True) - open_mock = mocker.patch("ahriman.core.alpm.pacman.tarfile.open", return_value=tarfile.open(tarball, "r:gz")) + with tarfile.open(tarball, "r:gz") as fd: + mocker.patch("pathlib.Path.is_file", return_value=True) + open_mock = mocker.patch("ahriman.core.alpm.pacman.tarfile.open", return_value=fd) - files = pacman.files() - assert len(files) == 2 - assert package_ahriman.base in files - assert "usr/bin/ahriman" in files[package_ahriman.base] - open_mock.assert_called_once_with(pytest.helpers.anyvar(int), "r:gz") + files = pacman.files() + assert len(files) == 2 + assert package_ahriman.base in files + assert "usr/bin/ahriman" in files[package_ahriman.base] + open_mock.assert_called_once_with(pytest.helpers.anyvar(int), "r:gz") def test_files_package(pacman: Pacman, package_ahriman: Package, mocker: MockerFixture, @@ -205,12 +206,13 @@ def test_files_package(pacman: Pacman, package_ahriman: Package, mocker: MockerF tarball = resource_path_root / "core" / "arcanisrepo.files.tar.gz" - mocker.patch("pathlib.Path.is_file", return_value=True) - mocker.patch("ahriman.core.alpm.pacman.tarfile.open", return_value=tarfile.open(tarball, "r:gz")) + with tarfile.open(tarball, "r:gz") as fd: + mocker.patch("pathlib.Path.is_file", return_value=True) + mocker.patch("ahriman.core.alpm.pacman.tarfile.open", return_value=fd) - files = pacman.files(package_ahriman.base) - assert len(files) == 1 - assert package_ahriman.base in files + files = pacman.files(package_ahriman.base) + assert len(files) == 1 + assert package_ahriman.base in files def test_files_skip(pacman: Pacman, mocker: MockerFixture) -> None: diff --git a/tests/ahriman/core/database/operations/test_package_operations.py b/tests/ahriman/core/database/operations/test_package_operations.py index f54ca873..c87d478e 100644 --- a/tests/ahriman/core/database/operations/test_package_operations.py +++ b/tests/ahriman/core/database/operations/test_package_operations.py @@ -165,7 +165,6 @@ def test_package_update_remove_get(database: SQLite, package_ahriman: Package) - """ must insert, remove and retrieve package """ - status = BuildStatus() database.package_update(package_ahriman) database.package_remove(package_ahriman.base) assert not database.packages_get() diff --git a/tests/ahriman/core/log/test_lazy_logging.py b/tests/ahriman/core/log/test_lazy_logging.py index 81abe4f2..5a05878d 100644 --- a/tests/ahriman/core/log/test_lazy_logging.py +++ b/tests/ahriman/core/log/test_lazy_logging.py @@ -68,9 +68,9 @@ def test_in_package_context_failed(database: SQLite, package_ahriman: Package, m mocker.patch("ahriman.core.log.LazyLogging._package_logger_set") reset_mock = mocker.patch("ahriman.core.log.LazyLogging._package_logger_reset") - with pytest.raises(Exception): + with pytest.raises(ValueError): with database.in_package_context(package_ahriman.base, ""): - raise Exception() + raise ValueError() reset_mock.assert_called_once_with() @@ -81,11 +81,3 @@ def test_logger(database: SQLite) -> None: """ assert database.logger assert database.logger.name == "ahriman.core.database.sqlite.SQLite" - - -def test_logger_attribute_error(database: SQLite) -> None: - """ - must raise AttributeError in case if no attribute found - """ - with pytest.raises(AttributeError): - database.loggerrrr diff --git a/tests/ahriman/core/status/test_local_client.py b/tests/ahriman/core/status/test_local_client.py index 1df794d8..8e3db4f4 100644 --- a/tests/ahriman/core/status/test_local_client.py +++ b/tests/ahriman/core/status/test_local_client.py @@ -4,7 +4,7 @@ import pytest from pytest_mock import MockerFixture from ahriman.core.status.local_client import LocalClient -from ahriman.models.build_status import BuildStatusEnum, BuildStatus +from ahriman.models.build_status import BuildStatus, BuildStatusEnum from ahriman.models.changes import Changes from ahriman.models.dependencies import Dependencies from ahriman.models.log_record_id import LogRecordId diff --git a/tests/ahriman/core/test_util.py b/tests/ahriman/core/test_util.py index 9686e332..b26303fc 100644 --- a/tests/ahriman/core/test_util.py +++ b/tests/ahriman/core/test_util.py @@ -2,7 +2,6 @@ import datetime import logging import os import pytest -import shlex from pathlib import Path from pytest_mock import MockerFixture diff --git a/tests/ahriman/models/test_repository_id.py b/tests/ahriman/models/test_repository_id.py index 94a9fb23..f18973c0 100644 --- a/tests/ahriman/models/test_repository_id.py +++ b/tests/ahriman/models/test_repository_id.py @@ -60,4 +60,4 @@ def test_lt_invalid() -> None: must raise ValueError if other is not valid repository id """ with pytest.raises(ValueError): - RepositoryId("x86_64", "a") < 42 + assert RepositoryId("x86_64", "a") < 42 diff --git a/tests/ahriman/web/views/v1/status/test_view_v1_status_info.py b/tests/ahriman/web/views/v1/status/test_view_v1_status_info.py index 3e72deaf..ff741482 100644 --- a/tests/ahriman/web/views/v1/status/test_view_v1_status_info.py +++ b/tests/ahriman/web/views/v1/status/test_view_v1_status_info.py @@ -30,7 +30,7 @@ async def test_get(client: TestClient, repository_id: RepositoryId) -> None: """ response_schema = pytest.helpers.schema_response(InfoView.get) - response = await client.get(f"/api/v1/info") + response = await client.get("/api/v1/info") assert response.ok json = await response.json() assert not response_schema.validate(json) diff --git a/tests/ahriman/web/views/v1/status/test_view_v1_status_repositories.py b/tests/ahriman/web/views/v1/status/test_view_v1_status_repositories.py index cd6f54f8..62ec0628 100644 --- a/tests/ahriman/web/views/v1/status/test_view_v1_status_repositories.py +++ b/tests/ahriman/web/views/v1/status/test_view_v1_status_repositories.py @@ -29,7 +29,7 @@ async def test_get(client: TestClient, repository_id: RepositoryId) -> None: """ response_schema = pytest.helpers.schema_response(RepositoriesView.get) - response = await client.get(f"/api/v1/repositories") + response = await client.get("/api/v1/repositories") assert response.ok json = await response.json() assert not response_schema.validate(json, many=True)