refactor: fix warnings and typos, cleanup code

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

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)