mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-07-29 21:59:55 +00:00
patch support (#35)
This commit is contained in:
107
tests/ahriman/core/build_tools/test_sources.py
Normal file
107
tests/ahriman/core/build_tools/test_sources.py
Normal file
@ -0,0 +1,107 @@
|
||||
import pytest
|
||||
|
||||
from pathlib import Path
|
||||
from pytest_mock import MockerFixture
|
||||
from unittest import mock
|
||||
|
||||
from ahriman.core.build_tools.sources import Sources
|
||||
|
||||
|
||||
def test_fetch_existing(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must fetch new package via clone command
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=True)
|
||||
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
|
||||
|
||||
local = Path("local")
|
||||
Sources.fetch(local, "remote", "master")
|
||||
check_output_mock.assert_has_calls([
|
||||
mock.call("git", "fetch", "origin", "master",
|
||||
exception=pytest.helpers.anyvar(int),
|
||||
cwd=local, logger=pytest.helpers.anyvar(int)),
|
||||
mock.call("git", "checkout", "--force", "master",
|
||||
exception=pytest.helpers.anyvar(int),
|
||||
cwd=local, logger=pytest.helpers.anyvar(int)),
|
||||
mock.call("git", "reset", "--hard", "origin/master",
|
||||
exception=pytest.helpers.anyvar(int),
|
||||
cwd=local, logger=pytest.helpers.anyvar(int))
|
||||
])
|
||||
|
||||
|
||||
def test_fetch_new(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must fetch new package via clone command
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=False)
|
||||
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
|
||||
|
||||
local = Path("local")
|
||||
Sources.fetch(local, "remote", "master")
|
||||
check_output_mock.assert_has_calls([
|
||||
mock.call("git", "clone", "remote", str(local),
|
||||
exception=pytest.helpers.anyvar(int),
|
||||
logger=pytest.helpers.anyvar(int)),
|
||||
mock.call("git", "checkout", "--force", "master",
|
||||
exception=pytest.helpers.anyvar(int),
|
||||
cwd=local, logger=pytest.helpers.anyvar(int)),
|
||||
mock.call("git", "reset", "--hard", "origin/master",
|
||||
exception=pytest.helpers.anyvar(int),
|
||||
cwd=local, logger=pytest.helpers.anyvar(int))
|
||||
])
|
||||
|
||||
|
||||
def test_load(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must load packages sources correctly
|
||||
"""
|
||||
fetch_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.fetch")
|
||||
patch_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.patch")
|
||||
|
||||
Sources.load(Path("local"), "remote", Path("patches"))
|
||||
fetch_mock.assert_called_with(Path("local"), "remote")
|
||||
patch_mock.assert_called_with(Path("local"), Path("patches"))
|
||||
|
||||
|
||||
def test_patches(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must apply patches if any
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=True)
|
||||
glob_mock = mocker.patch("pathlib.Path.glob", return_value=[Path("01.patch"), Path("02.patch")])
|
||||
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
|
||||
|
||||
local = Path("local")
|
||||
Sources.patch(local, Path("patches"))
|
||||
glob_mock.assert_called_once()
|
||||
check_output_mock.assert_has_calls([
|
||||
mock.call("git", "apply", "--ignore-space-change", "--ignore-whitespace", "01.patch",
|
||||
exception=pytest.helpers.anyvar(int),
|
||||
cwd=local, logger=pytest.helpers.anyvar(int)),
|
||||
mock.call("git", "apply", "--ignore-space-change", "--ignore-whitespace", "02.patch",
|
||||
exception=pytest.helpers.anyvar(int),
|
||||
cwd=local, logger=pytest.helpers.anyvar(int)),
|
||||
])
|
||||
|
||||
|
||||
def test_patches_no_dir(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must not fail if no patches directory exists
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=False)
|
||||
glob_mock = mocker.patch("pathlib.Path.glob")
|
||||
|
||||
Sources.patch(Path("local"), Path("patches"))
|
||||
glob_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_patches_no_patches(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must not fail if no patches exist
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=True)
|
||||
mocker.patch("pathlib.Path.glob", return_value=[])
|
||||
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
|
||||
|
||||
Sources.patch(Path("local"), Path("patches"))
|
||||
check_output_mock.assert_not_called()
|
@ -1,56 +1,8 @@
|
||||
import pytest
|
||||
|
||||
from pathlib import Path
|
||||
from pytest_mock import MockerFixture
|
||||
from unittest import mock
|
||||
|
||||
from ahriman.core.build_tools.task import Task
|
||||
|
||||
|
||||
def test_fetch_existing(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must fetch new package via clone command
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=True)
|
||||
check_output_mock = mocker.patch("ahriman.core.build_tools.task.Task._check_output")
|
||||
|
||||
local = Path("local")
|
||||
Task.fetch(local, "remote", "master")
|
||||
check_output_mock.assert_has_calls([
|
||||
mock.call("git", "fetch", "origin", "master",
|
||||
exception=pytest.helpers.anyvar(int),
|
||||
cwd=local, logger=pytest.helpers.anyvar(int)),
|
||||
mock.call("git", "checkout", "--force", "master",
|
||||
exception=pytest.helpers.anyvar(int),
|
||||
cwd=local, logger=pytest.helpers.anyvar(int)),
|
||||
mock.call("git", "reset", "--hard", "origin/master",
|
||||
exception=pytest.helpers.anyvar(int),
|
||||
cwd=local, logger=pytest.helpers.anyvar(int))
|
||||
])
|
||||
|
||||
|
||||
def test_fetch_new(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must fetch new package via clone command
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=False)
|
||||
check_output_mock = mocker.patch("ahriman.core.build_tools.task.Task._check_output")
|
||||
|
||||
local = Path("local")
|
||||
Task.fetch(local, "remote", "master")
|
||||
check_output_mock.assert_has_calls([
|
||||
mock.call("git", "clone", "remote", str(local),
|
||||
exception=pytest.helpers.anyvar(int),
|
||||
logger=pytest.helpers.anyvar(int)),
|
||||
mock.call("git", "checkout", "--force", "master",
|
||||
exception=pytest.helpers.anyvar(int),
|
||||
cwd=local, logger=pytest.helpers.anyvar(int)),
|
||||
mock.call("git", "reset", "--hard", "origin/master",
|
||||
exception=pytest.helpers.anyvar(int),
|
||||
cwd=local, logger=pytest.helpers.anyvar(int))
|
||||
])
|
||||
|
||||
|
||||
def test_build(task_ahriman: Task, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must build package
|
||||
@ -65,7 +17,7 @@ def test_init_with_cache(task_ahriman: Task, mocker: MockerFixture) -> None:
|
||||
must copy tree instead of fetch
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=True)
|
||||
mocker.patch("ahriman.core.build_tools.task.Task.fetch")
|
||||
mocker.patch("ahriman.core.build_tools.sources.Sources.load")
|
||||
copytree_mock = mocker.patch("shutil.copytree")
|
||||
|
||||
task_ahriman.init(None)
|
||||
|
@ -2,6 +2,7 @@ from pytest_mock import MockerFixture
|
||||
|
||||
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:
|
||||
@ -34,25 +35,25 @@ 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, mocker: MockerFixture) -> None:
|
||||
def test_leaf_load(package_ahriman: Package, repository_paths: RepositoryPaths, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must load with dependencies
|
||||
"""
|
||||
tempdir_mock = mocker.patch("tempfile.mkdtemp")
|
||||
fetch_mock = mocker.patch("ahriman.core.build_tools.task.Task.fetch")
|
||||
load_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.load")
|
||||
dependencies_mock = mocker.patch("ahriman.models.package.Package.dependencies", return_value={"ahriman-dependency"})
|
||||
rmtree_mock = mocker.patch("shutil.rmtree")
|
||||
|
||||
leaf = Leaf.load(package_ahriman)
|
||||
leaf = Leaf.load(package_ahriman, repository_paths)
|
||||
assert leaf.package == package_ahriman
|
||||
assert leaf.dependencies == {"ahriman-dependency"}
|
||||
tempdir_mock.assert_called_once()
|
||||
fetch_mock.assert_called_once()
|
||||
load_mock.assert_called_once()
|
||||
dependencies_mock.assert_called_once()
|
||||
rmtree_mock.assert_called_once()
|
||||
|
||||
|
||||
def test_tree_levels(leaf_ahriman: Leaf, leaf_python_schedule: Leaf, mocker: MockerFixture) -> None:
|
||||
def test_tree_levels(leaf_ahriman: Leaf, leaf_python_schedule: Leaf) -> None:
|
||||
"""
|
||||
must generate correct levels in the simples case
|
||||
"""
|
||||
@ -65,14 +66,15 @@ def test_tree_levels(leaf_ahriman: Leaf, leaf_python_schedule: Leaf, mocker: Moc
|
||||
assert second == [leaf_ahriman.package]
|
||||
|
||||
|
||||
def test_tree_load(package_ahriman: Package, package_python_schedule: Package, mocker: MockerFixture) -> None:
|
||||
def test_tree_load(package_ahriman: Package, package_python_schedule: Package,
|
||||
repository_paths: RepositoryPaths, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must package list
|
||||
"""
|
||||
mocker.patch("tempfile.mkdtemp")
|
||||
mocker.patch("ahriman.core.build_tools.task.Task.fetch")
|
||||
mocker.patch("ahriman.core.build_tools.sources.Sources.load")
|
||||
mocker.patch("ahriman.models.package.Package.dependencies")
|
||||
mocker.patch("shutil.rmtree")
|
||||
|
||||
tree = Tree.load([package_ahriman, package_python_schedule])
|
||||
tree = Tree.load([package_ahriman, package_python_schedule], repository_paths)
|
||||
assert len(tree.leaves) == 2
|
||||
|
Reference in New Issue
Block a user