mirror of
				https://github.com/arcan1s/ahriman.git
				synced 2025-11-04 07:43:42 +00:00 
			
		
		
		
	add ability to specify package source explicitly during the addition
This commit is contained in:
		@ -4,6 +4,7 @@ from pytest_mock import MockerFixture
 | 
			
		||||
 | 
			
		||||
from ahriman.application.handlers import Add
 | 
			
		||||
from ahriman.core.configuration import Configuration
 | 
			
		||||
from ahriman.models.package_source import PackageSource
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def _default_args(args: argparse.Namespace) -> argparse.Namespace:
 | 
			
		||||
@ -14,6 +15,7 @@ def _default_args(args: argparse.Namespace) -> argparse.Namespace:
 | 
			
		||||
    """
 | 
			
		||||
    args.package = []
 | 
			
		||||
    args.now = False
 | 
			
		||||
    args.source = PackageSource.Auto
 | 
			
		||||
    args.without_dependencies = False
 | 
			
		||||
    return args
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -6,6 +6,7 @@ from unittest import mock
 | 
			
		||||
from ahriman.application.application import Application
 | 
			
		||||
from ahriman.core.tree import Leaf, Tree
 | 
			
		||||
from ahriman.models.package import Package
 | 
			
		||||
from ahriman.models.package_source import PackageSource
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_finalize(application: Application, mocker: MockerFixture) -> None:
 | 
			
		||||
@ -108,12 +109,11 @@ def test_add_directory(application: Application, package_ahriman: Package, mocke
 | 
			
		||||
    must add packages from directory
 | 
			
		||||
    """
 | 
			
		||||
    mocker.patch("ahriman.application.application.Application._known_packages", return_value=set())
 | 
			
		||||
    mocker.patch("pathlib.Path.is_dir", return_value=True)
 | 
			
		||||
    iterdir_mock = mocker.patch("pathlib.Path.iterdir",
 | 
			
		||||
                                return_value=[package.filepath for package in package_ahriman.packages.values()])
 | 
			
		||||
    move_mock = mocker.patch("shutil.move")
 | 
			
		||||
 | 
			
		||||
    application.add([package_ahriman.base], False)
 | 
			
		||||
    application.add([package_ahriman.base], PackageSource.Directory, False)
 | 
			
		||||
    iterdir_mock.assert_called_once()
 | 
			
		||||
    move_mock.assert_called_once()
 | 
			
		||||
 | 
			
		||||
