From 54bd016c173efc3db994da56a74ffdf58b0a8f31 Mon Sep 17 00:00:00 2001 From: Evgenii Alekseev Date: Mon, 23 Oct 2023 02:24:53 +0300 Subject: [PATCH] refactor: drop _check_output class attribute --- src/ahriman/core/alpm/repo.py | 10 ++--- src/ahriman/core/build_tools/sources.py | 39 ++++++++-------- src/ahriman/core/build_tools/task.py | 6 +-- src/ahriman/core/sign/gpg.py | 10 ++--- src/ahriman/core/upload/rsync.py | 4 +- src/ahriman/models/package.py | 15 +++---- tests/ahriman/core/alpm/test_repo.py | 6 +-- .../ahriman/core/build_tools/test_sources.py | 44 +++++++++---------- tests/ahriman/core/build_tools/test_task.py | 2 +- tests/ahriman/core/sign/test_gpg.py | 8 ++-- tests/ahriman/core/upload/test_rsync.py | 2 +- tests/ahriman/models/test_package.py | 30 ++++++------- 12 files changed, 81 insertions(+), 95 deletions(-) diff --git a/src/ahriman/core/alpm/repo.py b/src/ahriman/core/alpm/repo.py index 834e9be0..da140353 100644 --- a/src/ahriman/core/alpm/repo.py +++ b/src/ahriman/core/alpm/repo.py @@ -36,8 +36,6 @@ class Repo(LazyLogging): uid(int): uid of the repository owner user """ - _check_output = check_output - def __init__(self, name: str, paths: RepositoryPaths, sign_args: list[str]) -> None: """ default constructor @@ -69,7 +67,7 @@ class Repo(LazyLogging): Args: path(Path): path to archive to add """ - Repo._check_output( + check_output( "repo-add", *self.sign_args, "-R", str(self.repo_path), str(path), exception=BuildError.from_process(path.name), cwd=self.paths.repository, @@ -80,8 +78,8 @@ class Repo(LazyLogging): """ create empty repository database """ - Repo._check_output("repo-add", *self.sign_args, str(self.repo_path), - cwd=self.paths.repository, logger=self.logger, user=self.uid) + check_output("repo-add", *self.sign_args, str(self.repo_path), + cwd=self.paths.repository, logger=self.logger, user=self.uid) def remove(self, package: str, filename: Path) -> None: """ @@ -96,7 +94,7 @@ class Repo(LazyLogging): full_path.unlink() # remove package from registry - Repo._check_output( + check_output( "repo-remove", *self.sign_args, str(self.repo_path), package, exception=BuildError.from_process(package), cwd=self.paths.repository, diff --git a/src/ahriman/core/build_tools/sources.py b/src/ahriman/core/build_tools/sources.py index 0de21adc..536ee82e 100644 --- a/src/ahriman/core/build_tools/sources.py +++ b/src/ahriman/core/build_tools/sources.py @@ -42,8 +42,6 @@ class Sources(LazyLogging): DEFAULT_BRANCH = "master" # default fallback branch DEFAULT_COMMIT_AUTHOR = ("ahriman", "ahriman@localhost") - _check_output = check_output - @staticmethod def extend_architectures(sources_dir: Path, architecture: str) -> list[PkgbuildPatch]: """ @@ -82,20 +80,20 @@ class Sources(LazyLogging): branch = remote.branch or instance.DEFAULT_BRANCH if is_initialized_git: instance.logger.info("update HEAD to remote at %s using branch %s", sources_dir, branch) - Sources._check_output("git", "fetch", "--quiet", "--depth", "1", "origin", branch, - cwd=sources_dir, logger=instance.logger) + check_output("git", "fetch", "--quiet", "--depth", "1", "origin", branch, + cwd=sources_dir, logger=instance.logger) elif remote.git_url is not None: instance.logger.info("clone remote %s to %s using branch %s", remote.git_url, sources_dir, branch) - Sources._check_output("git", "clone", "--quiet", "--depth", "1", "--branch", branch, "--single-branch", - remote.git_url, str(sources_dir), cwd=sources_dir.parent, logger=instance.logger) + check_output("git", "clone", "--quiet", "--depth", "1", "--branch", branch, "--single-branch", + remote.git_url, str(sources_dir), cwd=sources_dir.parent, logger=instance.logger) else: # it will cause an exception later instance.logger.error("%s is not initialized, but no remote provided", sources_dir) # and now force reset to our branch - Sources._check_output("git", "checkout", "--force", branch, cwd=sources_dir, logger=instance.logger) - Sources._check_output("git", "reset", "--quiet", "--hard", f"origin/{branch}", - cwd=sources_dir, logger=instance.logger) + check_output("git", "checkout", "--force", branch, cwd=sources_dir, logger=instance.logger) + check_output("git", "reset", "--quiet", "--hard", f"origin/{branch}", + cwd=sources_dir, logger=instance.logger) # move content if required # we are using full path to source directory in order to make append possible @@ -114,7 +112,7 @@ class Sources(LazyLogging): bool: True in case if there is any remote and false otherwise """ instance = Sources() - remotes = Sources._check_output("git", "remote", cwd=sources_dir, logger=instance.logger) + remotes = check_output("git", "remote", cwd=sources_dir, logger=instance.logger) return bool(remotes) @staticmethod @@ -128,8 +126,8 @@ class Sources(LazyLogging): instance = Sources() if not (sources_dir / ".git").is_dir(): # skip initializing in case if it was already - Sources._check_output("git", "init", "--quiet", "--initial-branch", instance.DEFAULT_BRANCH, - cwd=sources_dir, logger=instance.logger) + check_output("git", "init", "--quiet", "--initial-branch", instance.DEFAULT_BRANCH, + cwd=sources_dir, logger=instance.logger) # extract local files... files = ["PKGBUILD", ".SRCINFO"] + [str(path) for path in Package.local_files(sources_dir)] @@ -193,7 +191,7 @@ class Sources(LazyLogging): return # no changes to push, just skip action git_url, branch = remote.git_source() - Sources._check_output("git", "push", "--quiet", git_url, branch, cwd=sources_dir, logger=instance.logger) + check_output("git", "push", "--quiet", git_url, branch, cwd=sources_dir, logger=instance.logger) def add(self, sources_dir: Path, *pattern: str, intent_to_add: bool = False) -> None: """ @@ -214,8 +212,8 @@ class Sources(LazyLogging): self.logger.info("found matching files %s", found_files) # add them to index args = ["--intent-to-add"] if intent_to_add else [] - Sources._check_output("git", "add", *args, *[str(fn.relative_to(sources_dir)) for fn in found_files], - cwd=sources_dir, logger=self.logger) + check_output("git", "add", *args, *[str(fn.relative_to(sources_dir)) for fn in found_files], + cwd=sources_dir, logger=self.logger) def commit(self, sources_dir: Path, message: str | None = None, commit_author: tuple[str, str] | None = None) -> bool: @@ -245,8 +243,7 @@ class Sources(LazyLogging): environment["GIT_AUTHOR_NAME"] = environment["GIT_COMMITTER_NAME"] = user environment["GIT_AUTHOR_EMAIL"] = environment["GIT_COMMITTER_EMAIL"] = email - Sources._check_output("git", "commit", "--quiet", *args, - cwd=sources_dir, logger=self.logger, environment=environment) + check_output("git", "commit", "--quiet", *args, cwd=sources_dir, logger=self.logger, environment=environment) return True @@ -260,7 +257,7 @@ class Sources(LazyLogging): Returns: str: patch as plain string """ - return Sources._check_output("git", "diff", cwd=sources_dir, logger=self.logger) + return check_output("git", "diff", cwd=sources_dir, logger=self.logger) def has_changes(self, sources_dir: Path) -> bool: """ @@ -273,7 +270,7 @@ class Sources(LazyLogging): bool: True if there are uncommitted changes and False otherwise """ # there is --exit-code argument to diff, however, there might be other process errors - changes = Sources._check_output("git", "diff", "--cached", "--name-only", cwd=sources_dir, logger=self.logger) + changes = check_output("git", "diff", "--cached", "--name-only", cwd=sources_dir, logger=self.logger) return bool(changes) def move(self, pkgbuild_dir: Path, sources_dir: Path) -> None: @@ -302,7 +299,7 @@ class Sources(LazyLogging): # create patch self.logger.info("apply patch %s from database at %s", patch.key, sources_dir) if patch.is_plain_diff: - Sources._check_output("git", "apply", "--ignore-space-change", "--ignore-whitespace", - cwd=sources_dir, input_data=patch.serialize(), logger=self.logger) + check_output("git", "apply", "--ignore-space-change", "--ignore-whitespace", + cwd=sources_dir, input_data=patch.serialize(), logger=self.logger) else: patch.write(sources_dir / "PKGBUILD") diff --git a/src/ahriman/core/build_tools/task.py b/src/ahriman/core/build_tools/task.py index 0e30e146..5402f36f 100644 --- a/src/ahriman/core/build_tools/task.py +++ b/src/ahriman/core/build_tools/task.py @@ -45,8 +45,6 @@ class Task(LazyLogging): uid(int): uid of the repository owner user """ - _check_output = check_output - def __init__(self, package: Package, configuration: Configuration, architecture: str, paths: RepositoryPaths) -> None: """ @@ -92,7 +90,7 @@ class Task(LazyLogging): } self.logger.info("using environment variables %s", environment) - Task._check_output( + check_output( *command, exception=BuildError.from_process(self.package.base), cwd=sources_dir, @@ -102,7 +100,7 @@ class Task(LazyLogging): ) # well it is not actually correct, but we can deal with it - packages = Task._check_output( + packages = check_output( "makepkg", "--packagelist", exception=BuildError.from_process(self.package.base), cwd=sources_dir, diff --git a/src/ahriman/core/sign/gpg.py b/src/ahriman/core/sign/gpg.py index 30f26373..24a34b56 100644 --- a/src/ahriman/core/sign/gpg.py +++ b/src/ahriman/core/sign/gpg.py @@ -36,8 +36,6 @@ class GPG(SyncHttpClient): targets(set[SignSettings]): list of targets to sign (repository, package etc.) """ - _check_output = check_output - def __init__(self, configuration: Configuration) -> None: """ default constructor @@ -140,7 +138,7 @@ class GPG(SyncHttpClient): Returns: str: PGP key in .asc format """ - return GPG._check_output("gpg", "--armor", "--no-emit-version", "--export", key, logger=self.logger) + return check_output("gpg", "--armor", "--no-emit-version", "--export", key, logger=self.logger) def key_fingerprint(self, key: str) -> str: """ @@ -152,7 +150,7 @@ class GPG(SyncHttpClient): Returns: str: full PGP key fingerprint """ - metadata = GPG._check_output("gpg", "--with-colons", "--fingerprint", key, logger=self.logger) + metadata = check_output("gpg", "--with-colons", "--fingerprint", key, logger=self.logger) # fingerprint line will be like # fpr:::::::::43A663569A07EE1E4ECC55CC7E3A4240CE3C45C2: fingerprint = next(filter(lambda line: line[:3] == "fpr", metadata.splitlines())) @@ -167,7 +165,7 @@ class GPG(SyncHttpClient): key(str): key ID to import """ key_body = self.key_download(server, key) - GPG._check_output("gpg", "--import", input_data=key_body, logger=self.logger) + check_output("gpg", "--import", input_data=key_body, logger=self.logger) def process(self, path: Path, key: str) -> list[Path]: """ @@ -180,7 +178,7 @@ class GPG(SyncHttpClient): Returns: list[Path]: list of generated files including original file """ - GPG._check_output( + check_output( *GPG.sign_command(path, key), exception=BuildError.from_process(path.name), logger=self.logger) diff --git a/src/ahriman/core/upload/rsync.py b/src/ahriman/core/upload/rsync.py index 8f5db29d..2bab81e3 100644 --- a/src/ahriman/core/upload/rsync.py +++ b/src/ahriman/core/upload/rsync.py @@ -35,8 +35,6 @@ class Rsync(Upload): remote(str): remote address to sync """ - _check_output = check_output - def __init__(self, repository_id: RepositoryId, configuration: Configuration, section: str) -> None: """ default constructor @@ -58,4 +56,4 @@ class Rsync(Upload): path(Path): local path to sync built_packages(list[Package]): list of packages which has just been built """ - Rsync._check_output(*self.command, str(path), self.remote, logger=self.logger) + check_output(*self.command, str(path), self.remote, logger=self.logger) diff --git a/src/ahriman/models/package.py b/src/ahriman/models/package.py index 5f306ba2..8e33572d 100644 --- a/src/ahriman/models/package.py +++ b/src/ahriman/models/package.py @@ -80,8 +80,6 @@ class Package(LazyLogging): packages: dict[str, PackageDescription] packager: str | None = None - _check_output = check_output - @property def depends(self) -> list[str]: """ @@ -259,7 +257,7 @@ class Package(LazyLogging): Raises: PackageInfoError: if there are parsing errors """ - srcinfo_source = Package._check_output("makepkg", "--printsrcinfo", cwd=path) + srcinfo_source = check_output("makepkg", "--printsrcinfo", cwd=path) srcinfo, errors = parse_srcinfo(srcinfo_source) if errors: raise PackageInfoError(errors) @@ -363,7 +361,7 @@ class Package(LazyLogging): Raises: PackageInfoError: if there are parsing errors """ - srcinfo_source = Package._check_output("makepkg", "--printsrcinfo", cwd=path) + srcinfo_source = check_output("makepkg", "--printsrcinfo", cwd=path) srcinfo, errors = parse_srcinfo(srcinfo_source) if errors: raise PackageInfoError(errors) @@ -400,7 +398,7 @@ class Package(LazyLogging): Raises: PackageInfoError: if there are parsing errors """ - srcinfo_source = Package._check_output("makepkg", "--printsrcinfo", cwd=path) + srcinfo_source = check_output("makepkg", "--printsrcinfo", cwd=path) srcinfo, errors = parse_srcinfo(srcinfo_source) if errors: raise PackageInfoError(errors) @@ -448,11 +446,10 @@ class Package(LazyLogging): try: # update pkgver first - Package._check_output("makepkg", "--nodeps", "--nobuild", - cwd=paths.cache_for(self.base), logger=self.logger) + check_output("makepkg", "--nodeps", "--nobuild", cwd=paths.cache_for(self.base), logger=self.logger) # generate new .SRCINFO and put it to parser - srcinfo_source = Package._check_output("makepkg", "--printsrcinfo", - cwd=paths.cache_for(self.base), logger=self.logger) + srcinfo_source = check_output("makepkg", "--printsrcinfo", + cwd=paths.cache_for(self.base), logger=self.logger) srcinfo, errors = parse_srcinfo(srcinfo_source) if errors: raise PackageInfoError(errors) diff --git a/tests/ahriman/core/alpm/test_repo.py b/tests/ahriman/core/alpm/test_repo.py index 38a4a1c6..db52b1e3 100644 --- a/tests/ahriman/core/alpm/test_repo.py +++ b/tests/ahriman/core/alpm/test_repo.py @@ -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 diff --git a/tests/ahriman/core/build_tools/test_sources.py b/tests/ahriman/core/build_tools/test_sources.py index 45f10630..c2a35b94 100644 --- a/tests/ahriman/core/build_tools/test_sources.py +++ b/tests/ahriman/core/build_tools/test_sources.py @@ -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) diff --git a/tests/ahriman/core/build_tools/test_task.py b/tests/ahriman/core/build_tools/test_task.py index 742df180..e59ef5b5 100644 --- a/tests/ahriman/core/build_tools/test_task.py +++ b/tests/ahriman/core/build_tools/test_task.py @@ -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() diff --git a/tests/ahriman/core/sign/test_gpg.py b/tests/ahriman/core/sign/test_gpg.py index 802698c7..7d2cdf75 100644 --- a/tests/ahriman/core/sign/test_gpg.py +++ b/tests/ahriman/core/sign/test_gpg.py @@ -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() diff --git a/tests/ahriman/core/upload/test_rsync.py b/tests/ahriman/core/upload/test_rsync.py index b38959e1..57a76e38 100644 --- a/tests/ahriman/core/upload/test_rsync.py +++ b/tests/ahriman/core/upload/test_rsync.py @@ -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) diff --git a/tests/ahriman/models/test_package.py b/tests/ahriman/models/test_package.py index 79709eb9..daf764c5 100644 --- a/tests/ahriman/models/test_package.py +++ b/tests/ahriman/models/test_package.py @@ -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