mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-08-31 22:09:56 +00:00
calculate dependencies based on package information (#89)
This commit is contained in:
@ -2,7 +2,7 @@ import pytest
|
||||
|
||||
from pathlib import Path
|
||||
from pytest_mock import MockerFixture
|
||||
from unittest.mock import MagicMock
|
||||
from unittest.mock import MagicMock, call as MockCall
|
||||
|
||||
from ahriman.application.application.application_packages import ApplicationPackages
|
||||
from ahriman.models.package import Package
|
||||
@ -29,18 +29,12 @@ def test_add_aur(application_packages: ApplicationPackages, package_ahriman: Pac
|
||||
must add package from AUR
|
||||
"""
|
||||
mocker.patch("ahriman.models.package.Package.from_aur", return_value=package_ahriman)
|
||||
load_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.load")
|
||||
dependencies_mock = mocker.patch(
|
||||
"ahriman.application.application.application_packages.ApplicationPackages._process_dependencies")
|
||||
build_queue_mock = mocker.patch("ahriman.core.database.SQLite.build_queue_insert")
|
||||
update_remote_mock = mocker.patch("ahriman.core.database.SQLite.remote_update")
|
||||
|
||||
application_packages._add_aur(package_ahriman.base, set(), False)
|
||||
load_mock.assert_called_once_with(
|
||||
pytest.helpers.anyvar(int),
|
||||
package_ahriman,
|
||||
pytest.helpers.anyvar(int),
|
||||
application_packages.repository.paths)
|
||||
dependencies_mock.assert_called_once_with(pytest.helpers.anyvar(int), set(), False)
|
||||
build_queue_mock.assert_called_once_with(package_ahriman)
|
||||
update_remote_mock.assert_called_once_with(package_ahriman)
|
||||
@ -121,43 +115,37 @@ def test_known_packages(application_packages: ApplicationPackages) -> None:
|
||||
application_packages._known_packages()
|
||||
|
||||
|
||||
def test_process_dependencies(application_packages: ApplicationPackages, mocker: MockerFixture) -> None:
|
||||
def test_process_dependencies(application_packages: ApplicationPackages, package_ahriman: Package,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must process dependencies addition
|
||||
"""
|
||||
missing = {"python"}
|
||||
path = Path("local")
|
||||
dependencies_mock = mocker.patch("ahriman.models.package.Package.dependencies", return_value=missing)
|
||||
add_mock = mocker.patch("ahriman.application.application.application_packages.ApplicationPackages.add")
|
||||
|
||||
application_packages._process_dependencies(path, set(), False)
|
||||
dependencies_mock.assert_called_once_with(path)
|
||||
add_mock.assert_called_once_with(missing, PackageSource.AUR, False)
|
||||
application_packages._process_dependencies(package_ahriman, set(), False)
|
||||
add_mock.assert_called_once_with(package_ahriman.depends_build, PackageSource.AUR, False)
|
||||
|
||||
|
||||
def test_process_dependencies_missing(application_packages: ApplicationPackages, mocker: MockerFixture) -> None:
|
||||
def test_process_dependencies_missing(application_packages: ApplicationPackages, package_ahriman: Package,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must process dependencies addition only for missing packages
|
||||
"""
|
||||
path = Path("local")
|
||||
dependencies_mock = mocker.patch("ahriman.models.package.Package.dependencies",
|
||||
return_value={"python", "python-aiohttp"})
|
||||
missing = {"devtools"}
|
||||
add_mock = mocker.patch("ahriman.application.application.application_packages.ApplicationPackages.add")
|
||||
|
||||
application_packages._process_dependencies(path, {"python"}, False)
|
||||
dependencies_mock.assert_called_once_with(path)
|
||||
add_mock.assert_called_once_with({"python-aiohttp"}, PackageSource.AUR, False)
|
||||
application_packages._process_dependencies(
|
||||
package_ahriman, package_ahriman.depends_build.difference(missing), False)
|
||||
add_mock.assert_called_once_with(missing, PackageSource.AUR, False)
|
||||
|
||||
|
||||
def test_process_dependencies_skip(application_packages: ApplicationPackages, mocker: MockerFixture) -> None:
|
||||
def test_process_dependencies_skip(application_packages: ApplicationPackages, package_ahriman: Package,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must skip dependencies processing
|
||||
"""
|
||||
dependencies_mock = mocker.patch("ahriman.models.package.Package.dependencies")
|
||||
add_mock = mocker.patch("ahriman.application.application.application_packages.ApplicationPackages.add")
|
||||
|
||||
application_packages._process_dependencies(Path("local"), set(), True)
|
||||
dependencies_mock.assert_not_called()
|
||||
application_packages._process_dependencies(package_ahriman, set(), True)
|
||||
add_mock.assert_not_called()
|
||||
|
||||
|
||||
|
@ -161,7 +161,7 @@ def test_update(application_repository: ApplicationRepository, package_ahriman:
|
||||
must process package updates
|
||||
"""
|
||||
paths = [package.filepath for package in package_ahriman.packages.values()]
|
||||
tree = Tree([Leaf(package_ahriman, set())])
|
||||
tree = Tree([Leaf(package_ahriman)])
|
||||
|
||||
mocker.patch("ahriman.core.tree.Tree.resolve", return_value=tree.levels())
|
||||
mocker.patch("ahriman.core.repository.repository.Repository.packages_built", return_value=paths)
|
||||
@ -181,7 +181,7 @@ def test_update_empty(application_repository: ApplicationRepository, package_ahr
|
||||
"""
|
||||
must skip updating repository if no packages supplied
|
||||
"""
|
||||
tree = Tree([Leaf(package_ahriman, set())])
|
||||
tree = Tree([Leaf(package_ahriman)])
|
||||
|
||||
mocker.patch("ahriman.core.tree.Tree.resolve", return_value=tree.levels())
|
||||
mocker.patch("ahriman.core.repository.repository.Repository.packages_built", return_value=[])
|
||||
@ -197,7 +197,7 @@ def test_updates_all(application_repository: ApplicationRepository, package_ahri
|
||||
"""
|
||||
must get updates for all
|
||||
"""
|
||||
tree = Tree([Leaf(package_ahriman, set())])
|
||||
tree = Tree([Leaf(package_ahriman)])
|
||||
|
||||
mocker.patch("ahriman.core.tree.Tree.resolve", return_value=tree.levels())
|
||||
mocker.patch("ahriman.core.repository.repository.Repository.packages", return_value=[])
|
||||
|
@ -56,4 +56,4 @@ def test_run_dry_run(args: argparse.Namespace, configuration: Configuration, rep
|
||||
RemoveUnknown.run(args, "x86_64", configuration, report=False, unsafe=False)
|
||||
application_mock.assert_called_once_with()
|
||||
remove_mock.assert_not_called()
|
||||
print_mock.assert_called_once_with(False)
|
||||
print_mock.assert_called_once_with(verbose=False)
|
||||
|
@ -46,7 +46,7 @@ def test_run(args: argparse.Namespace, configuration: Configuration, repository:
|
||||
aur_search_mock.assert_called_once_with("ahriman", pacman=pytest.helpers.anyvar(int))
|
||||
official_search_mock.assert_called_once_with("ahriman", pacman=pytest.helpers.anyvar(int))
|
||||
check_mock.assert_called_once_with(False, False)
|
||||
print_mock.assert_has_calls([MockCall(False), MockCall(False)])
|
||||
print_mock.assert_has_calls([MockCall(verbose=False), MockCall(verbose=False)])
|
||||
|
||||
|
||||
def test_run_empty_exception(args: argparse.Namespace, configuration: Configuration, repository: Repository,
|
||||
|
@ -47,7 +47,7 @@ def test_run(args: argparse.Namespace, configuration: Configuration, repository:
|
||||
application_mock.assert_called_once_with()
|
||||
packages_mock.assert_called_once_with(None)
|
||||
check_mock.assert_called_once_with(False, False)
|
||||
print_mock.assert_has_calls([MockCall(False) for _ in range(3)])
|
||||
print_mock.assert_has_calls([MockCall(verbose=False) for _ in range(3)])
|
||||
|
||||
|
||||
def test_run_empty_exception(args: argparse.Namespace, configuration: Configuration, repository: Repository,
|
||||
@ -79,7 +79,7 @@ def test_run_verbose(args: argparse.Namespace, configuration: Configuration, rep
|
||||
print_mock = mocker.patch("ahriman.core.formatters.Printer.print")
|
||||
|
||||
Status.run(args, "x86_64", configuration, report=False, unsafe=False)
|
||||
print_mock.assert_has_calls([MockCall(True) for _ in range(2)])
|
||||
print_mock.assert_has_calls([MockCall(verbose=True) for _ in range(2)])
|
||||
|
||||
|
||||
def test_run_with_package_filter(args: argparse.Namespace, configuration: Configuration, repository: Repository,
|
||||
@ -111,7 +111,7 @@ def test_run_by_status(args: argparse.Namespace, configuration: Configuration, r
|
||||
print_mock = mocker.patch("ahriman.core.formatters.Printer.print")
|
||||
|
||||
Status.run(args, "x86_64", configuration, report=False, unsafe=False)
|
||||
print_mock.assert_has_calls([MockCall(False) for _ in range(2)])
|
||||
print_mock.assert_has_calls([MockCall(verbose=False) for _ in range(2)])
|
||||
|
||||
|
||||
def test_imply_with_report(args: argparse.Namespace, configuration: Configuration, database: SQLite,
|
||||
|
@ -1,5 +1,4 @@
|
||||
import argparse
|
||||
import pytest
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
@ -20,7 +19,7 @@ def test_run(args: argparse.Namespace, configuration: Configuration, repository:
|
||||
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))
|
||||
application_mock.assert_called_once_with([package_ahriman])
|
||||
print_mock.assert_called_once_with(verbose=True, separator=" ")
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user