refactor: drop _check_output class attribute

This commit is contained in:
2023-10-23 02:24:53 +03:00
parent 42f77742f8
commit 54bd016c17
12 changed files with 81 additions and 95 deletions

View File

@ -17,7 +17,7 @@ def test_repo_add(repo: Repo, mocker: MockerFixture) -> None:
"""
must call repo-add on package addition
"""
check_output_mock = mocker.patch("ahriman.core.alpm.repo.Repo._check_output")
check_output_mock = mocker.patch("ahriman.core.alpm.repo.check_output")
repo.add(Path("path"))
check_output_mock.assert_called_once() # it will be checked later
@ -28,7 +28,7 @@ def test_repo_init(repo: Repo, mocker: MockerFixture) -> None:
"""
must call repo-add with empty package list on repo initializing
"""
check_output_mock = mocker.patch("ahriman.core.alpm.repo.Repo._check_output")
check_output_mock = mocker.patch("ahriman.core.alpm.repo.check_output")
repo.init()
check_output_mock.assert_called_once() # it will be checked later
@ -40,7 +40,7 @@ def test_repo_remove(repo: Repo, mocker: MockerFixture) -> None:
must call repo-remove on package addition
"""
mocker.patch("pathlib.Path.glob", return_value=[])
check_output_mock = mocker.patch("ahriman.core.alpm.repo.Repo._check_output")
check_output_mock = mocker.patch("ahriman.core.alpm.repo.check_output")
repo.remove("package", Path("package.pkg.tar.xz"))
check_output_mock.assert_called_once() # it will be checked later

View File

@ -38,7 +38,7 @@ def test_fetch_empty(remote_source: RemoteSource, mocker: MockerFixture) -> None
"""
mocker.patch("pathlib.Path.is_dir", return_value=True)
mocker.patch("ahriman.core.build_tools.sources.Sources.has_remotes", return_value=False)
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.check_output")
Sources.fetch(Path("local"), remote_source)
check_output_mock.assert_not_called()
@ -50,7 +50,7 @@ def test_fetch_existing(remote_source: RemoteSource, mocker: MockerFixture) -> N
"""
mocker.patch("pathlib.Path.is_dir", return_value=True)
mocker.patch("ahriman.core.build_tools.sources.Sources.has_remotes", return_value=True)
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.check_output")
move_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.move")
local = Path("local")
@ -70,7 +70,7 @@ def test_fetch_new(remote_source: RemoteSource, mocker: MockerFixture) -> None:
must fetch new package via clone command
"""
mocker.patch("pathlib.Path.is_dir", return_value=False)
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.check_output")
move_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.move")
local = Path("local")
@ -90,7 +90,7 @@ def test_fetch_new_without_remote(mocker: MockerFixture) -> None:
must fetch nothing in case if no remote set
"""
mocker.patch("pathlib.Path.is_dir", return_value=False)
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.check_output")
move_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.move")
local = Path("local")
@ -107,7 +107,7 @@ def test_fetch_relative(remote_source: RemoteSource, mocker: MockerFixture) -> N
"""
must process move correctly on relative directory
"""
mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
mocker.patch("ahriman.core.build_tools.sources.check_output")
move_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.move")
Sources.fetch(Path("path"), remote_source)
@ -118,7 +118,7 @@ def test_has_remotes(mocker: MockerFixture) -> None:
"""
must ask for remotes
"""
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output", return_value="origin")
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.check_output", return_value="origin")
local = Path("local")
assert Sources.has_remotes(local)
@ -129,7 +129,7 @@ def test_has_remotes_empty(mocker: MockerFixture) -> None:
"""
must ask for remotes and return false in case if no remotes found
"""
mocker.patch("ahriman.core.build_tools.sources.Sources._check_output", return_value="")
mocker.patch("ahriman.core.build_tools.sources.check_output", return_value="")
assert not Sources.has_remotes(Path("local"))
@ -140,7 +140,7 @@ def test_init(mocker: MockerFixture) -> None:
mocker.patch("ahriman.models.package.Package.local_files", return_value=[Path("local")])
mocker.patch("pathlib.Path.is_dir", return_value=False)
add_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.add")
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.check_output")
commit_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.commit")
local = Path("local")
@ -159,7 +159,7 @@ def test_init_skip(mocker: MockerFixture) -> None:
mocker.patch("pathlib.Path.is_dir", return_value=True)
mocker.patch("ahriman.core.build_tools.sources.Sources.add")
mocker.patch("ahriman.core.build_tools.sources.Sources.commit")
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.check_output")
Sources.init(Path("local"))
check_output_mock.assert_not_called()
@ -234,7 +234,7 @@ def test_push(package_ahriman: Package, mocker: MockerFixture) -> None:
"""
add_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.add")
commit_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.commit", return_value=True)
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.check_output")
commit_author = ("commit author", "user@host")
local = Path("local")
@ -252,7 +252,7 @@ def test_push_skipped(package_ahriman: Package, mocker: MockerFixture) -> None:
"""
mocker.patch("ahriman.core.build_tools.sources.Sources.add")
mocker.patch("ahriman.core.build_tools.sources.Sources.commit", return_value=False)
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.check_output")
Sources.push(Path("local"), package_ahriman.remote)
check_output_mock.assert_not_called()
@ -263,7 +263,7 @@ def test_add(sources: Sources, mocker: MockerFixture) -> None:
must add files to git
"""
glob_mock = mocker.patch("pathlib.Path.glob", return_value=[Path("local/1"), Path("local/2")])
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.check_output")
local = Path("local")
sources.add(local, "pattern1", "pattern2")
@ -278,7 +278,7 @@ def test_add_intent_to_add(sources: Sources, mocker: MockerFixture) -> None:
must add files to git with --intent-to-add flag
"""
glob_mock = mocker.patch("pathlib.Path.glob", return_value=[Path("local/1"), Path("local/2")])
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.check_output")
local = Path("local")
sources.add(local, "pattern1", "pattern2", intent_to_add=True)
@ -293,7 +293,7 @@ def test_add_skip(sources: Sources, mocker: MockerFixture) -> None:
must skip addition of files to index if no fields found
"""
mocker.patch("pathlib.Path.glob", return_value=[])
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.check_output")
sources.add(Path("local"), "pattern1")
check_output_mock.assert_not_called()
@ -304,7 +304,7 @@ def test_commit(sources: Sources, mocker: MockerFixture) -> None:
must commit changes
"""
mocker.patch("ahriman.core.build_tools.sources.Sources.has_changes", return_value=True)
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.check_output")
local = Path("local")
message = "Commit message"
@ -326,7 +326,7 @@ def test_commit_no_changes(sources: Sources, mocker: MockerFixture) -> None:
must skip commit if there are no changes
"""
mocker.patch("ahriman.core.build_tools.sources.Sources.has_changes", return_value=False)
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.check_output")
assert not sources.commit(Path("local"))
check_output_mock.assert_not_called()
@ -337,7 +337,7 @@ def test_commit_author(sources: Sources, mocker: MockerFixture) -> None:
must commit changes with commit author
"""
mocker.patch("ahriman.core.build_tools.sources.Sources.has_changes", return_value=True)
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.check_output")
local = Path("local")
message = "Commit message"
@ -359,7 +359,7 @@ def test_commit_autogenerated_message(sources: Sources, mocker: MockerFixture) -
must commit changes with autogenerated commit message
"""
mocker.patch("ahriman.core.build_tools.sources.Sources.has_changes", return_value=True)
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.check_output")
local = Path("local")
assert sources.commit(Path("local"))
@ -379,7 +379,7 @@ def test_diff(sources: Sources, mocker: MockerFixture) -> None:
"""
must calculate diff
"""
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.check_output")
local = Path("local")
assert sources.diff(local)
@ -392,12 +392,12 @@ def test_has_changes(sources: Sources, mocker: MockerFixture) -> None:
"""
local = Path("local")
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output", return_value="M a.txt")
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.check_output", return_value="M a.txt")
assert sources.has_changes(local)
check_output_mock.assert_called_once_with("git", "diff", "--cached", "--name-only",
cwd=local, logger=pytest.helpers.anyvar(int))
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output", return_value="")
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.check_output", return_value="")
assert not sources.has_changes(local)
check_output_mock.assert_called_once_with("git", "diff", "--cached", "--name-only",
cwd=local, logger=pytest.helpers.anyvar(int))
@ -428,7 +428,7 @@ def test_patch_apply(sources: Sources, mocker: MockerFixture) -> None:
must apply patches if any
"""
patch = PkgbuildPatch(None, "patch")
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.check_output")
local = Path("local")
sources.patch_apply(local, patch)