@ -126,7 +126,7 @@ def test_add_manual(application: Application, package_ahriman: Package, mocker:
 | 
			
		||||
    mocker.patch("ahriman.models.package.Package.load", return_value=package_ahriman)
 | 
			
		||||
    fetch_mock = mocker.patch("ahriman.core.build_tools.task.Task.fetch")
 | 
			
		||||
 | 
			
		||||
    application.add([package_ahriman.base], True)
 | 
			
		||||
    application.add([package_ahriman.base], PackageSource.AUR, True)
 | 
			
		||||
    fetch_mock.assert_called_once()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -140,7 +140,7 @@ def test_add_manual_with_dependencies(application: Application, package_ahriman:
 | 
			
		||||
    mocker.patch("ahriman.core.build_tools.task.Task.fetch")
 | 
			
		||||
    dependencies_mock = mocker.patch("ahriman.models.package.Package.dependencies")
 | 
			
		||||
 | 
			
		||||
    application.add([package_ahriman.base], False)
 | 
			
		||||
    application.add([package_ahriman.base], PackageSource.AUR, False)
 | 
			
		||||
    dependencies_mock.assert_called_once()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -149,10 +149,9 @@ def test_add_package(application: Application, package_ahriman: Package, mocker:
 | 
			
		||||
    must add package from archive
 | 
			
		||||
    """
 | 
			
		||||
    mocker.patch("ahriman.application.application.Application._known_packages", return_value=set())
 | 
			
		||||
    mocker.patch("pathlib.Path.is_file", return_value=True)
 | 
			
		||||
    move_mock = mocker.patch("shutil.move")
 | 
			
		||||
 | 
			
		||||
    application.add([package_ahriman.base], False)
 | 
			
		||||
    application.add([package_ahriman.base], PackageSource.Archive, False)
 | 
			
		||||
    move_mock.assert_called_once()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -42,7 +42,7 @@ def test_packages_add(spawner: Spawn, mocker: MockerFixture) -> None:
 | 
			
		||||
    """
 | 
			
		||||
    spawn_mock = mocker.patch("ahriman.core.spawn.Spawn.spawn_process")
 | 
			
		||||
    spawner.packages_add(["ahriman", "linux"], now=False)
 | 
			
		||||
    spawn_mock.assert_called_with("add", "ahriman", "linux")
 | 
			
		||||
    spawn_mock.assert_called_with("add", "ahriman", "linux", source="aur")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_packages_add_with_build(spawner: Spawn, mocker: MockerFixture) -> None:
 | 
			
		||||
@ -51,7 +51,7 @@ def test_packages_add_with_build(spawner: Spawn, mocker: MockerFixture) -> None:
 | 
			
		||||
    """
 | 
			
		||||
    spawn_mock = mocker.patch("ahriman.core.spawn.Spawn.spawn_process")
 | 
			
		||||
    spawner.packages_add(["ahriman", "linux"], now=True)
 | 
			
		||||
    spawn_mock.assert_called_with("add", "ahriman", "linux", now="")
 | 
			
		||||
    spawn_mock.assert_called_with("add", "ahriman", "linux", source="aur", now="")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_packages_remove(spawner: Spawn, mocker: MockerFixture) -> None:
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										47
									
								
								tests/ahriman/models/test_package_source.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								tests/ahriman/models/test_package_source.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,47 @@
 | 
			
		||||
from pytest_mock import MockerFixture
 | 
			
		||||
 | 
			
		||||
from ahriman.models.package_source import PackageSource
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_resolve_non_auto() -> None:
 | 
			
		||||
    """
 | 
			
		||||
    must resolve non auto type to itself
 | 
			
		||||
    """
 | 
			
		||||
    for source in filter(lambda src: src != PackageSource.Auto, PackageSource):
 | 
			
		||||
        assert source.resolve("") == source
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_resolve_archive(mocker: MockerFixture) -> None:
 | 
			
		||||
    """
 | 
			
		||||
    must resolve auto type into the archive
 | 
			
		||||
    """
 | 
			
		||||
    mocker.patch("pathlib.Path.is_dir", return_value=False)
 | 
			
		||||
    mocker.patch("pathlib.Path.is_file", return_value=True)
 | 
			
		||||
    assert PackageSource.Auto.resolve("linux-5.14.2.arch1-2-x86_64.pkg.tar.zst") == PackageSource.Archive
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_resolve_directory(mocker: MockerFixture) -> None:
 | 
			
		||||
    """
 | 
			
		||||
    must resolve auto type into the directory
 | 
			
		||||
    """
 | 
			
		||||
    mocker.patch("pathlib.Path.is_dir", return_value=True)
 | 
			
		||||
    mocker.patch("pathlib.Path.is_file", return_value=False)
 | 
			
		||||
    assert PackageSource.Auto.resolve("path") == PackageSource.Directory
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_resolve_aur(mocker: MockerFixture) -> None:
 | 
			
		||||
    """
 | 
			
		||||
    must resolve auto type into the AUR package
 | 
			
		||||
    """
 | 
			
		||||
    mocker.patch("pathlib.Path.is_dir", return_value=False)
 | 
			
		||||
    mocker.patch("pathlib.Path.is_file", return_value=False)
 | 
			
		||||
    assert PackageSource.Auto.resolve("package") == PackageSource.AUR
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_resolve_aur_not_package_like(mocker: MockerFixture) -> None:
 | 
			
		||||
    """
 | 
			
		||||
    must resolve auto type into the AUR package if it is file, but does not look like a package archive
 | 
			
		||||
    """
 | 
			
		||||
    mocker.patch("pathlib.Path.is_dir", return_value=False)
 | 
			
		||||
    mocker.patch("pathlib.Path.is_file", return_value=True)
 | 
			
		||||
    assert PackageSource.Auto.resolve("package") == PackageSource.AUR
 | 
			
		||||
		Reference in New Issue
	
	Block a user