refactor: fix warnings and typos, cleanup code

This commit is contained in:
2023-12-28 16:53:45 +02:00
parent 1a2327cefd
commit e9116741a5
20 changed files with 35 additions and 37 deletions

View File

@ -1,6 +1,4 @@
import argparse
import configparser
import pytest
from pytest_mock import MockerFixture

View File

@ -565,6 +565,7 @@ def watcher(repository_id: RepositoryId, database: SQLite, repository: Repositor
Args:
repository_id(RepositoryId): repository identifier fixture
database(SQLite): database fixture
repository(Repository): repository fixture
Returns:
Watcher: package status watcher test instance

View File

@ -510,7 +510,7 @@ def test_head(sources: Sources, mocker: MockerFixture) -> None:
local = Path("local")
assert sources.head(local) == "sha"
check_output_mock.assert_called_once_with("git", "rev-parse", "HEAD", cwd=local)
check_output_mock.assert_called_once_with("git", "rev-parse", "HEAD", cwd=local, logger=sources.logger)
def test_head_specific(sources: Sources, mocker: MockerFixture) -> None:
@ -521,7 +521,7 @@ def test_head_specific(sources: Sources, mocker: MockerFixture) -> None:
local = Path("local")
assert sources.head(local, "master") == "sha"
check_output_mock.assert_called_once_with("git", "rev-parse", "master", cwd=local)
check_output_mock.assert_called_once_with("git", "rev-parse", "master", cwd=local, logger=sources.logger)
def test_move(sources: Sources, mocker: MockerFixture) -> None:

View File

@ -145,7 +145,7 @@ def update_printer(package_ahriman: Package) -> UpdatePrinter:
package_ahriman(Package): package fixture
Returns:
UpdatePrinter: udpate printer test instance
UpdatePrinter: update printer test instance
"""
return UpdatePrinter(package_ahriman, None)

View File

@ -15,6 +15,7 @@ from ahriman.core.util import check_output, check_user, dataclass_view, enum_val
srcinfo_property, srcinfo_property_list, trim_package, unquote, utcnow, walk
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
@ -150,11 +151,11 @@ def test_check_output_empty_line(mocker: MockerFixture) -> None:
logger_mock.assert_has_calls([MockCall(""), MockCall("hello")])
def test_check_user(mocker: MockerFixture) -> None:
def test_check_user(repository_id: RepositoryId, mocker: MockerFixture) -> None:
"""
must check user correctly
"""
paths = RepositoryPaths(Path.cwd(), "x86_64")
paths = RepositoryPaths(Path.cwd(), repository_id)
mocker.patch("os.getuid", return_value=paths.root_owner[0])
check_user(paths, unsafe=False)
@ -167,22 +168,22 @@ def test_check_user_no_directory(repository_paths: RepositoryPaths, mocker: Mock
check_user(repository_paths, unsafe=False)
def test_check_user_exception(mocker: MockerFixture) -> None:
def test_check_user_exception(repository_id: RepositoryId, mocker: MockerFixture) -> None:
"""
must raise exception if user differs
"""
paths = RepositoryPaths(Path.cwd(), "x86_64")
paths = RepositoryPaths(Path.cwd(), repository_id)
mocker.patch("os.getuid", return_value=paths.root_owner[0] + 1)
with pytest.raises(UnsafeRunError):
check_user(paths, unsafe=False)
def test_check_user_unsafe(mocker: MockerFixture) -> None:
def test_check_user_unsafe(repository_id: RepositoryId, mocker: MockerFixture) -> None:
"""
must skip check if unsafe flag is set
"""
paths = RepositoryPaths(Path.cwd(), "x86_64")
paths = RepositoryPaths(Path.cwd(), repository_id)
mocker.patch("os.getuid", return_value=paths.root_owner[0] + 1)
check_user(paths, unsafe=True)

View File

@ -37,7 +37,9 @@ def test_load_trigger(trigger_loader: TriggerLoader, configuration: Configuratio
"""
must load trigger
"""
loaded = trigger_loader.load_trigger("ahriman.core.report.ReportTrigger", "x86_64", configuration)
_, repository_id = configuration.check_loaded()
loaded = trigger_loader.load_trigger("ahriman.core.report.ReportTrigger", repository_id, configuration)
assert loaded
assert isinstance(loaded, ReportTrigger)

View File

@ -54,8 +54,7 @@ def test_from_json_2(aur_package_ahriman: AURPackage, mocker: MockerFixture) ->
assert AURPackage.from_json(asdict(aur_package_ahriman)) == aur_package_ahriman
def test_from_pacman(pyalpm_package_ahriman: pyalpm.Package, aur_package_ahriman: AURPackage,
resource_path_root: Path) -> None:
def test_from_pacman(pyalpm_package_ahriman: pyalpm.Package, aur_package_ahriman: AURPackage) -> None:
"""
must load package from repository database
"""

View File

@ -320,7 +320,7 @@ def test_local_files_empty(mocker: MockerFixture, resource_path_root: Path) -> N
assert list(Package.local_files(Path("path"))) == []
def test_local_files_error(mocker: MockerFixture, resource_path_root: Path) -> None:
def test_local_files_error(mocker: MockerFixture) -> None:
"""
must raise exception on package parsing for local sources
"""

View File

@ -139,7 +139,7 @@ async def test_exception_handler_head() -> None:
async def test_exception_handler_method_not_allowed() -> None:
"""
must handle not allowed methodss
must handle not allowed methods
"""
request = pytest.helpers.request("", "", "POST")
request_handler = AsyncMock(side_effect=HTTPMethodNotAllowed("POST", ["GET"]))