mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-07-29 13:49:57 +00:00
fix error with missing sources
In case if package has local cache it will fail to load because no remote source set. Particially this case can be observed during tree load
This commit is contained in:
@ -5,7 +5,9 @@ from pytest_mock import MockerFixture
|
||||
from unittest import mock
|
||||
|
||||
from ahriman.core.build_tools.sources import Sources
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.remote_source import RemoteSource
|
||||
from ahriman.models.repository_paths import RepositoryPaths
|
||||
|
||||
|
||||
def test_add(mocker: MockerFixture) -> None:
|
||||
@ -16,7 +18,7 @@ def test_add(mocker: MockerFixture) -> None:
|
||||
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
|
||||
|
||||
local = Path("local")
|
||||
Sources.add(local, "pattern1", "pattern2")
|
||||
Sources._add(local, "pattern1", "pattern2")
|
||||
glob_mock.assert_has_calls([mock.call("pattern1"), mock.call("pattern2")])
|
||||
check_output_mock.assert_called_once_with(
|
||||
"git", "add", "--intent-to-add", "1", "2", "1", "2",
|
||||
@ -30,7 +32,7 @@ def test_add_skip(mocker: MockerFixture) -> None:
|
||||
mocker.patch("pathlib.Path.glob", return_value=[])
|
||||
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
|
||||
|
||||
Sources.add(Path("local"), "pattern1")
|
||||
Sources._add(Path("local"), "pattern1")
|
||||
check_output_mock.assert_not_called()
|
||||
|
||||
|
||||
@ -41,9 +43,29 @@ def test_diff(mocker: MockerFixture) -> None:
|
||||
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
|
||||
|
||||
local = Path("local")
|
||||
assert Sources.diff(local)
|
||||
check_output_mock.assert_called_once_with("git", "diff",
|
||||
exception=None, cwd=local, logger=pytest.helpers.anyvar(int))
|
||||
assert Sources._diff(local)
|
||||
check_output_mock.assert_called_once_with(
|
||||
"git", "diff", exception=None, cwd=local, logger=pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
def test_move(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must move content between directories
|
||||
"""
|
||||
mocker.patch("ahriman.core.build_tools.sources.walk", return_value=[Path("/source/path")])
|
||||
move_mock = mocker.patch("shutil.move")
|
||||
|
||||
Sources._move(Path("/source"), Path("/destination"))
|
||||
move_mock.assert_called_once_with(Path("/source/path"), Path("/destination/path"))
|
||||
|
||||
|
||||
def test_move_same(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must not do anything in case if directories are the same
|
||||
"""
|
||||
walk_mock = mocker.patch("ahriman.core.build_tools.sources.walk")
|
||||
Sources._move(Path("/same"), Path("/same"))
|
||||
walk_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_fetch_empty(remote_source: RemoteSource, mocker: MockerFixture) -> None:
|
||||
@ -65,7 +87,7 @@ def test_fetch_existing(remote_source: RemoteSource, mocker: MockerFixture) -> N
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=True)
|
||||
mocker.patch("ahriman.core.build_tools.sources.Sources.has_remotes", return_value=True)
|
||||
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
|
||||
move_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.move")
|
||||
move_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._move")
|
||||
|
||||
local = Path("local")
|
||||
Sources.fetch(local, remote_source)
|
||||
@ -86,7 +108,7 @@ def test_fetch_new(remote_source: RemoteSource, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=False)
|
||||
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
|
||||
move_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.move")
|
||||
move_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._move")
|
||||
|
||||
local = Path("local")
|
||||
Sources.fetch(local, remote_source)
|
||||
@ -107,7 +129,7 @@ def test_fetch_new_without_remote(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=False)
|
||||
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
|
||||
move_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.move")
|
||||
move_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._move")
|
||||
|
||||
local = Path("local")
|
||||
Sources.fetch(local, None)
|
||||
@ -125,7 +147,7 @@ def test_fetch_relative(remote_source: RemoteSource, mocker: MockerFixture) -> N
|
||||
must process move correctly on relative directory
|
||||
"""
|
||||
mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
|
||||
move_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.move")
|
||||
move_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._move")
|
||||
|
||||
Sources.fetch(Path("path"), remote_source)
|
||||
move_mock.assert_called_once_with(Path("path").resolve(), Path("path"))
|
||||
@ -139,8 +161,8 @@ def test_has_remotes(mocker: MockerFixture) -> None:
|
||||
|
||||
local = Path("local")
|
||||
assert Sources.has_remotes(local)
|
||||
check_output_mock.assert_called_once_with("git", "remote",
|
||||
exception=None, cwd=local, logger=pytest.helpers.anyvar(int))
|
||||
check_output_mock.assert_called_once_with(
|
||||
"git", "remote", exception=None, cwd=local, logger=pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
def test_has_remotes_empty(mocker: MockerFixture) -> None:
|
||||
@ -163,47 +185,41 @@ def test_init(mocker: MockerFixture) -> None:
|
||||
exception=None, cwd=local, logger=pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
def test_load(remote_source: RemoteSource, mocker: MockerFixture) -> None:
|
||||
def test_load(package_ahriman: Package, repository_paths: RepositoryPaths, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must load packages sources correctly
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=False)
|
||||
fetch_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.fetch")
|
||||
patch_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.patch_apply")
|
||||
|
||||
Sources.load(Path("local"), remote_source, "patch")
|
||||
fetch_mock.assert_called_once_with(Path("local"), remote_source)
|
||||
Sources.load(Path("local"), package_ahriman, "patch", repository_paths)
|
||||
fetch_mock.assert_called_once_with(Path("local"), package_ahriman.remote)
|
||||
patch_mock.assert_called_once_with(Path("local"), "patch")
|
||||
|
||||
|
||||
def test_load_no_patch(remote_source: RemoteSource, mocker: MockerFixture) -> None:
|
||||
def test_load_no_patch(package_ahriman: Package, repository_paths: RepositoryPaths, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must load packages sources correctly without patches
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=False)
|
||||
mocker.patch("ahriman.core.build_tools.sources.Sources.fetch")
|
||||
patch_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.patch_apply")
|
||||
|
||||
Sources.load(Path("local"), remote_source, None)
|
||||
Sources.load(Path("local"), package_ahriman, None, repository_paths)
|
||||
patch_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_move(mocker: MockerFixture) -> None:
|
||||
def test_load_with_cache(package_ahriman: Package, repository_paths: RepositoryPaths, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must move content between directories
|
||||
must load sources by using local cache
|
||||
"""
|
||||
mocker.patch("ahriman.core.build_tools.sources.walk", return_value=[Path("/source/path")])
|
||||
move_mock = mocker.patch("shutil.move")
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=True)
|
||||
copytree_mock = mocker.patch("shutil.copytree")
|
||||
mocker.patch("ahriman.core.build_tools.sources.Sources.fetch")
|
||||
|
||||
Sources.move(Path("/source"), Path("/destination"))
|
||||
move_mock.assert_called_once_with(Path("/source/path"), Path("/destination/path"))
|
||||
|
||||
|
||||
def test_move_same(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must not do anything in case if directories are the same
|
||||
"""
|
||||
walk_mock = mocker.patch("ahriman.core.build_tools.sources.walk")
|
||||
Sources.move(Path("/same"), Path("/same"))
|
||||
walk_mock.assert_not_called()
|
||||
Sources.load(Path("local"), package_ahriman, None, repository_paths)
|
||||
copytree_mock.assert_called_once() # we do not check full command here, sorry
|
||||
|
||||
|
||||
def test_patch_apply(mocker: MockerFixture) -> None:
|
||||
@ -224,8 +240,8 @@ def test_patch_create(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must create patch set for the package
|
||||
"""
|
||||
add_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.add")
|
||||
diff_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.diff")
|
||||
add_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._add")
|
||||
diff_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._diff")
|
||||
|
||||
Sources.patch_create(Path("local"), "glob")
|
||||
add_mock.assert_called_once_with(Path("local"), "glob")
|
||||
@ -236,6 +252,6 @@ def test_patch_create_with_newline(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
created patch must have new line at the end
|
||||
"""
|
||||
mocker.patch("ahriman.core.build_tools.sources.Sources.add")
|
||||
mocker.patch("ahriman.core.build_tools.sources.Sources.diff", return_value="diff")
|
||||
mocker.patch("ahriman.core.build_tools.sources.Sources._add")
|
||||
mocker.patch("ahriman.core.build_tools.sources.Sources._diff", return_value="diff")
|
||||
assert Sources.patch_create(Path("local"), "glob").endswith("\n")
|
||||
|
@ -14,13 +14,10 @@ def test_build(task_ahriman: Task, mocker: MockerFixture) -> None:
|
||||
check_output_mock.assert_called()
|
||||
|
||||
|
||||
def test_init_with_cache(task_ahriman: Task, database: SQLite, mocker: MockerFixture) -> None:
|
||||
def test_init(task_ahriman: Task, database: SQLite, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must copy tree instead of fetch
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=True)
|
||||
mocker.patch("ahriman.core.build_tools.sources.Sources.load")
|
||||
copytree_mock = mocker.patch("shutil.copytree")
|
||||
|
||||
load_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.load")
|
||||
task_ahriman.init(Path("ahriman"), database)
|
||||
copytree_mock.assert_called_once() # we do not check full command here, sorry
|
||||
load_mock.assert_called_once_with(Path("ahriman"), task_ahriman.package, None, task_ahriman.paths)
|
||||
|
@ -5,6 +5,7 @@ from pytest_mock import MockerFixture
|
||||
from ahriman.core.database import SQLite
|
||||
from ahriman.core.tree import Leaf, Tree
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.repository_paths import RepositoryPaths
|
||||
|
||||
|
||||
def test_leaf_is_root_empty(leaf_ahriman: Leaf) -> None:
|
||||
@ -37,7 +38,8 @@ def test_leaf_is_root_true(leaf_ahriman: Leaf, leaf_python_schedule: Leaf) -> No
|
||||
assert not leaf_ahriman.is_root([leaf_python_schedule])
|
||||
|
||||
|
||||
def test_leaf_load(package_ahriman: Package, database: SQLite, mocker: MockerFixture) -> None:
|
||||
def test_leaf_load(package_ahriman: Package, repository_paths: RepositoryPaths,
|
||||
database: SQLite, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must load with dependencies
|
||||
"""
|
||||
@ -46,12 +48,12 @@ def test_leaf_load(package_ahriman: Package, database: SQLite, mocker: MockerFix
|
||||
dependencies_mock = mocker.patch("ahriman.models.package.Package.dependencies", return_value={"ahriman-dependency"})
|
||||
rmtree_mock = mocker.patch("shutil.rmtree")
|
||||
|
||||
leaf = Leaf.load(package_ahriman, database)
|
||||
leaf = Leaf.load(package_ahriman, repository_paths, database)
|
||||
assert leaf.package == package_ahriman
|
||||
assert leaf.dependencies == {"ahriman-dependency"}
|
||||
tempdir_mock.assert_called_once_with()
|
||||
load_mock.assert_called_once_with(
|
||||
pytest.helpers.anyvar(int), package_ahriman.remote, database.patches_get(package_ahriman.base))
|
||||
pytest.helpers.anyvar(int), package_ahriman, None, repository_paths)
|
||||
dependencies_mock.assert_called_once_with(pytest.helpers.anyvar(int))
|
||||
rmtree_mock.assert_called_once_with(pytest.helpers.anyvar(int), ignore_errors=True)
|
||||
|
||||
@ -69,8 +71,8 @@ def test_tree_levels(leaf_ahriman: Leaf, leaf_python_schedule: Leaf) -> None:
|
||||
assert second == [leaf_ahriman.package]
|
||||
|
||||
|
||||
def test_tree_load(package_ahriman: Package, package_python_schedule: Package, database: SQLite,
|
||||
mocker: MockerFixture) -> None:
|
||||
def test_tree_load(package_ahriman: Package, package_python_schedule: Package, repository_paths: RepositoryPaths,
|
||||
database: SQLite, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must package list
|
||||
"""
|
||||
@ -79,5 +81,5 @@ def test_tree_load(package_ahriman: Package, package_python_schedule: Package, d
|
||||
mocker.patch("ahriman.models.package.Package.dependencies")
|
||||
mocker.patch("shutil.rmtree")
|
||||
|
||||
tree = Tree.load([package_ahriman, package_python_schedule], database)
|
||||
tree = Tree.load([package_ahriman, package_python_schedule], repository_paths, database)
|
||||
assert len(tree.leaves) == 2
|
||||
|
Reference in New Issue
Block a user