mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-07-30 06:09:56 +00:00
add ability to add manually stored packages (#40)
* add ability to add manually stored packages * update tests * handle manual packages in remove-unknown method * live fixes also rename branches to has_remotes method and change return type
This commit is contained in:
@ -1,8 +1,21 @@
|
||||
from pytest_mock import MockerFixture
|
||||
from pathlib import Path
|
||||
from typing import Callable
|
||||
|
||||
from ahriman.models.package_source import PackageSource
|
||||
|
||||
|
||||
def _is_file_mock(is_any_file: bool, is_pkgbuild: bool) -> Callable[[Path], bool]:
|
||||
"""
|
||||
helper to mock is_file method
|
||||
:param is_any_file: value which will be return for any file
|
||||
:param is_pkgbuild: value which will be return if PKGBUILD like path asked
|
||||
:return: side effect function for the mocker object
|
||||
"""
|
||||
side_effect: Callable[[Path], bool] = lambda source: is_pkgbuild if source.name == "PKGBUILD" else is_any_file
|
||||
return side_effect
|
||||
|
||||
|
||||
def test_resolve_non_auto() -> None:
|
||||
"""
|
||||
must resolve non auto type to itself
|
||||
@ -16,19 +29,10 @@ 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)
|
||||
mocker.patch("pathlib.Path.is_file", autospec=True, side_effect=_is_file_mock(True, False))
|
||||
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
|
||||
@ -43,5 +47,23 @@ 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)
|
||||
mocker.patch("pathlib.Path.is_file", autospec=True, side_effect=_is_file_mock(True, False))
|
||||
assert PackageSource.Auto.resolve("package") == PackageSource.AUR
|
||||
|
||||
|
||||
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_local(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must resolve auto type into the directory
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=False)
|
||||
mocker.patch("pathlib.Path.is_file", autospec=True, side_effect=_is_file_mock(True, True))
|
||||
assert PackageSource.Auto.resolve("path") == PackageSource.Local
|
||||
|
@ -23,27 +23,6 @@ def test_cache_for(repository_paths: RepositoryPaths, package_ahriman: Package)
|
||||
assert path.parent == repository_paths.cache
|
||||
|
||||
|
||||
def test_create_tree(repository_paths: RepositoryPaths, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must create whole tree
|
||||
"""
|
||||
paths = {
|
||||
prop
|
||||
for prop in dir(repository_paths)
|
||||
if not prop.startswith("_")
|
||||
and not prop.endswith("_for")
|
||||
and prop not in ("architecture", "create_tree", "known_architectures", "root")
|
||||
}
|
||||
mkdir_mock = mocker.patch("pathlib.Path.mkdir")
|
||||
|
||||
repository_paths.create_tree()
|
||||
mkdir_mock.assert_has_calls(
|
||||
[
|
||||
mock.call(mode=0o755, parents=True, exist_ok=True)
|
||||
for _ in paths
|
||||
])
|
||||
|
||||
|
||||
def test_manual_for(repository_paths: RepositoryPaths, package_ahriman: Package) -> None:
|
||||
"""
|
||||
must return correct path for manual directory
|
||||
@ -69,3 +48,41 @@ def test_sources_for(repository_paths: RepositoryPaths, package_ahriman: Package
|
||||
path = repository_paths.sources_for(package_ahriman.base)
|
||||
assert path.name == package_ahriman.base
|
||||
assert path.parent == repository_paths.sources
|
||||
|
||||
|
||||
def test_tree_clear(repository_paths: RepositoryPaths, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must remove any package related files
|
||||
"""
|
||||
paths = {
|
||||
getattr(repository_paths, prop)(package_ahriman.base)
|
||||
for prop in dir(repository_paths) if prop.endswith("_for")
|
||||
}
|
||||
rmtree_mock = mocker.patch("shutil.rmtree")
|
||||
|
||||
repository_paths.tree_clear(package_ahriman.base)
|
||||
rmtree_mock.assert_has_calls(
|
||||
[
|
||||
mock.call(path, ignore_errors=True) for path in paths
|
||||
], any_order=True)
|
||||
|
||||
|
||||
def test_tree_create(repository_paths: RepositoryPaths, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must create whole tree
|
||||
"""
|
||||
paths = {
|
||||
prop
|
||||
for prop in dir(repository_paths)
|
||||
if not prop.startswith("_")
|
||||
and not prop.endswith("_for")
|
||||
and prop not in ("architecture", "known_architectures", "root", "tree_clear", "tree_create")
|
||||
}
|
||||
mkdir_mock = mocker.patch("pathlib.Path.mkdir")
|
||||
|
||||
repository_paths.tree_create()
|
||||
mkdir_mock.assert_has_calls(
|
||||
[
|
||||
mock.call(mode=0o755, parents=True, exist_ok=True)
|
||||
for _ in paths
|
||||
], any_order=True)
|
||||
|
Reference in New Issue
Block a user