mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-06-28 06:41:43 +00:00
implement single-function patches (#69)
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import argparse
|
||||
import pytest
|
||||
import sys
|
||||
|
||||
from pathlib import Path
|
||||
from pytest_mock import MockerFixture
|
||||
@ -9,6 +10,7 @@ from ahriman.application.handlers import Patch
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.models.action import Action
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.pkgbuild_patch import PkgbuildPatch
|
||||
|
||||
|
||||
def _default_args(args: argparse.Namespace) -> argparse.Namespace:
|
||||
@ -25,6 +27,7 @@ def _default_args(args: argparse.Namespace) -> argparse.Namespace:
|
||||
args.exit_code = False
|
||||
args.remove = False
|
||||
args.track = ["*.diff", "*.patch"]
|
||||
args.variable = None
|
||||
return args
|
||||
|
||||
|
||||
@ -35,12 +38,31 @@ def test_run(args: argparse.Namespace, configuration: Configuration, mocker: Moc
|
||||
args = _default_args(args)
|
||||
args.action = Action.Update
|
||||
mocker.patch("ahriman.models.repository_paths.RepositoryPaths.tree_create")
|
||||
patch_mock = mocker.patch("ahriman.application.handlers.Patch.patch_create_from_diff",
|
||||
return_value=(args.package, PkgbuildPatch(None, "patch")))
|
||||
application_mock = mocker.patch("ahriman.application.handlers.Patch.patch_set_create")
|
||||
on_start_mock = mocker.patch("ahriman.application.application.Application.on_start")
|
||||
|
||||
Patch.run(args, "x86_64", configuration, True, False)
|
||||
application_mock.assert_called_once_with(pytest.helpers.anyvar(int), Path(args.package), args.track)
|
||||
on_start_mock.assert_called_once_with()
|
||||
patch_mock.assert_called_once_with(args.package, args.track)
|
||||
application_mock.assert_called_once_with(pytest.helpers.anyvar(int), args.package, PkgbuildPatch(None, "patch"))
|
||||
|
||||
|
||||
def test_run_function(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must run command with patch function flag
|
||||
"""
|
||||
args = _default_args(args)
|
||||
args.action = Action.Update
|
||||
args.patch = "patch"
|
||||
args.variable = "version"
|
||||
patch = PkgbuildPatch(args.variable, args.patch)
|
||||
mocker.patch("ahriman.models.repository_paths.RepositoryPaths.tree_create")
|
||||
patch_mock = mocker.patch("ahriman.application.handlers.Patch.patch_create_from_function", return_value=patch)
|
||||
application_mock = mocker.patch("ahriman.application.handlers.Patch.patch_set_create")
|
||||
|
||||
Patch.run(args, "x86_64", configuration, True, False)
|
||||
patch_mock.assert_called_once_with(args.variable, args.patch)
|
||||
application_mock.assert_called_once_with(pytest.helpers.anyvar(int), args.package, patch)
|
||||
|
||||
|
||||
def test_run_list(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
@ -49,11 +71,12 @@ def test_run_list(args: argparse.Namespace, configuration: Configuration, mocker
|
||||
"""
|
||||
args = _default_args(args)
|
||||
args.action = Action.List
|
||||
args.variable = ["version"]
|
||||
mocker.patch("ahriman.models.repository_paths.RepositoryPaths.tree_create")
|
||||
application_mock = mocker.patch("ahriman.application.handlers.Patch.patch_set_list")
|
||||
|
||||
Patch.run(args, "x86_64", configuration, True, False)
|
||||
application_mock.assert_called_once_with(pytest.helpers.anyvar(int), args.package, False)
|
||||
application_mock.assert_called_once_with(pytest.helpers.anyvar(int), args.package, ["version"], False)
|
||||
|
||||
|
||||
def test_run_remove(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
@ -62,24 +85,71 @@ def test_run_remove(args: argparse.Namespace, configuration: Configuration, mock
|
||||
"""
|
||||
args = _default_args(args)
|
||||
args.action = Action.Remove
|
||||
args.variable = ["version"]
|
||||
mocker.patch("ahriman.models.repository_paths.RepositoryPaths.tree_create")
|
||||
application_mock = mocker.patch("ahriman.application.handlers.Patch.patch_set_remove")
|
||||
|
||||
Patch.run(args, "x86_64", configuration, True, False)
|
||||
application_mock.assert_called_once_with(pytest.helpers.anyvar(int), args.package)
|
||||
application_mock.assert_called_once_with(pytest.helpers.anyvar(int), args.package, ["version"])
|
||||
|
||||
|
||||
def test_patch_create_from_diff(package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must create patch from directory tree diff
|
||||
"""
|
||||
patch = PkgbuildPatch(None, "patch")
|
||||
path = Path("local")
|
||||
mocker.patch("pathlib.Path.mkdir")
|
||||
package_mock = mocker.patch("ahriman.models.package.Package.from_build", return_value=package_ahriman)
|
||||
sources_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.patch_create", return_value=patch.value)
|
||||
|
||||
assert Patch.patch_create_from_diff(path, ["*.diff"]) == (package_ahriman.base, patch)
|
||||
package_mock.assert_called_once_with(path)
|
||||
sources_mock.assert_called_once_with(path, "*.diff")
|
||||
|
||||
|
||||
def test_patch_create_from_function(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must create function patch from file
|
||||
"""
|
||||
path = Path("local")
|
||||
patch = PkgbuildPatch("version", "patch")
|
||||
read_mock = mocker.patch("pathlib.Path.read_text", return_value=patch.value)
|
||||
|
||||
assert Patch.patch_create_from_function(patch.key, path) == patch
|
||||
read_mock.assert_called_once_with(encoding="utf8")
|
||||
|
||||
|
||||
def test_patch_create_from_function_stdin(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must create function patch from stdin
|
||||
"""
|
||||
patch = PkgbuildPatch("version", "This is a patch")
|
||||
mocker.patch.object(sys, "stdin", patch.value.splitlines())
|
||||
assert Patch.patch_create_from_function(patch.key, None) == patch
|
||||
|
||||
|
||||
def test_patch_create_from_function_strip(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must remove spaces at the beginning and at the end of the line
|
||||
"""
|
||||
patch = PkgbuildPatch("version", "This is a patch")
|
||||
mocker.patch.object(sys, "stdin", ["\n"] + patch.value.splitlines() + ["\n"])
|
||||
assert Patch.patch_create_from_function(patch.key, None) == patch
|
||||
|
||||
|
||||
def test_patch_set_list(application: Application, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must list available patches for the command
|
||||
"""
|
||||
get_mock = mocker.patch("ahriman.core.database.SQLite.patches_list", return_value={"ahriman": "patch"})
|
||||
get_mock = mocker.patch("ahriman.core.database.SQLite.patches_list",
|
||||
return_value={"ahriman": PkgbuildPatch(None, "patch")})
|
||||
print_mock = mocker.patch("ahriman.core.formatters.Printer.print")
|
||||
check_mock = mocker.patch("ahriman.application.handlers.Handler.check_if_empty")
|
||||
|
||||
Patch.patch_set_list(application, "ahriman", False)
|
||||
get_mock.assert_called_once_with("ahriman")
|
||||
print_mock.assert_called_once_with(verbose=True)
|
||||
Patch.patch_set_list(application, "ahriman", ["version"], False)
|
||||
get_mock.assert_called_once_with("ahriman", ["version"])
|
||||
print_mock.assert_called_once_with(verbose=True, separator=" = ")
|
||||
check_mock.assert_called_once_with(False, False)
|
||||
|
||||
|
||||
@ -90,7 +160,7 @@ def test_patch_set_list_empty_exception(application: Application, mocker: Mocker
|
||||
mocker.patch("ahriman.core.database.SQLite.patches_list", return_value={})
|
||||
check_mock = mocker.patch("ahriman.application.handlers.Handler.check_if_empty")
|
||||
|
||||
Patch.patch_set_list(application, "ahriman", True)
|
||||
Patch.patch_set_list(application, "ahriman", [], True)
|
||||
check_mock.assert_called_once_with(True, True)
|
||||
|
||||
|
||||
@ -98,13 +168,9 @@ def test_patch_set_create(application: Application, package_ahriman: Package, mo
|
||||
"""
|
||||
must create patch set for the package
|
||||
"""
|
||||
mocker.patch("pathlib.Path.mkdir")
|
||||
mocker.patch("ahriman.models.package.Package.from_build", return_value=package_ahriman)
|
||||
mocker.patch("ahriman.core.build_tools.sources.Sources.patch_create", return_value="patch")
|
||||
create_mock = mocker.patch("ahriman.core.database.SQLite.patches_insert")
|
||||
|
||||
Patch.patch_set_create(application, Path("path"), ["*.patch"])
|
||||
create_mock.assert_called_once_with(package_ahriman.base, "patch")
|
||||
Patch.patch_set_create(application, package_ahriman.base, PkgbuildPatch("version", package_ahriman.version))
|
||||
create_mock.assert_called_once_with(package_ahriman.base, PkgbuildPatch("version", package_ahriman.version))
|
||||
|
||||
|
||||
def test_patch_set_remove(application: Application, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
@ -112,5 +178,5 @@ def test_patch_set_remove(application: Application, package_ahriman: Package, mo
|
||||
must remove patch set for the package
|
||||
"""
|
||||
remove_mock = mocker.patch("ahriman.core.database.SQLite.patches_remove")
|
||||
Patch.patch_set_remove(application, package_ahriman.base)
|
||||
remove_mock.assert_called_once_with(package_ahriman.base)
|
||||
Patch.patch_set_remove(application, package_ahriman.base, ["version"])
|
||||
remove_mock.assert_called_once_with(package_ahriman.base, ["version"])
|
||||
|
@ -197,7 +197,7 @@ def test_subparsers_patch_add(parser: argparse.ArgumentParser) -> None:
|
||||
"""
|
||||
patch-add command must imply action, architecture list, lock and no-report
|
||||
"""
|
||||
args = parser.parse_args(["patch-add", "ahriman"])
|
||||
args = parser.parse_args(["patch-add", "ahriman", "version"])
|
||||
assert args.action == Action.Update
|
||||
assert args.architecture == [""]
|
||||
assert args.lock is None
|
||||
@ -208,18 +208,10 @@ def test_subparsers_patch_add_architecture(parser: argparse.ArgumentParser) -> N
|
||||
"""
|
||||
patch-add command must correctly parse architecture list
|
||||
"""
|
||||
args = parser.parse_args(["-a", "x86_64", "patch-add", "ahriman"])
|
||||
args = parser.parse_args(["-a", "x86_64", "patch-add", "ahriman", "version"])
|
||||
assert args.architecture == [""]
|
||||
|
||||
|
||||
def test_subparsers_patch_add_track(parser: argparse.ArgumentParser) -> None:
|
||||
"""
|
||||
patch-add command must correctly parse track files patterns
|
||||
"""
|
||||
args = parser.parse_args(["patch-add", "-t", "*.py", "ahriman"])
|
||||
assert args.track == ["*.diff", "*.patch", "*.py"]
|
||||
|
||||
|
||||
def test_subparsers_patch_list(parser: argparse.ArgumentParser) -> None:
|
||||
"""
|
||||
patch-list command must imply action, architecture list, lock and no-report
|
||||
@ -258,6 +250,42 @@ def test_subparsers_patch_remove_architecture(parser: argparse.ArgumentParser) -
|
||||
assert args.architecture == [""]
|
||||
|
||||
|
||||
def test_subparsers_patch_set_add(parser: argparse.ArgumentParser) -> None:
|
||||
"""
|
||||
patch-set-add command must imply action, architecture list, lock, no-report and variable
|
||||
"""
|
||||
args = parser.parse_args(["patch-set-add", "ahriman"])
|
||||
assert args.action == Action.Update
|
||||
assert args.architecture == [""]
|
||||
assert args.lock is None
|
||||
assert args.no_report
|
||||
assert args.variable is None
|
||||
|
||||
|
||||
def test_subparsers_patch_set_add_architecture(parser: argparse.ArgumentParser) -> None:
|
||||
"""
|
||||
patch-set-add command must correctly parse architecture list
|
||||
"""
|
||||
args = parser.parse_args(["-a", "x86_64", "patch-set-add", "ahriman"])
|
||||
assert args.architecture == [""]
|
||||
|
||||
|
||||
def test_subparsers_patch_set_add_option_package(parser: argparse.ArgumentParser) -> None:
|
||||
"""
|
||||
patch-set-add command must convert package option to path instance
|
||||
"""
|
||||
args = parser.parse_args(["patch-set-add", "ahriman"])
|
||||
assert isinstance(args.package, Path)
|
||||
|
||||
|
||||
def test_subparsers_patch_set_add_option_track(parser: argparse.ArgumentParser) -> None:
|
||||
"""
|
||||
patch-set-add command must correctly parse track files patterns
|
||||
"""
|
||||
args = parser.parse_args(["patch-set-add", "-t", "*.py", "ahriman"])
|
||||
assert args.track == ["*.diff", "*.patch", "*.py"]
|
||||
|
||||
|
||||
def test_subparsers_repo_backup(parser: argparse.ArgumentParser) -> None:
|
||||
"""
|
||||
repo-backup command must imply architecture list, lock, no-report and unsafe
|
||||
|
@ -6,6 +6,7 @@ from unittest import mock
|
||||
|
||||
from ahriman.core.build_tools.sources import Sources
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.pkgbuild_patch import PkgbuildPatch
|
||||
from ahriman.models.remote_source import RemoteSource
|
||||
from ahriman.models.repository_paths import RepositoryPaths
|
||||
|
||||
@ -16,11 +17,9 @@ def test_extend_architectures(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_file", return_value=True)
|
||||
archs_mock = mocker.patch("ahriman.models.package.Package.supported_architectures", return_value={"x86_64"})
|
||||
write_mock = mocker.patch("ahriman.models.pkgbuild_patch.PkgbuildPatch.write")
|
||||
|
||||
Sources.extend_architectures(Path("local"), "i686")
|
||||
assert Sources.extend_architectures(Path("local"), "i686") == [PkgbuildPatch("arch", list({"x86_64", "i686"}))]
|
||||
archs_mock.assert_called_once_with(Path("local"))
|
||||
write_mock.assert_called_once_with(Path("local") / "PKGBUILD")
|
||||
|
||||
|
||||
def test_extend_architectures_any(mocker: MockerFixture) -> None:
|
||||
@ -29,21 +28,7 @@ def test_extend_architectures_any(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_file", return_value=True)
|
||||
mocker.patch("ahriman.models.package.Package.supported_architectures", return_value={"any"})
|
||||
write_mock = mocker.patch("ahriman.models.pkgbuild_patch.PkgbuildPatch.write")
|
||||
|
||||
Sources.extend_architectures(Path("local"), "i686")
|
||||
write_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_extend_architectures_skip(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must skip extending list of the architectures in case if no PKGBUILD file found
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_file", return_value=False)
|
||||
write_mock = mocker.patch("ahriman.models.pkgbuild_patch.PkgbuildPatch.write")
|
||||
|
||||
Sources.extend_architectures(Path("local"), "i686")
|
||||
write_mock.assert_not_called()
|
||||
assert Sources.extend_architectures(Path("local"), "i686") == []
|
||||
|
||||
|
||||
def test_fetch_empty(remote_source: RemoteSource, mocker: MockerFixture) -> None:
|
||||
@ -167,15 +152,16 @@ def test_load(package_ahriman: Package, repository_paths: RepositoryPaths, mocke
|
||||
"""
|
||||
must load packages sources correctly
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=False)
|
||||
patch = PkgbuildPatch(None, "patch")
|
||||
path = Path("local")
|
||||
fetch_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.fetch")
|
||||
patch_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.patch_apply")
|
||||
architectures_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.extend_architectures")
|
||||
architectures_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.extend_architectures", return_value=[])
|
||||
|
||||
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")
|
||||
architectures_mock.assert_called_once_with(Path("local"), repository_paths.architecture)
|
||||
Sources.load(path, package_ahriman, [patch], repository_paths)
|
||||
fetch_mock.assert_called_once_with(path, package_ahriman.remote)
|
||||
patch_mock.assert_called_once_with(path, patch)
|
||||
architectures_mock.assert_called_once_with(path, repository_paths.architecture)
|
||||
|
||||
|
||||
def test_load_no_patch(package_ahriman: Package, repository_paths: RepositoryPaths, mocker: MockerFixture) -> None:
|
||||
@ -184,9 +170,10 @@ def test_load_no_patch(package_ahriman: Package, repository_paths: RepositoryPat
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=False)
|
||||
mocker.patch("ahriman.core.build_tools.sources.Sources.fetch")
|
||||
mocker.patch("ahriman.core.build_tools.sources.Sources.extend_architectures", return_value=[])
|
||||
patch_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.patch_apply")
|
||||
|
||||
Sources.load(Path("local"), package_ahriman, None, repository_paths)
|
||||
Sources.load(Path("local"), package_ahriman, [], repository_paths)
|
||||
patch_mock.assert_not_called()
|
||||
|
||||
|
||||
@ -197,8 +184,9 @@ def test_load_with_cache(package_ahriman: Package, repository_paths: RepositoryP
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=True)
|
||||
copytree_mock = mocker.patch("shutil.copytree")
|
||||
mocker.patch("ahriman.core.build_tools.sources.Sources.fetch")
|
||||
mocker.patch("ahriman.core.build_tools.sources.Sources.extend_architectures", return_value=[])
|
||||
|
||||
Sources.load(Path("local"), package_ahriman, None, repository_paths)
|
||||
Sources.load(Path("local"), package_ahriman, [], repository_paths)
|
||||
copytree_mock.assert_called_once() # we do not check full command here, sorry
|
||||
|
||||
|
||||
@ -331,11 +319,24 @@ def test_patch_apply(sources: Sources, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must apply patches if any
|
||||
"""
|
||||
patch = PkgbuildPatch(None, "patch")
|
||||
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
|
||||
|
||||
local = Path("local")
|
||||
sources.patch_apply(local, "patches")
|
||||
sources.patch_apply(local, patch)
|
||||
check_output_mock.assert_called_once_with(
|
||||
"git", "apply", "--ignore-space-change", "--ignore-whitespace",
|
||||
exception=None, cwd=local, input_data="patches", logger=pytest.helpers.anyvar(int)
|
||||
exception=None, cwd=local, input_data=patch.value, logger=pytest.helpers.anyvar(int)
|
||||
)
|
||||
|
||||
|
||||
def test_patch_apply_function(sources: Sources, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must apply single-function patches
|
||||
"""
|
||||
patch = PkgbuildPatch("version", "42")
|
||||
local = Path("local")
|
||||
write_mock = mocker.patch("ahriman.models.pkgbuild_patch.PkgbuildPatch.write")
|
||||
|
||||
sources.patch_apply(local, patch)
|
||||
write_mock.assert_called_once_with(local / "PKGBUILD")
|
||||
|
@ -20,4 +20,4 @@ def test_init(task_ahriman: Task, database: SQLite, mocker: MockerFixture) -> No
|
||||
"""
|
||||
load_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.load")
|
||||
task_ahriman.init(Path("ahriman"), database)
|
||||
load_mock.assert_called_once_with(Path("ahriman"), task_ahriman.package, None, task_ahriman.paths)
|
||||
load_mock.assert_called_once_with(Path("ahriman"), task_ahriman.package, [], task_ahriman.paths)
|
||||
|
@ -0,0 +1,8 @@
|
||||
from ahriman.core.database.migrations.m003_patch_variables import steps
|
||||
|
||||
|
||||
def test_migration_package_source() -> None:
|
||||
"""
|
||||
migration must not be empty
|
||||
"""
|
||||
assert steps
|
@ -1,55 +1,96 @@
|
||||
from ahriman.core.database import SQLite
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.pkgbuild_patch import PkgbuildPatch
|
||||
|
||||
|
||||
def test_patches_get_insert(database: SQLite, package_ahriman: Package, package_python_schedule: Package) -> None:
|
||||
"""
|
||||
must insert patch to database
|
||||
"""
|
||||
database.patches_insert(package_ahriman.base, "patch_1")
|
||||
database.patches_insert(package_python_schedule.base, "patch_2")
|
||||
assert database.patches_get(package_ahriman.base) == "patch_1"
|
||||
assert not database.build_queue_get()
|
||||
database.patches_insert(package_ahriman.base, PkgbuildPatch(None, "patch_1"))
|
||||
database.patches_insert(package_ahriman.base, PkgbuildPatch("key", "patch_3"))
|
||||
database.patches_insert(package_python_schedule.base, PkgbuildPatch(None, "patch_2"))
|
||||
assert database.patches_get(package_ahriman.base) == [
|
||||
PkgbuildPatch(None, "patch_1"), PkgbuildPatch("key", "patch_3")
|
||||
]
|
||||
|
||||
|
||||
def test_patches_list(database: SQLite, package_ahriman: Package, package_python_schedule: Package) -> None:
|
||||
"""
|
||||
must list all patches
|
||||
"""
|
||||
database.patches_insert(package_ahriman.base, "patch1")
|
||||
database.patches_insert(package_python_schedule.base, "patch2")
|
||||
assert database.patches_list(None) == {package_ahriman.base: "patch1", package_python_schedule.base: "patch2"}
|
||||
database.patches_insert(package_ahriman.base, PkgbuildPatch(None, "patch1"))
|
||||
database.patches_insert(package_ahriman.base, PkgbuildPatch("key", "patch3"))
|
||||
database.patches_insert(package_python_schedule.base, PkgbuildPatch(None, "patch2"))
|
||||
assert database.patches_list(None, []) == {
|
||||
package_ahriman.base: [PkgbuildPatch(None, "patch1"), PkgbuildPatch("key", "patch3")],
|
||||
package_python_schedule.base: [PkgbuildPatch(None, "patch2")],
|
||||
}
|
||||
|
||||
|
||||
def test_patches_list_filter(database: SQLite, package_ahriman: Package, package_python_schedule: Package) -> None:
|
||||
"""
|
||||
must list all patches filtered by package name (same as get)
|
||||
"""
|
||||
database.patches_insert(package_ahriman.base, "patch1")
|
||||
database.patches_insert(package_python_schedule.base, "patch2")
|
||||
database.patches_insert(package_ahriman.base, PkgbuildPatch(None, "patch1"))
|
||||
database.patches_insert(package_python_schedule.base, PkgbuildPatch(None, "patch2"))
|
||||
|
||||
assert database.patches_list(package_ahriman.base) == {package_ahriman.base: "patch1"}
|
||||
assert database.patches_list(package_python_schedule.base) == {package_python_schedule.base: "patch2"}
|
||||
assert database.patches_list(package_ahriman.base, []) == {package_ahriman.base: [PkgbuildPatch(None, "patch1")]}
|
||||
assert database.patches_list(package_python_schedule.base, []) == {
|
||||
package_python_schedule.base: [PkgbuildPatch(None, "patch2")],
|
||||
}
|
||||
|
||||
|
||||
def test_patches_list_filter_by_variable(database: SQLite, package_ahriman: Package,
|
||||
package_python_schedule: Package) -> None:
|
||||
"""
|
||||
must list all patches filtered by package name (same as get)
|
||||
"""
|
||||
database.patches_insert(package_ahriman.base, PkgbuildPatch(None, "patch1"))
|
||||
database.patches_insert(package_ahriman.base, PkgbuildPatch("key", "patch2"))
|
||||
database.patches_insert(package_python_schedule.base, PkgbuildPatch(None, "patch3"))
|
||||
|
||||
assert database.patches_list(None, []) == {
|
||||
package_ahriman.base: [PkgbuildPatch(None, "patch1"), PkgbuildPatch("key", "patch2")],
|
||||
package_python_schedule.base: [PkgbuildPatch(None, "patch3")],
|
||||
}
|
||||
assert database.patches_list(None, ["key"]) == {
|
||||
package_ahriman.base: [PkgbuildPatch("key", "patch2")],
|
||||
}
|
||||
|
||||
|
||||
def test_patches_insert_remove(database: SQLite, package_ahriman: Package, package_python_schedule: Package) -> None:
|
||||
"""
|
||||
must remove patch from database
|
||||
"""
|
||||
database.patches_insert(package_ahriman.base, "patch_1")
|
||||
database.patches_insert(package_python_schedule.base, "patch_2")
|
||||
database.patches_remove(package_ahriman.base)
|
||||
database.patches_insert(package_ahriman.base, PkgbuildPatch(None, "patch1"))
|
||||
database.patches_insert(package_python_schedule.base, PkgbuildPatch(None, "patch2"))
|
||||
database.patches_remove(package_ahriman.base, [])
|
||||
|
||||
assert database.patches_get(package_ahriman.base) is None
|
||||
database.patches_insert(package_python_schedule.base, "patch_2")
|
||||
assert database.patches_get(package_ahriman.base) == []
|
||||
assert database.patches_get(package_python_schedule.base) == [PkgbuildPatch(None, "patch2")]
|
||||
|
||||
|
||||
def test_patches_insert_remove_by_variable(database: SQLite, package_ahriman: Package,
|
||||
package_python_schedule: Package) -> None:
|
||||
"""
|
||||
must remove patch from database by variable
|
||||
"""
|
||||
database.patches_insert(package_ahriman.base, PkgbuildPatch(None, "patch1"))
|
||||
database.patches_insert(package_ahriman.base, PkgbuildPatch("key", "patch3"))
|
||||
database.patches_insert(package_python_schedule.base, PkgbuildPatch(None, "patch2"))
|
||||
database.patches_remove(package_ahriman.base, ["key"])
|
||||
|
||||
assert database.patches_get(package_ahriman.base) == [PkgbuildPatch(None, "patch1")]
|
||||
assert database.patches_get(package_python_schedule.base) == [PkgbuildPatch(None, "patch2")]
|
||||
|
||||
|
||||
def test_patches_insert_insert(database: SQLite, package_ahriman: Package) -> None:
|
||||
"""
|
||||
must update patch in database
|
||||
"""
|
||||
database.patches_insert(package_ahriman.base, "patch_1")
|
||||
assert database.patches_get(package_ahriman.base) == "patch_1"
|
||||
database.patches_insert(package_ahriman.base, PkgbuildPatch(None, "patch1"))
|
||||
assert database.patches_get(package_ahriman.base) == [PkgbuildPatch(None, "patch1")]
|
||||
|
||||
database.patches_insert(package_ahriman.base, "patch_2")
|
||||
assert database.patches_get(package_ahriman.base) == "patch_2"
|
||||
database.patches_insert(package_ahriman.base, PkgbuildPatch(None, "patch2"))
|
||||
assert database.patches_get(package_ahriman.base) == [PkgbuildPatch(None, "patch2")]
|
||||
|
@ -1,10 +1,11 @@
|
||||
import pytest
|
||||
|
||||
from ahriman.core.formatters import AurPrinter, ConfigurationPrinter, PackagePrinter, StatusPrinter, StringPrinter, \
|
||||
UpdatePrinter, UserPrinter, VersionPrinter
|
||||
from ahriman.core.formatters import AurPrinter, ConfigurationPrinter, PackagePrinter, PatchPrinter, StatusPrinter, \
|
||||
StringPrinter, UpdatePrinter, UserPrinter, VersionPrinter
|
||||
from ahriman.models.aur_package import AURPackage
|
||||
from ahriman.models.build_status import BuildStatus
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.pkgbuild_patch import PkgbuildPatch
|
||||
from ahriman.models.user import User
|
||||
|
||||
|
||||
@ -47,6 +48,20 @@ def package_ahriman_printer(package_ahriman: Package) -> PackagePrinter:
|
||||
return PackagePrinter(package_ahriman, BuildStatus())
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def patch_printer(package_ahriman: Package) -> PatchPrinter:
|
||||
"""
|
||||
fixture for patch printer
|
||||
|
||||
Args:
|
||||
package_ahriman(Package): package fixture
|
||||
|
||||
Returns:
|
||||
PatchPrinter: patch printer test instance
|
||||
"""
|
||||
return PatchPrinter(package_ahriman.base, [PkgbuildPatch("key", "value")])
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def status_printer() -> StatusPrinter:
|
||||
"""
|
||||
|
22
tests/ahriman/core/formatters/test_patch_printer.py
Normal file
22
tests/ahriman/core/formatters/test_patch_printer.py
Normal file
@ -0,0 +1,22 @@
|
||||
from ahriman.core.formatters import PatchPrinter
|
||||
|
||||
|
||||
def test_properties(patch_printer: PatchPrinter) -> None:
|
||||
"""
|
||||
must return non empty properties list
|
||||
"""
|
||||
assert patch_printer.properties()
|
||||
|
||||
|
||||
def test_properties_required(patch_printer: PatchPrinter) -> None:
|
||||
"""
|
||||
must return all properties as required
|
||||
"""
|
||||
assert all(prop.is_required for prop in patch_printer.properties())
|
||||
|
||||
|
||||
def test_title(patch_printer: PatchPrinter) -> None:
|
||||
"""
|
||||
must return non empty title
|
||||
"""
|
||||
assert patch_printer.title() == "ahriman"
|
@ -72,7 +72,7 @@ def test_process_remove_base(executor: Executor, package_ahriman: Package, mocke
|
||||
# must update status and remove package files
|
||||
tree_clear_mock.assert_called_once_with(package_ahriman.base)
|
||||
build_queue_mock.assert_called_once_with(package_ahriman.base)
|
||||
patches_mock.assert_called_once_with(package_ahriman.base)
|
||||
patches_mock.assert_called_once_with(package_ahriman.base, [])
|
||||
status_client_mock.assert_called_once_with(package_ahriman.base)
|
||||
|
||||
|
||||
|
@ -49,8 +49,7 @@ def test_leaf_load(package_ahriman: Package, repository_paths: RepositoryPaths,
|
||||
leaf = Leaf.load(package_ahriman, repository_paths, database)
|
||||
assert leaf.package == package_ahriman
|
||||
assert leaf.dependencies == {"ahriman-dependency"}
|
||||
load_mock.assert_called_once_with(
|
||||
pytest.helpers.anyvar(int), package_ahriman, None, repository_paths)
|
||||
load_mock.assert_called_once_with(pytest.helpers.anyvar(int), package_ahriman, [], repository_paths)
|
||||
dependencies_mock.assert_called_once_with(pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
|
@ -5,6 +5,15 @@ from unittest.mock import MagicMock, call
|
||||
from ahriman.models.pkgbuild_patch import PkgbuildPatch
|
||||
|
||||
|
||||
def test_post_init() -> None:
|
||||
"""
|
||||
must remove empty keys
|
||||
"""
|
||||
assert PkgbuildPatch("", "value").key is None
|
||||
assert PkgbuildPatch(None, "value").key is None
|
||||
assert PkgbuildPatch("key", "value").key == "key"
|
||||
|
||||
|
||||
def test_is_function() -> None:
|
||||
"""
|
||||
must correctly define key as function
|
||||
@ -13,6 +22,14 @@ def test_is_function() -> None:
|
||||
assert PkgbuildPatch("key()", "value").is_function
|
||||
|
||||
|
||||
def test_is_plain_diff() -> None:
|
||||
"""
|
||||
must correctly define key as function
|
||||
"""
|
||||
assert not PkgbuildPatch("key", "value").is_plain_diff
|
||||
assert PkgbuildPatch(None, "value").is_plain_diff
|
||||
|
||||
|
||||
def test_quote() -> None:
|
||||
"""
|
||||
must quote strings if unsafe flag is not set
|
||||
@ -32,6 +49,13 @@ def test_serialize() -> None:
|
||||
assert PkgbuildPatch("key", "4'2", unsafe=True).serialize() == "key=4'2"
|
||||
|
||||
|
||||
def test_serialize_plain_diff() -> None:
|
||||
"""
|
||||
must correctly serialize function values
|
||||
"""
|
||||
assert PkgbuildPatch(None, "{ value }").serialize() == "{ value }"
|
||||
|
||||
|
||||
def test_serialize_function() -> None:
|
||||
"""
|
||||
must correctly serialize function values
|
||||
|
Reference in New Issue
Block a user