|
|
|
@ -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")
|
|
|
|
|