mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-06-28 14:51:43 +00:00
docs: improve application help messages
This commit is contained in:
@ -5,6 +5,7 @@ from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.application.ahriman import _parser
|
||||
from ahriman.application.application import Application
|
||||
from ahriman.application.help_formatter import _HelpFormatter
|
||||
from ahriman.application.lock import Lock
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.database import SQLite
|
||||
@ -44,6 +45,17 @@ def args() -> argparse.Namespace:
|
||||
repository=None, repository_id=None, wait_timeout=-1)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def formatter() -> _HelpFormatter:
|
||||
"""
|
||||
fixture for help message formatter
|
||||
|
||||
Returns:
|
||||
_HelpFormatter: help message formatter test instance
|
||||
"""
|
||||
return _HelpFormatter("ahriman")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def lock(args: argparse.Namespace, configuration: Configuration) -> Lock:
|
||||
"""
|
||||
|
@ -73,8 +73,8 @@ def test_execute(args: argparse.Namespace, mocker: MockerFixture) -> None:
|
||||
must run execution in multiple processes
|
||||
"""
|
||||
ids = [
|
||||
RepositoryId("i686", "aur-clone"),
|
||||
RepositoryId("x86_64", "aur-clone"),
|
||||
RepositoryId("i686", "aur"),
|
||||
RepositoryId("x86_64", "aur"),
|
||||
]
|
||||
mocker.patch("ahriman.application.handlers.Handler.repositories_extract", return_value=ids)
|
||||
starmap_mock = mocker.patch("multiprocessing.pool.Pool.starmap")
|
||||
@ -89,8 +89,8 @@ def test_execute_multiple_not_supported(args: argparse.Namespace, mocker: Mocker
|
||||
"""
|
||||
args.command = "web"
|
||||
mocker.patch("ahriman.application.handlers.Handler.repositories_extract", return_value=[
|
||||
RepositoryId("i686", "aur-clone"),
|
||||
RepositoryId("x86_64", "aur-clone"),
|
||||
RepositoryId("i686", "aur"),
|
||||
RepositoryId("x86_64", "aur"),
|
||||
])
|
||||
mocker.patch.object(Handler, "ALLOW_MULTI_ARCHITECTURE_RUN", False)
|
||||
|
||||
@ -103,7 +103,7 @@ def test_execute_single(args: argparse.Namespace, mocker: MockerFixture) -> None
|
||||
must run execution in current process if only one architecture supplied
|
||||
"""
|
||||
mocker.patch("ahriman.application.handlers.Handler.repositories_extract", return_value=[
|
||||
RepositoryId("x86_64", "aur-clone"),
|
||||
RepositoryId("x86_64", "aur"),
|
||||
])
|
||||
starmap_mock = mocker.patch("multiprocessing.pool.Pool.starmap")
|
||||
|
||||
@ -179,7 +179,7 @@ def test_repositories_extract_repository_legacy(args: argparse.Namespace, config
|
||||
known_repositories_mock = mocker.patch("ahriman.models.repository_paths.RepositoryPaths.known_repositories",
|
||||
return_value=set())
|
||||
|
||||
assert Handler.repositories_extract(args) == [RepositoryId("arch", "aur-clone")]
|
||||
assert Handler.repositories_extract(args) == [RepositoryId("arch", "aur")]
|
||||
known_architectures_mock.assert_not_called()
|
||||
known_repositories_mock.assert_called_once_with(configuration.repository_paths.root)
|
||||
|
||||
@ -255,6 +255,6 @@ def test_repositories_extract_systemd_legacy(args: argparse.Namespace, configura
|
||||
known_repositories_mock = mocker.patch("ahriman.models.repository_paths.RepositoryPaths.known_repositories",
|
||||
return_value=set())
|
||||
|
||||
assert Handler.repositories_extract(args) == [RepositoryId("i686", "aur-clone")]
|
||||
assert Handler.repositories_extract(args) == [RepositoryId("i686", "aur")]
|
||||
known_architectures_mock.assert_not_called()
|
||||
known_repositories_mock.assert_called_once_with(configuration.repository_paths.root)
|
||||
|
@ -33,8 +33,8 @@ def _default_args(args: argparse.Namespace) -> argparse.Namespace:
|
||||
args.makeflags_jobs = True
|
||||
args.mirror = "mirror"
|
||||
args.multilib = True
|
||||
args.packager = "John Doe <john@doe.com>"
|
||||
args.repository = "aur-clone"
|
||||
args.packager = "ahriman bot <ahriman@example.com>"
|
||||
args.repository = "aur"
|
||||
args.server = None
|
||||
args.sign_key = "key"
|
||||
args.sign_target = [SignSettings.Packages]
|
||||
|
@ -1318,7 +1318,8 @@ def test_subparsers_service_setup(parser: argparse.ArgumentParser) -> None:
|
||||
"""
|
||||
service-setup command must imply lock, quiet, report and unsafe
|
||||
"""
|
||||
args = parser.parse_args(["-a", "x86_64", "-r", "repo", "service-setup", "--packager", "John Doe <john@doe.com>"])
|
||||
args = parser.parse_args(["-a", "x86_64", "-r", "repo", "service-setup",
|
||||
"--packager", "ahriman bot <ahriman@example.com>"])
|
||||
assert args.architecture == "x86_64"
|
||||
assert args.lock is None
|
||||
assert args.quiet
|
||||
@ -1331,10 +1332,11 @@ def test_subparsers_service_setup_option_from_configuration(parser: argparse.Arg
|
||||
"""
|
||||
service-setup command must convert from-configuration option to path instance
|
||||
"""
|
||||
args = parser.parse_args(["-a", "x86_64", "-r", "repo", "service-setup", "--packager", "John Doe <john@doe.com>"])
|
||||
args = parser.parse_args(["-a", "x86_64", "-r", "repo", "service-setup",
|
||||
"--packager", "ahriman bot <ahriman@example.com>"])
|
||||
assert isinstance(args.from_configuration, Path)
|
||||
args = parser.parse_args(["-a", "x86_64", "-r", "repo", "service-setup", "--packager", "John Doe <john@doe.com>",
|
||||
"--from-configuration", "path"])
|
||||
args = parser.parse_args(["-a", "x86_64", "-r", "repo", "service-setup",
|
||||
"--packager", "ahriman bot <ahriman@example.com>", "--from-configuration", "path"])
|
||||
assert isinstance(args.from_configuration, Path)
|
||||
|
||||
|
||||
@ -1342,8 +1344,8 @@ def test_subparsers_service_setup_option_sign_target(parser: argparse.ArgumentPa
|
||||
"""
|
||||
service-setup command must convert sign-target option to SignSettings instance
|
||||
"""
|
||||
args = parser.parse_args(["-a", "x86_64", "-r", "repo", "service-setup", "--packager", "John Doe <john@doe.com>",
|
||||
"--sign-target", "packages"])
|
||||
args = parser.parse_args(["-a", "x86_64", "-r", "repo", "service-setup",
|
||||
"--packager", "ahriman bot <ahriman@example.com>", "--sign-target", "packages"])
|
||||
assert args.sign_target
|
||||
assert all(isinstance(target, SignSettings) for target in args.sign_target)
|
||||
|
||||
@ -1352,7 +1354,8 @@ def test_subparsers_service_setup_option_sign_target_empty(parser: argparse.Argu
|
||||
"""
|
||||
service-setup command must accept empty sign-target list as None
|
||||
"""
|
||||
args = parser.parse_args(["-a", "x86_64", "-r", "repo", "service-setup", "--packager", "John Doe <john@doe.com>"])
|
||||
args = parser.parse_args(["-a", "x86_64", "-r", "repo", "service-setup",
|
||||
"--packager", "ahriman bot <ahriman@example.com>"])
|
||||
assert args.sign_target is None
|
||||
|
||||
|
||||
@ -1360,8 +1363,9 @@ def test_subparsers_service_setup_option_sign_target_multiple(parser: argparse.A
|
||||
"""
|
||||
service-setup command must accept multiple sign-target
|
||||
"""
|
||||
args = parser.parse_args(["-a", "x86_64", "-r", "repo", "service-setup", "--packager", "John Doe <john@doe.com>",
|
||||
"--sign-target", "packages", "--sign-target", "repository"])
|
||||
args = parser.parse_args(["-a", "x86_64", "-r", "repo", "service-setup",
|
||||
"--packager", "ahriman bot <ahriman@example.com>", "--sign-target", "packages",
|
||||
"--sign-target", "repository"])
|
||||
assert args.sign_target == [SignSettings.Packages, SignSettings.Repository]
|
||||
|
||||
|
||||
|
19
tests/ahriman/application/test_help_formatter.py
Normal file
19
tests/ahriman/application/test_help_formatter.py
Normal file
@ -0,0 +1,19 @@
|
||||
from ahriman.application.help_formatter import _HelpFormatter
|
||||
|
||||
|
||||
def test_whitespace_matcher(formatter: _HelpFormatter) -> None:
|
||||
"""
|
||||
must only match spaces or tabs
|
||||
"""
|
||||
assert formatter._whitespace_matcher.match(" ")
|
||||
assert formatter._whitespace_matcher.match("\t")
|
||||
|
||||
assert formatter._whitespace_matcher.match("\n") is None
|
||||
assert formatter._whitespace_matcher.match("\r") is None
|
||||
|
||||
|
||||
def test_fill_text(formatter: _HelpFormatter) -> None:
|
||||
"""
|
||||
must wrap text keeping new lines
|
||||
"""
|
||||
assert formatter._fill_text("first\n 1 longwordhere", 10, "") == "first\n 1 longwor\ndhere"
|
@ -26,10 +26,10 @@ def test_path(args: argparse.Namespace, configuration: Configuration) -> None:
|
||||
assert Lock(args, repository_id, configuration).path is None
|
||||
|
||||
args.lock = Path("/run/ahriman.pid")
|
||||
assert Lock(args, repository_id, configuration).path == Path("/run/ahriman_x86_64-aur-clone.pid")
|
||||
assert Lock(args, repository_id, configuration).path == Path("/run/ahriman_x86_64-aur.pid")
|
||||
|
||||
args.lock = Path("ahriman.pid")
|
||||
assert Lock(args, repository_id, configuration).path == Path("/run/ahriman/ahriman_x86_64-aur-clone.pid")
|
||||
assert Lock(args, repository_id, configuration).path == Path("/run/ahriman/ahriman_x86_64-aur.pid")
|
||||
|
||||
assert Lock(args, RepositoryId("", ""), configuration).path == Path("/run/ahriman/ahriman.pid")
|
||||
|
||||
|
@ -555,7 +555,7 @@ def repository_id() -> RepositoryId:
|
||||
Returns:
|
||||
RepositoryId: repository identifier test instance
|
||||
"""
|
||||
return RepositoryId("x86_64", "aur-clone")
|
||||
return RepositoryId("x86_64", "aur")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -22,7 +22,7 @@ def test_repository_name(configuration: Configuration) -> None:
|
||||
"""
|
||||
must return valid repository name
|
||||
"""
|
||||
assert configuration.repository_name == "aur-clone"
|
||||
assert configuration.repository_name == "aur"
|
||||
|
||||
|
||||
def test_repository_paths(configuration: Configuration, repository_paths: RepositoryPaths) -> None:
|
||||
@ -68,8 +68,8 @@ def test_section_name(configuration: Configuration) -> None:
|
||||
assert configuration.section_name("build") == "build"
|
||||
assert configuration.section_name("build", None) == "build"
|
||||
assert configuration.section_name("build", "x86_64") == "build:x86_64"
|
||||
assert configuration.section_name("build", "aur-clone", "x86_64") == "build:aur-clone:x86_64"
|
||||
assert configuration.section_name("build", "aur-clone", None) == "build:aur-clone"
|
||||
assert configuration.section_name("build", "aur", "x86_64") == "build:aur:x86_64"
|
||||
assert configuration.section_name("build", "aur", None) == "build:aur"
|
||||
assert configuration.section_name("build", None, "x86_64") == "build:x86_64"
|
||||
|
||||
|
||||
@ -379,8 +379,8 @@ def test_override_sections(configuration: Configuration, repository_id: Reposito
|
||||
"""
|
||||
assert configuration.override_sections("build", repository_id) == [
|
||||
"build:x86_64",
|
||||
"build:aur-clone",
|
||||
"build:aur-clone:x86_64",
|
||||
"build:aur",
|
||||
"build:aur:x86_64",
|
||||
]
|
||||
|
||||
|
||||
|
@ -71,7 +71,7 @@ def test_pkgdesc(database: SQLite, gpg: GPG, configuration: Configuration) -> No
|
||||
"""
|
||||
_, repository_id = configuration.check_loaded()
|
||||
|
||||
assert KeyringGenerator(database, gpg, repository_id, configuration, "keyring").pkgdesc == "aur-clone PGP keyring"
|
||||
assert KeyringGenerator(database, gpg, repository_id, configuration, "keyring").pkgdesc == "aur PGP keyring"
|
||||
|
||||
configuration.set_option("keyring", "description", "description")
|
||||
assert KeyringGenerator(database, gpg, repository_id, configuration, "keyring").pkgdesc == "description"
|
||||
@ -83,7 +83,7 @@ def test_pkgname(database: SQLite, gpg: GPG, configuration: Configuration) -> No
|
||||
"""
|
||||
_, repository_id = configuration.check_loaded()
|
||||
|
||||
assert KeyringGenerator(database, gpg, repository_id, configuration, "keyring").pkgname == "aur-clone-keyring"
|
||||
assert KeyringGenerator(database, gpg, repository_id, configuration, "keyring").pkgname == "aur-keyring"
|
||||
|
||||
configuration.set_option("keyring", "package", "keyring")
|
||||
assert KeyringGenerator(database, gpg, repository_id, configuration, "keyring").pkgname == "keyring"
|
||||
@ -169,7 +169,7 @@ def test_install(keyring_generator: KeyringGenerator) -> None:
|
||||
"""
|
||||
assert keyring_generator.install() == """post_upgrade() {
|
||||
if usr/bin/pacman-key -l >/dev/null 2>&1; then
|
||||
usr/bin/pacman-key --populate aur-clone
|
||||
usr/bin/pacman-key --populate aur
|
||||
usr/bin/pacman-key --updatedb
|
||||
fi
|
||||
}
|
||||
@ -186,9 +186,9 @@ def test_package(keyring_generator: KeyringGenerator) -> None:
|
||||
must generate package function correctly
|
||||
"""
|
||||
assert keyring_generator.package() == """{
|
||||
install -Dm644 "$srcdir/aur-clone.gpg" "$pkgdir/usr/share/pacman/keyrings/aur-clone.gpg"
|
||||
install -Dm644 "$srcdir/aur-clone-revoked" "$pkgdir/usr/share/pacman/keyrings/aur-clone-revoked"
|
||||
install -Dm644 "$srcdir/aur-clone-trusted" "$pkgdir/usr/share/pacman/keyrings/aur-clone-trusted"
|
||||
install -Dm644 "$srcdir/aur.gpg" "$pkgdir/usr/share/pacman/keyrings/aur.gpg"
|
||||
install -Dm644 "$srcdir/aur-revoked" "$pkgdir/usr/share/pacman/keyrings/aur-revoked"
|
||||
install -Dm644 "$srcdir/aur-trusted" "$pkgdir/usr/share/pacman/keyrings/aur-trusted"
|
||||
}"""
|
||||
|
||||
|
||||
@ -196,6 +196,6 @@ def test_sources(keyring_generator: KeyringGenerator) -> None:
|
||||
"""
|
||||
must return valid sources files list
|
||||
"""
|
||||
assert keyring_generator.sources().get("aur-clone.gpg")
|
||||
assert keyring_generator.sources().get("aur-clone-revoked")
|
||||
assert keyring_generator.sources().get("aur-clone-trusted")
|
||||
assert keyring_generator.sources().get("aur.gpg")
|
||||
assert keyring_generator.sources().get("aur-revoked")
|
||||
assert keyring_generator.sources().get("aur-trusted")
|
||||
|
@ -12,7 +12,7 @@ def test_init_path(configuration: Configuration) -> None:
|
||||
_, repository_id = configuration.check_loaded()
|
||||
|
||||
assert MirrorlistGenerator(repository_id, configuration, "mirrorlist").path == \
|
||||
Path("etc") / "pacman.d" / "aur-clone-mirrorlist"
|
||||
Path("etc") / "pacman.d" / "aur-mirrorlist"
|
||||
|
||||
configuration.set_option("mirrorlist", "path", "/etc")
|
||||
assert MirrorlistGenerator(repository_id, configuration, "mirrorlist").path == Path("etc")
|
||||
@ -37,7 +37,7 @@ def test_pkgdesc(configuration: Configuration) -> None:
|
||||
_, repository_id = configuration.check_loaded()
|
||||
|
||||
assert MirrorlistGenerator(repository_id, configuration, "mirrorlist").pkgdesc == \
|
||||
"aur-clone mirror list for use by pacman"
|
||||
"aur mirror list for use by pacman"
|
||||
|
||||
configuration.set_option("mirrorlist", "description", "description")
|
||||
assert MirrorlistGenerator(repository_id, configuration, "mirrorlist").pkgdesc == "description"
|
||||
@ -49,7 +49,7 @@ def test_pkgname(configuration: Configuration) -> None:
|
||||
"""
|
||||
_, repository_id = configuration.check_loaded()
|
||||
|
||||
assert MirrorlistGenerator(repository_id, configuration, "mirrorlist").pkgname == "aur-clone-mirrorlist"
|
||||
assert MirrorlistGenerator(repository_id, configuration, "mirrorlist").pkgname == "aur-mirrorlist"
|
||||
|
||||
configuration.set_option("mirrorlist", "package", "mirrorlist")
|
||||
assert MirrorlistGenerator(repository_id, configuration, "mirrorlist").pkgname == "mirrorlist"
|
||||
@ -81,7 +81,7 @@ def test_package(mirrorlist_generator: MirrorlistGenerator) -> None:
|
||||
must generate package function correctly
|
||||
"""
|
||||
assert mirrorlist_generator.package() == """{
|
||||
install -Dm644 "$srcdir/mirrorlist" "$pkgdir/etc/pacman.d/aur-clone-mirrorlist"
|
||||
install -Dm644 "$srcdir/mirrorlist" "$pkgdir/etc/pacman.d/aur-mirrorlist"
|
||||
}"""
|
||||
|
||||
|
||||
|
@ -18,7 +18,7 @@ def test_object_path(configuration: Configuration, mocker: MockerFixture) -> Non
|
||||
_, repository_id = configuration.check_loaded()
|
||||
|
||||
# new-style tree
|
||||
assert S3(repository_id, configuration, "customs3").object_path == Path("aur-clone/x86_64")
|
||||
assert S3(repository_id, configuration, "customs3").object_path == Path("aur/x86_64")
|
||||
|
||||
# legacy tree
|
||||
mocker.patch.object(RepositoryPaths, "_suffix", Path("x86_64"))
|
||||
@ -58,12 +58,12 @@ def test_files_remove(s3_remote_objects: list[Any]) -> None:
|
||||
must remove remote objects
|
||||
"""
|
||||
local_files = {
|
||||
Path(item.key): item.e_tag for item in s3_remote_objects if item.key != "aur-clone/x86_64/a"
|
||||
Path(item.key): item.e_tag for item in s3_remote_objects if item.key != "aur/x86_64/a"
|
||||
}
|
||||
remote_objects = {Path(item.key): item for item in s3_remote_objects}
|
||||
|
||||
S3.files_remove(local_files, remote_objects)
|
||||
remote_objects[Path("aur-clone/x86_64/a")].delete.assert_called_once_with()
|
||||
remote_objects[Path("aur/x86_64/a")].delete.assert_called_once_with()
|
||||
|
||||
|
||||
def test_files_upload(s3: S3, s3_remote_objects: list[Any], mocker: MockerFixture) -> None:
|
||||
|
@ -67,11 +67,13 @@ def internal_status(counters: Counters) -> InternalStatus:
|
||||
Returns:
|
||||
InternalStatus: internal status test instance
|
||||
"""
|
||||
return InternalStatus(status=BuildStatus(),
|
||||
architecture="x86_64",
|
||||
packages=counters,
|
||||
version=__version__,
|
||||
repository="aur-clone")
|
||||
return InternalStatus(
|
||||
status=BuildStatus(),
|
||||
architecture="x86_64",
|
||||
packages=counters,
|
||||
version=__version__,
|
||||
repository="aur",
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -30,7 +30,7 @@ triggers = ahriman.core.report.ReportTrigger ahriman.core.upload.UploadTrigger
|
||||
triggers_known = ahriman.core.distributed.WorkerLoaderTrigger ahriman.core.distributed.WorkerRegisterTrigger ahriman.core.distributed.WorkerTrigger ahriman.core.distributed.WorkerUnregisterTrigger ahriman.core.gitremote.RemotePullTrigger ahriman.core.gitremote.RemotePushTrigger ahriman.core.report.ReportTrigger ahriman.core.upload.UploadTrigger ahriman.core.support.KeyringTrigger ahriman.core.support.MirrorlistTrigger
|
||||
|
||||
[repository]
|
||||
name = aur-clone
|
||||
name = aur
|
||||
root = ../../../
|
||||
|
||||
[sign]
|
||||
|
Reference in New Issue
Block a user