View File

@ -9,7 +9,7 @@ def test_build(task_ahriman: Task, mocker: MockerFixture) -> None:
"""
must build package
"""
check_output_mock = mocker.patch("ahriman.core.build_tools.task.Task._check_output")
check_output_mock = mocker.patch("ahriman.core.build_tools.task.check_output")
task_ahriman.build(Path("ahriman"))
check_output_mock.assert_called()

View File

@ -107,7 +107,7 @@ def test_key_export(gpg: GPG, mocker: MockerFixture) -> None:
"""
must export gpg key correctly
"""
check_output_mock = mocker.patch("ahriman.core.sign.gpg.GPG._check_output", return_value="key")
check_output_mock = mocker.patch("ahriman.core.sign.gpg.check_output", return_value="key")
assert gpg.key_export("k") == "key"
check_output_mock.assert_called_once_with("gpg", "--armor", "--no-emit-version", "--export", "k",
logger=pytest.helpers.anyvar(int))
@ -118,7 +118,7 @@ def test_key_fingerprint(gpg: GPG, mocker: MockerFixture) -> None:
must extract fingerprint
"""
check_output_mock = mocker.patch(
"ahriman.core.sign.gpg.GPG._check_output",
"ahriman.core.sign.gpg.check_output",
return_value="""tru::1:1576103830:0:3:1:5
fpr:::::::::C6EBB9222C3C8078631A0DE4BD2AC8C5E989490C:
sub:-:4096:1:7E3A4240CE3C45C2:1615121387::::::e::::::23:
@ -135,7 +135,7 @@ def test_key_import(gpg: GPG, mocker: MockerFixture) -> None:
must import PGP key from the server
"""
mocker.patch("ahriman.core.sign.gpg.GPG.key_download", return_value="key")
check_output_mock = mocker.patch("ahriman.core.sign.gpg.GPG._check_output")
check_output_mock = mocker.patch("ahriman.core.sign.gpg.check_output")
gpg.key_import("keyserver.ubuntu.com", "0xE989490C")
check_output_mock.assert_called_once_with("gpg", "--import", input_data="key", logger=pytest.helpers.anyvar(int))
@ -146,7 +146,7 @@ def test_process(gpg_with_key: GPG, mocker: MockerFixture) -> None:
must call process method correctly
"""
result = [Path("a"), Path("a.sig")]
check_output_mock = mocker.patch("ahriman.core.sign.gpg.GPG._check_output")
check_output_mock = mocker.patch("ahriman.core.sign.gpg.check_output")
assert gpg_with_key.process(Path("a"), gpg_with_key.default_key) == result
check_output_mock.assert_called()

