refactor: drop _check_output class attribute

This commit is contained in:
Evgenii Alekseev 2023-10-23 02:24:53 +03:00
parent 4b6feb9ae6
commit 8524f1eb20
12 changed files with 81 additions and 95 deletions

View File

@ -36,8 +36,6 @@ class Repo(LazyLogging):
uid(int): uid of the repository owner user uid(int): uid of the repository owner user
""" """
_check_output = check_output
def __init__(self, name: str, paths: RepositoryPaths, sign_args: list[str]) -> None: def __init__(self, name: str, paths: RepositoryPaths, sign_args: list[str]) -> None:
""" """
default constructor default constructor
@ -69,7 +67,7 @@ class Repo(LazyLogging):
Args: Args:
path(Path): path to archive to add path(Path): path to archive to add
""" """
Repo._check_output( check_output(
"repo-add", *self.sign_args, "-R", str(self.repo_path), str(path), "repo-add", *self.sign_args, "-R", str(self.repo_path), str(path),
exception=BuildError.from_process(path.name), exception=BuildError.from_process(path.name),
cwd=self.paths.repository, cwd=self.paths.repository,
@ -80,7 +78,7 @@ class Repo(LazyLogging):
""" """
create empty repository database create empty repository database
""" """
Repo._check_output("repo-add", *self.sign_args, str(self.repo_path), check_output("repo-add", *self.sign_args, str(self.repo_path),
cwd=self.paths.repository, logger=self.logger, user=self.uid) cwd=self.paths.repository, logger=self.logger, user=self.uid)
def remove(self, package: str, filename: Path) -> None: def remove(self, package: str, filename: Path) -> None:
@ -96,7 +94,7 @@ class Repo(LazyLogging):
full_path.unlink() full_path.unlink()
# remove package from registry # remove package from registry
Repo._check_output( check_output(
"repo-remove", *self.sign_args, str(self.repo_path), package, "repo-remove", *self.sign_args, str(self.repo_path), package,
exception=BuildError.from_process(package), exception=BuildError.from_process(package),
cwd=self.paths.repository, cwd=self.paths.repository,

View File

@ -42,8 +42,6 @@ class Sources(LazyLogging):
DEFAULT_BRANCH = "master" # default fallback branch DEFAULT_BRANCH = "master" # default fallback branch
DEFAULT_COMMIT_AUTHOR = ("ahriman", "ahriman@localhost") DEFAULT_COMMIT_AUTHOR = ("ahriman", "ahriman@localhost")
_check_output = check_output
@staticmethod @staticmethod
def extend_architectures(sources_dir: Path, architecture: str) -> list[PkgbuildPatch]: def extend_architectures(sources_dir: Path, architecture: str) -> list[PkgbuildPatch]:
""" """
@ -82,19 +80,19 @@ class Sources(LazyLogging):
branch = remote.branch or instance.DEFAULT_BRANCH branch = remote.branch or instance.DEFAULT_BRANCH
if is_initialized_git: if is_initialized_git:
instance.logger.info("update HEAD to remote at %s using branch %s", sources_dir, branch) 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, check_output("git", "fetch", "--quiet", "--depth", "1", "origin", branch,
cwd=sources_dir, logger=instance.logger) cwd=sources_dir, logger=instance.logger)
elif remote.git_url is not None: elif remote.git_url is not None:
instance.logger.info("clone remote %s to %s using branch %s", remote.git_url, sources_dir, branch) 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", check_output("git", "clone", "--quiet", "--depth", "1", "--branch", branch, "--single-branch",
remote.git_url, str(sources_dir), cwd=sources_dir.parent, logger=instance.logger) remote.git_url, str(sources_dir), cwd=sources_dir.parent, logger=instance.logger)
else: else:
# it will cause an exception later # it will cause an exception later
instance.logger.error("%s is not initialized, but no remote provided", sources_dir) instance.logger.error("%s is not initialized, but no remote provided", sources_dir)
# and now force reset to our branch # and now force reset to our branch
Sources._check_output("git", "checkout", "--force", branch, cwd=sources_dir, logger=instance.logger) check_output("git", "checkout", "--force", branch, cwd=sources_dir, logger=instance.logger)
Sources._check_output("git", "reset", "--quiet", "--hard", f"origin/{branch}", check_output("git", "reset", "--quiet", "--hard", f"origin/{branch}",
cwd=sources_dir, logger=instance.logger) cwd=sources_dir, logger=instance.logger)
# move content if required # move content if required
@ -114,7 +112,7 @@ class Sources(LazyLogging):
bool: True in case if there is any remote and false otherwise bool: True in case if there is any remote and false otherwise
""" """
instance = Sources() 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) return bool(remotes)
@staticmethod @staticmethod
@ -128,7 +126,7 @@ class Sources(LazyLogging):
instance = Sources() instance = Sources()
if not (sources_dir / ".git").is_dir(): if not (sources_dir / ".git").is_dir():
# skip initializing in case if it was already # skip initializing in case if it was already
Sources._check_output("git", "init", "--quiet", "--initial-branch", instance.DEFAULT_BRANCH, check_output("git", "init", "--quiet", "--initial-branch", instance.DEFAULT_BRANCH,
cwd=sources_dir, logger=instance.logger) cwd=sources_dir, logger=instance.logger)
# extract local files... # extract local files...
@ -193,7 +191,7 @@ class Sources(LazyLogging):
return # no changes to push, just skip action return # no changes to push, just skip action
git_url, branch = remote.git_source() 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: def add(self, sources_dir: Path, *pattern: str, intent_to_add: bool = False) -> None:
""" """
@ -214,7 +212,7 @@ class Sources(LazyLogging):
self.logger.info("found matching files %s", found_files) self.logger.info("found matching files %s", found_files)
# add them to index # add them to index
args = ["--intent-to-add"] if intent_to_add else [] 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], check_output("git", "add", *args, *[str(fn.relative_to(sources_dir)) for fn in found_files],
cwd=sources_dir, logger=self.logger) cwd=sources_dir, logger=self.logger)
def commit(self, sources_dir: Path, message: str | None = None, def commit(self, sources_dir: Path, message: str | None = None,
@ -245,8 +243,7 @@ class Sources(LazyLogging):
environment["GIT_AUTHOR_NAME"] = environment["GIT_COMMITTER_NAME"] = user environment["GIT_AUTHOR_NAME"] = environment["GIT_COMMITTER_NAME"] = user
environment["GIT_AUTHOR_EMAIL"] = environment["GIT_COMMITTER_EMAIL"] = email environment["GIT_AUTHOR_EMAIL"] = environment["GIT_COMMITTER_EMAIL"] = email
Sources._check_output("git", "commit", "--quiet", *args, check_output("git", "commit", "--quiet", *args, cwd=sources_dir, logger=self.logger, environment=environment)
cwd=sources_dir, logger=self.logger, environment=environment)
return True return True
@ -260,7 +257,7 @@ class Sources(LazyLogging):
Returns: Returns:
str: patch as plain string 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: 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 bool: True if there are uncommitted changes and False otherwise
""" """
# there is --exit-code argument to diff, however, there might be other process errors # 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) return bool(changes)
def move(self, pkgbuild_dir: Path, sources_dir: Path) -> None: def move(self, pkgbuild_dir: Path, sources_dir: Path) -> None:
@ -302,7 +299,7 @@ class Sources(LazyLogging):
# create patch # create patch
self.logger.info("apply patch %s from database at %s", patch.key, sources_dir) self.logger.info("apply patch %s from database at %s", patch.key, sources_dir)
if patch.is_plain_diff: if patch.is_plain_diff:
Sources._check_output("git", "apply", "--ignore-space-change", "--ignore-whitespace", check_output("git", "apply", "--ignore-space-change", "--ignore-whitespace",
cwd=sources_dir, input_data=patch.serialize(), logger=self.logger) cwd=sources_dir, input_data=patch.serialize(), logger=self.logger)
else: else:
patch.write(sources_dir / "PKGBUILD") patch.write(sources_dir / "PKGBUILD")

View File

@ -45,8 +45,6 @@ class Task(LazyLogging):
uid(int): uid of the repository owner user uid(int): uid of the repository owner user
""" """
_check_output = check_output
def __init__(self, package: Package, configuration: Configuration, architecture: str, def __init__(self, package: Package, configuration: Configuration, architecture: str,
paths: RepositoryPaths) -> None: paths: RepositoryPaths) -> None:
""" """
@ -92,7 +90,7 @@ class Task(LazyLogging):
} }
self.logger.info("using environment variables %s", environment) self.logger.info("using environment variables %s", environment)
Task._check_output( check_output(
*command, *command,
exception=BuildError.from_process(self.package.base), exception=BuildError.from_process(self.package.base),
cwd=sources_dir, cwd=sources_dir,
@ -102,7 +100,7 @@ class Task(LazyLogging):
) )
# well it is not actually correct, but we can deal with it # well it is not actually correct, but we can deal with it
packages = Task._check_output( packages = check_output(
"makepkg", "--packagelist", "makepkg", "--packagelist",
exception=BuildError.from_process(self.package.base), exception=BuildError.from_process(self.package.base),
cwd=sources_dir, cwd=sources_dir,

View File

@ -36,8 +36,6 @@ class GPG(SyncHttpClient):
targets(set[SignSettings]): list of targets to sign (repository, package etc.) targets(set[SignSettings]): list of targets to sign (repository, package etc.)
""" """
_check_output = check_output
def __init__(self, configuration: Configuration) -> None: def __init__(self, configuration: Configuration) -> None:
""" """
default constructor default constructor
@ -140,7 +138,7 @@ class GPG(SyncHttpClient):
Returns: Returns:
str: PGP key in .asc format 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: def key_fingerprint(self, key: str) -> str:
""" """
@ -152,7 +150,7 @@ class GPG(SyncHttpClient):
Returns: Returns:
str: full PGP key fingerprint 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 # fingerprint line will be like
# fpr:::::::::43A663569A07EE1E4ECC55CC7E3A4240CE3C45C2: # fpr:::::::::43A663569A07EE1E4ECC55CC7E3A4240CE3C45C2:
fingerprint = next(filter(lambda line: line[:3] == "fpr", metadata.splitlines())) fingerprint = next(filter(lambda line: line[:3] == "fpr", metadata.splitlines()))
@ -167,7 +165,7 @@ class GPG(SyncHttpClient):
key(str): key ID to import key(str): key ID to import
""" """
key_body = self.key_download(server, key) 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]: def process(self, path: Path, key: str) -> list[Path]:
""" """
@ -180,7 +178,7 @@ class GPG(SyncHttpClient):
Returns: Returns:
list[Path]: list of generated files including original file list[Path]: list of generated files including original file
""" """
GPG._check_output( check_output(
*GPG.sign_command(path, key), *GPG.sign_command(path, key),
exception=BuildError.from_process(path.name), exception=BuildError.from_process(path.name),
logger=self.logger) logger=self.logger)

View File

@ -35,8 +35,6 @@ class Rsync(Upload):
remote(str): remote address to sync remote(str): remote address to sync
""" """
_check_output = check_output
def __init__(self, repository_id: RepositoryId, configuration: Configuration, section: str) -> None: def __init__(self, repository_id: RepositoryId, configuration: Configuration, section: str) -> None:
""" """
default constructor default constructor
@ -58,4 +56,4 @@ class Rsync(Upload):
path(Path): local path to sync path(Path): local path to sync
built_packages(list[Package]): list of packages which has just been built 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)

