add repo-structure subcommand

This commit also changes Tree class, replacing load method by resolve
This commit is contained in:
2022-12-27 02:06:10 +02:00
parent aa1a59d0a3
commit 7de94a8daa
17 changed files with 364 additions and 37 deletions

View File

@ -163,7 +163,7 @@ def test_update(application_repository: ApplicationRepository, package_ahriman:
paths = [package.filepath for package in package_ahriman.packages.values()]
tree = Tree([Leaf(package_ahriman, set())])
mocker.patch("ahriman.core.tree.Tree.load", return_value=tree)
mocker.patch("ahriman.core.tree.Tree.resolve", return_value=tree.levels())
mocker.patch("ahriman.core.repository.repository.Repository.packages_built", return_value=paths)
build_mock = mocker.patch("ahriman.core.repository.executor.Executor.process_build", return_value=result)
update_mock = mocker.patch("ahriman.core.repository.executor.Executor.process_update", return_value=result)
@ -183,7 +183,7 @@ def test_update_empty(application_repository: ApplicationRepository, package_ahr
"""
tree = Tree([Leaf(package_ahriman, set())])
mocker.patch("ahriman.core.tree.Tree.load", return_value=tree)
mocker.patch("ahriman.core.tree.Tree.resolve", return_value=tree.levels())
mocker.patch("ahriman.core.repository.repository.Repository.packages_built", return_value=[])
mocker.patch("ahriman.core.repository.executor.Executor.process_build")
update_mock = mocker.patch("ahriman.core.repository.executor.Executor.process_update")
@ -197,6 +197,9 @@ def test_updates_all(application_repository: ApplicationRepository, package_ahri
"""
must get updates for all
"""
tree = Tree([Leaf(package_ahriman, set())])
mocker.patch("ahriman.core.tree.Tree.resolve", return_value=tree.levels())
mocker.patch("ahriman.core.repository.repository.Repository.packages", return_value=[])
updates_aur_mock = mocker.patch("ahriman.core.repository.update_handler.UpdateHandler.updates_aur",
return_value=[package_ahriman])

View File

@ -0,0 +1,31 @@
import argparse
import pytest
from pytest_mock import MockerFixture
from ahriman.application.handlers import Structure
from ahriman.core.configuration import Configuration
from ahriman.core.repository import Repository
from ahriman.models.package import Package
def test_run(args: argparse.Namespace, configuration: Configuration, repository: Repository,
package_ahriman: Package, mocker: MockerFixture) -> None:
"""
must run command
"""
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
mocker.patch("ahriman.core.repository.Repository.packages", return_value=[package_ahriman])
application_mock = mocker.patch("ahriman.core.tree.Tree.resolve", return_value=[[package_ahriman]])
print_mock = mocker.patch("ahriman.core.formatters.Printer.print")
Structure.run(args, "x86_64", configuration, report=False, unsafe=False)
application_mock.assert_called_once_with([package_ahriman], repository.paths, pytest.helpers.anyvar(int))
print_mock.assert_called_once_with(verbose=True, separator=" ")
def test_disallow_auto_architecture_run() -> None:
"""
must not allow multi architecture run
"""
assert not Structure.ALLOW_AUTO_ARCHITECTURE_RUN

View File

@ -550,9 +550,29 @@ def test_subparsers_repo_sync_architecture(parser: argparse.ArgumentParser) -> N
"""
repo-sync command must correctly parse architecture list
"""
args = parser.parse_args(["repo-report"])
args = parser.parse_args(["repo-sync"])
assert args.architecture is None
args = parser.parse_args(["-a", "x86_64", "repo-report"])
args = parser.parse_args(["-a", "x86_64", "repo-sync"])
assert args.architecture == ["x86_64"]
def test_subparsers_repo_tree(parser: argparse.ArgumentParser) -> None:
"""
repo-tree command must imply lock, report and quiet
"""
args = parser.parse_args(["repo-tree"])
assert args.lock is None
assert not args.report
assert args.quiet
def test_subparsers_repo_tree_architecture(parser: argparse.ArgumentParser) -> None:
"""
repo-tree command must correctly parse architecture list
"""
args = parser.parse_args(["repo-tree"])
assert args.architecture is None
args = parser.parse_args(["-a", "x86_64", "repo-tree"])
assert args.architecture == ["x86_64"]