View File

@ -8,6 +8,6 @@ def test_sync(rsync: Rsync, mocker: MockerFixture) -> None:
"""
must run sync command
"""
check_output_mock = mocker.patch("ahriman.core.upload.rsync.Rsync._check_output")
check_output_mock = mocker.patch("ahriman.core.upload.rsync.check_output")
rsync.sync(Path("path"), [])
check_output_mock.assert_called_once_with(*rsync.command, "path", rsync.remote, logger=rsync.logger)

View File

@ -54,7 +54,7 @@ def test_depends_build_with_version_and_overlap(mocker: MockerFixture, resource_
"""
srcinfo = (resource_path_root / "models" / "package_gcc10_srcinfo").read_text()
mocker.patch("ahriman.models.package.Package._check_output", return_value=srcinfo)
mocker.patch("ahriman.models.package.check_output", return_value=srcinfo)
package_gcc10 = Package.from_build(Path("local"), "x86_64", None)
assert package_gcc10.depends_build == {
@ -182,7 +182,7 @@ def test_from_build(package_ahriman: Package, mocker: MockerFixture, resource_pa
must construct package from srcinfo
"""
srcinfo = (resource_path_root / "models" / "package_ahriman_srcinfo").read_text()
mocker.patch("ahriman.models.package.Package._check_output", return_value=srcinfo)
mocker.patch("ahriman.models.package.check_output", return_value=srcinfo)
package = Package.from_build(Path("path"), "x86_64", "packager")
assert package_ahriman.packages.keys() == package.packages.keys()
@ -196,7 +196,7 @@ def test_from_build_multiple_packages(mocker: MockerFixture, resource_path_root:
must construct package from srcinfo with dependencies per-package overrides
"""
srcinfo = (resource_path_root / "models" / "package_gcc10_srcinfo").read_text()
mocker.patch("ahriman.models.package.Package._check_output", return_value=srcinfo)
mocker.patch("ahriman.models.package.check_output", return_value=srcinfo)
package = Package.from_build(Path("path"), "x86_64", None)
assert package.packages == {
@ -226,7 +226,7 @@ def test_from_build_architecture(mocker: MockerFixture, resource_path_root: Path
must construct package with architecture specific depends list
"""
srcinfo = (resource_path_root / "models" / "package_jellyfin-ffmpeg5-bin_srcinfo").read_text()
mocker.patch("ahriman.models.package.Package._check_output", return_value=srcinfo)
mocker.patch("ahriman.models.package.check_output", return_value=srcinfo)
package = Package.from_build(Path("path"), "x86_64", None)
assert package.packages == {
@ -253,7 +253,7 @@ def test_from_build_failed(package_ahriman: Package, mocker: MockerFixture) -> N
"""
must raise exception if there are errors during srcinfo load
"""
mocker.patch("ahriman.models.package.Package._check_output", return_value="")
mocker.patch("ahriman.models.package.check_output", return_value="")
mocker.patch("ahriman.models.package.parse_srcinfo", return_value=({"packages": {}}, ["an error"]))
with pytest.raises(PackageInfoError):
@ -303,7 +303,7 @@ def test_local_files(mocker: MockerFixture, resource_path_root: Path) -> None:
parsed_srcinfo, _ = parse_srcinfo(srcinfo)
parsed_srcinfo["source"] = ["local-file.tar.gz"]
mocker.patch("ahriman.models.package.parse_srcinfo", return_value=(parsed_srcinfo, []))
mocker.patch("ahriman.models.package.Package._check_output", return_value=srcinfo)
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"))) == [Path("local-file.tar.gz")]
@ -314,7 +314,7 @@ def test_local_files_empty(mocker: MockerFixture, resource_path_root: Path) -> N
must extract empty local files list when there is no local files
"""
srcinfo = (resource_path_root / "models" / "package_yay_srcinfo").read_text()
mocker.patch("ahriman.models.package.Package._check_output", return_value=srcinfo)
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"))) == []
@ -324,7 +324,7 @@ def test_local_files_error(mocker: MockerFixture, resource_path_root: Path) -> N
"""
must raise exception on package parsing for local sources
"""
mocker.patch("ahriman.models.package.Package._check_output", return_value="")
mocker.patch("ahriman.models.package.check_output", return_value="")
mocker.patch("ahriman.models.package.parse_srcinfo", return_value=({"packages": {}}, ["an error"]))
with pytest.raises(PackageInfoError):
@ -339,7 +339,7 @@ def test_local_files_schema(mocker: MockerFixture, resource_path_root: Path) ->
parsed_srcinfo, _ = parse_srcinfo(srcinfo)
parsed_srcinfo["source"] = ["file:///local-file.tar.gz"]
mocker.patch("ahriman.models.package.parse_srcinfo", return_value=(parsed_srcinfo, []))
mocker.patch("ahriman.models.package.Package._check_output", return_value="")
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"))) == []
@ -353,7 +353,7 @@ def test_local_files_with_install(mocker: MockerFixture, resource_path_root: Pat
parsed_srcinfo, _ = parse_srcinfo(srcinfo)
parsed_srcinfo["install"] = "install"
mocker.patch("ahriman.models.package.parse_srcinfo", return_value=(parsed_srcinfo, []))
mocker.patch("ahriman.models.package.Package._check_output", return_value="")
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"))) == [Path("install")]
@ -364,7 +364,7 @@ def test_supported_architectures(mocker: MockerFixture, resource_path_root: Path
must generate list of available architectures
"""
srcinfo = (resource_path_root / "models" / "package_yay_srcinfo").read_text()
mocker.patch("ahriman.models.package.Package._check_output", return_value=srcinfo)
mocker.patch("ahriman.models.package.check_output", return_value=srcinfo)
assert Package.supported_architectures(Path("path")) == \
{"i686", "pentium4", "x86_64", "arm", "armv7h", "armv6h", "aarch64"}
@ -373,7 +373,7 @@ def test_supported_architectures_failed(mocker: MockerFixture) -> None:
"""
must raise exception if there are errors during srcinfo load for architectures
"""
mocker.patch("ahriman.models.package.Package._check_output", return_value="")
mocker.patch("ahriman.models.package.check_output", return_value="")
mocker.patch("ahriman.models.package.parse_srcinfo", return_value=({"packages": {}}, ["an error"]))
with pytest.raises(PackageInfoError):
@ -393,7 +393,7 @@ def test_actual_version_vcs(package_tpacpi_bat_git: Package, repository_paths: R
must return valid actual_version for VCS package
"""
srcinfo = (resource_path_root / "models" / "package_tpacpi-bat-git_srcinfo").read_text()
mocker.patch("ahriman.models.package.Package._check_output", return_value=srcinfo)
mocker.patch("ahriman.models.package.check_output", return_value=srcinfo)
mocker.patch("ahriman.core.build_tools.sources.Sources.load")
assert package_tpacpi_bat_git.actual_version(repository_paths) == "3.1.r13.g4959b52-1"
@ -404,7 +404,7 @@ def test_actual_version_srcinfo_failed(package_tpacpi_bat_git: Package, reposito
"""
must return same version in case if exception occurred
"""
mocker.patch("ahriman.models.package.Package._check_output", side_effect=Exception())
mocker.patch("ahriman.models.package.check_output", side_effect=Exception())
mocker.patch("ahriman.core.build_tools.sources.Sources.load")
assert package_tpacpi_bat_git.actual_version(repository_paths) == package_tpacpi_bat_git.version
@ -417,7 +417,7 @@ def test_actual_version_vcs_failed(package_tpacpi_bat_git: Package, repository_p
"""
mocker.patch("pathlib.Path.read_text", return_value="")
mocker.patch("ahriman.models.package.parse_srcinfo", return_value=({"packages": {}}, ["an error"]))
mocker.patch("ahriman.models.package.Package._check_output")
mocker.patch("ahriman.models.package.check_output")
mocker.patch("ahriman.core.build_tools.sources.Sources.load")
assert package_tpacpi_bat_git.actual_version(repository_paths) == package_tpacpi_bat_git.version