View File

@ -80,8 +80,6 @@ class Package(LazyLogging):
packages: dict[str, PackageDescription] packages: dict[str, PackageDescription]
packager: str | None = None packager: str | None = None
_check_output = check_output
@property @property
def depends(self) -> list[str]: def depends(self) -> list[str]:
""" """
@ -259,7 +257,7 @@ class Package(LazyLogging):
Raises: Raises:
PackageInfoError: if there are parsing errors 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) srcinfo, errors = parse_srcinfo(srcinfo_source)
if errors: if errors:
raise PackageInfoError(errors) raise PackageInfoError(errors)
@ -363,7 +361,7 @@ class Package(LazyLogging):
Raises: Raises:
PackageInfoError: if there are parsing errors 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) srcinfo, errors = parse_srcinfo(srcinfo_source)
if errors: if errors:
raise PackageInfoError(errors) raise PackageInfoError(errors)
@ -400,7 +398,7 @@ class Package(LazyLogging):
Raises: Raises:
PackageInfoError: if there are parsing errors 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) srcinfo, errors = parse_srcinfo(srcinfo_source)
if errors: if errors:
raise PackageInfoError(errors) raise PackageInfoError(errors)
@ -448,10 +446,9 @@ class Package(LazyLogging):
try: try:
# update pkgver first # update pkgver first
Package._check_output("makepkg", "--nodeps", "--nobuild", check_output("makepkg", "--nodeps", "--nobuild", cwd=paths.cache_for(self.base), logger=self.logger)
cwd=paths.cache_for(self.base), logger=self.logger)
# generate new .SRCINFO and put it to parser # generate new .SRCINFO and put it to parser
srcinfo_source = Package._check_output("makepkg", "--printsrcinfo", srcinfo_source = check_output("makepkg", "--printsrcinfo",
cwd=paths.cache_for(self.base), logger=self.logger) cwd=paths.cache_for(self.base), logger=self.logger)
srcinfo, errors = parse_srcinfo(srcinfo_source) srcinfo, errors = parse_srcinfo(srcinfo_source)
if errors: if errors:

View File

@ -17,7 +17,7 @@ def test_repo_add(repo: Repo, mocker: MockerFixture) -> None:
""" """
must call repo-add on package addition 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")) repo.add(Path("path"))
check_output_mock.assert_called_once() # it will be checked later 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 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() repo.init()
check_output_mock.assert_called_once() # it will be checked later 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 must call repo-remove on package addition
""" """
mocker.patch("pathlib.Path.glob", return_value=[]) 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")) repo.remove("package", Path("package.pkg.tar.xz"))
check_output_mock.assert_called_once() # it will be checked later 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("pathlib.Path.is_dir", return_value=True)
mocker.patch("ahriman.core.build_tools.sources.Sources.has_remotes", return_value=False) 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) Sources.fetch(Path("local"), remote_source)
check_output_mock.assert_not_called() 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("pathlib.Path.is_dir", return_value=True)
mocker.patch("ahriman.core.build_tools.sources.Sources.has_remotes", 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") move_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.move")
local = Path("local") local = Path("local")
@ -70,7 +70,7 @@ def test_fetch_new(remote_source: RemoteSource, mocker: MockerFixture) -> None:
must fetch new package via clone command must fetch new package via clone command
""" """
mocker.patch("pathlib.Path.is_dir", return_value=False) 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") move_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.move")
local = Path("local") 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 must fetch nothing in case if no remote set
""" """
mocker.patch("pathlib.Path.is_dir", return_value=False) 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") move_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.move")
local = Path("local") local = Path("local")
@ -107,7 +107,7 @@ def test_fetch_relative(remote_source: RemoteSource, mocker: MockerFixture) -> N
""" """
must process move correctly on relative directory 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") move_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.move")
Sources.fetch(Path("path"), remote_source) Sources.fetch(Path("path"), remote_source)
@ -118,7 +118,7 @@ def test_has_remotes(mocker: MockerFixture) -> None:
""" """
must ask for remotes 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") local = Path("local")
assert Sources.has_remotes(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 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")) 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("ahriman.models.package.Package.local_files", return_value=[Path("local")])
mocker.patch("pathlib.Path.is_dir", return_value=False) mocker.patch("pathlib.Path.is_dir", return_value=False)
add_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.add") 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") commit_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.commit")
local = Path("local") 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("pathlib.Path.is_dir", return_value=True)
mocker.patch("ahriman.core.build_tools.sources.Sources.add") mocker.patch("ahriman.core.build_tools.sources.Sources.add")
mocker.patch("ahriman.core.build_tools.sources.Sources.commit") 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")) Sources.init(Path("local"))
check_output_mock.assert_not_called() 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") 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) 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") commit_author = ("commit author", "user@host")
local = Path("local") 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.add")
mocker.patch("ahriman.core.build_tools.sources.Sources.commit", return_value=False) 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) Sources.push(Path("local"), package_ahriman.remote)
check_output_mock.assert_not_called() check_output_mock.assert_not_called()
@ -263,7 +263,7 @@ def test_add(sources: Sources, mocker: MockerFixture) -> None:
must add files to git must add files to git
""" """
glob_mock = mocker.patch("pathlib.Path.glob", return_value=[Path("local/1"), Path("local/2")]) 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") local = Path("local")
sources.add(local, "pattern1", "pattern2") 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 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")]) 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") local = Path("local")
sources.add(local, "pattern1", "pattern2", intent_to_add=True) 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 must skip addition of files to index if no fields found
""" """
mocker.patch("pathlib.Path.glob", return_value=[]) 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") sources.add(Path("local"), "pattern1")
check_output_mock.assert_not_called() check_output_mock.assert_not_called()
@ -304,7 +304,7 @@ def test_commit(sources: Sources, mocker: MockerFixture) -> None:
must commit changes must commit changes
""" """
mocker.patch("ahriman.core.build_tools.sources.Sources.has_changes", return_value=True) 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") local = Path("local")
message = "Commit message" 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 must skip commit if there are no changes
""" """
mocker.patch("ahriman.core.build_tools.sources.Sources.has_changes", return_value=False) 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")) assert not sources.commit(Path("local"))
check_output_mock.assert_not_called() 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 must commit changes with commit author
""" """
mocker.patch("ahriman.core.build_tools.sources.Sources.has_changes", return_value=True) 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") local = Path("local")
message = "Commit message" message = "Commit message"
@ -359,7 +359,7 @@ def test_commit_autogenerated_message(sources: Sources, mocker: MockerFixture) -
must commit changes with autogenerated commit message must commit changes with autogenerated commit message
""" """
mocker.patch("ahriman.core.build_tools.sources.Sources.has_changes", return_value=True) 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") local = Path("local")
assert sources.commit(Path("local")) assert sources.commit(Path("local"))
@ -379,7 +379,7 @@ def test_diff(sources: Sources, mocker: MockerFixture) -> None:
""" """
must calculate diff 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") local = Path("local")
assert sources.diff(local) assert sources.diff(local)
@ -392,12 +392,12 @@ def test_has_changes(sources: Sources, mocker: MockerFixture) -> None:
""" """
local = Path("local") 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) assert sources.has_changes(local)
check_output_mock.assert_called_once_with("git", "diff", "--cached", "--name-only", check_output_mock.assert_called_once_with("git", "diff", "--cached", "--name-only",
cwd=local, logger=pytest.helpers.anyvar(int)) 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) assert not sources.has_changes(local)
check_output_mock.assert_called_once_with("git", "diff", "--cached", "--name-only", check_output_mock.assert_called_once_with("git", "diff", "--cached", "--name-only",
cwd=local, logger=pytest.helpers.anyvar(int)) 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 must apply patches if any
""" """
patch = PkgbuildPatch(None, "patch") 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") local = Path("local")
sources.patch_apply(local, patch) sources.patch_apply(local, patch)

View File

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

View File

@ -8,6 +8,6 @@ def test_sync(rsync: Rsync, mocker: MockerFixture) -> None:
""" """
must run sync command 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"), []) rsync.sync(Path("path"), [])
check_output_mock.assert_called_once_with(*rsync.command, "path", rsync.remote, logger=rsync.logger) 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() 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) package_gcc10 = Package.from_build(Path("local"), "x86_64", None)
assert package_gcc10.depends_build == { 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 must construct package from srcinfo
""" """
srcinfo = (resource_path_root / "models" / "package_ahriman_srcinfo").read_text() 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") package = Package.from_build(Path("path"), "x86_64", "packager")
assert package_ahriman.packages.keys() == package.packages.keys() 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 must construct package from srcinfo with dependencies per-package overrides
""" """
srcinfo = (resource_path_root / "models" / "package_gcc10_srcinfo").read_text() 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) package = Package.from_build(Path("path"), "x86_64", None)
assert package.packages == { 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 must construct package with architecture specific depends list
""" """
srcinfo = (resource_path_root / "models" / "package_jellyfin-ffmpeg5-bin_srcinfo").read_text() 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) package = Package.from_build(Path("path"), "x86_64", None)
assert package.packages == { 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 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"])) mocker.patch("ahriman.models.package.parse_srcinfo", return_value=({"packages": {}}, ["an error"]))
with pytest.raises(PackageInfoError): 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, _ = parse_srcinfo(srcinfo)
parsed_srcinfo["source"] = ["local-file.tar.gz"] parsed_srcinfo["source"] = ["local-file.tar.gz"]
mocker.patch("ahriman.models.package.parse_srcinfo", return_value=(parsed_srcinfo, [])) 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"]) mocker.patch("ahriman.models.package.Package.supported_architectures", return_value=["any"])
assert list(Package.local_files(Path("path"))) == [Path("local-file.tar.gz")] 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 must extract empty local files list when there is no local files
""" """
srcinfo = (resource_path_root / "models" / "package_yay_srcinfo").read_text() 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"]) mocker.patch("ahriman.models.package.Package.supported_architectures", return_value=["any"])
assert list(Package.local_files(Path("path"))) == [] 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 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"])) mocker.patch("ahriman.models.package.parse_srcinfo", return_value=({"packages": {}}, ["an error"]))
with pytest.raises(PackageInfoError): 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, _ = parse_srcinfo(srcinfo)
parsed_srcinfo["source"] = ["file:///local-file.tar.gz"] parsed_srcinfo["source"] = ["file:///local-file.tar.gz"]
mocker.patch("ahriman.models.package.parse_srcinfo", return_value=(parsed_srcinfo, [])) 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"]) mocker.patch("ahriman.models.package.Package.supported_architectures", return_value=["any"])
assert list(Package.local_files(Path("path"))) == [] 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, _ = parse_srcinfo(srcinfo)
parsed_srcinfo["install"] = "install" parsed_srcinfo["install"] = "install"
mocker.patch("ahriman.models.package.parse_srcinfo", return_value=(parsed_srcinfo, [])) 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"]) mocker.patch("ahriman.models.package.Package.supported_architectures", return_value=["any"])
assert list(Package.local_files(Path("path"))) == [Path("install")] 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 must generate list of available architectures
""" """
srcinfo = (resource_path_root / "models" / "package_yay_srcinfo").read_text() 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")) == \ assert Package.supported_architectures(Path("path")) == \
{"i686", "pentium4", "x86_64", "arm", "armv7h", "armv6h", "aarch64"} {"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 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"])) mocker.patch("ahriman.models.package.parse_srcinfo", return_value=({"packages": {}}, ["an error"]))
with pytest.raises(PackageInfoError): 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 must return valid actual_version for VCS package
""" """
srcinfo = (resource_path_root / "models" / "package_tpacpi-bat-git_srcinfo").read_text() 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") mocker.patch("ahriman.core.build_tools.sources.Sources.load")
assert package_tpacpi_bat_git.actual_version(repository_paths) == "3.1.r13.g4959b52-1" 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 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") mocker.patch("ahriman.core.build_tools.sources.Sources.load")
assert package_tpacpi_bat_git.actual_version(repository_paths) == package_tpacpi_bat_git.version 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("pathlib.Path.read_text", return_value="")
mocker.patch("ahriman.models.package.parse_srcinfo", return_value=({"packages": {}}, ["an error"])) 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") mocker.patch("ahriman.core.build_tools.sources.Sources.load")
assert package_tpacpi_bat_git.actual_version(repository_paths) == package_tpacpi_bat_git.version assert package_tpacpi_bat_git.actual_version(repository_paths) == package_tpacpi_bat_git.version