mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-07-31 22:59:55 +00:00
patch control subcommands
This commit is contained in:
123
tests/ahriman/application/handlers/test_handler_patch.py
Normal file
123
tests/ahriman/application/handlers/test_handler_patch.py
Normal file
@ -0,0 +1,123 @@
|
||||
import argparse
|
||||
|
||||
from pathlib import Path
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.application.application import Application
|
||||
from ahriman.application.handlers import Patch
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.models.action import Action
|
||||
from ahriman.models.package import Package
|
||||
|
||||
|
||||
def _default_args(args: argparse.Namespace) -> argparse.Namespace:
|
||||
"""
|
||||
default arguments for these test cases
|
||||
:param args: command line arguments fixture
|
||||
:return: generated arguments for these test cases
|
||||
"""
|
||||
args.package = "ahriman"
|
||||
args.remove = False
|
||||
args.track = ["*.diff", "*.patch"]
|
||||
return args
|
||||
|
||||
|
||||
def test_run(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must run command
|
||||
"""
|
||||
args = _default_args(args)
|
||||
args.action = Action.Update
|
||||
mocker.patch("pathlib.Path.mkdir")
|
||||
application_mock = mocker.patch("ahriman.application.handlers.patch.Patch.patch_set_create")
|
||||
|
||||
Patch.run(args, "x86_64", configuration, True)
|
||||
application_mock.assert_called_once()
|
||||
|
||||
|
||||
def test_run_list(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must run command with list flag
|
||||
"""
|
||||
args = _default_args(args)
|
||||
args.action = Action.List
|
||||
mocker.patch("pathlib.Path.mkdir")
|
||||
application_mock = mocker.patch("ahriman.application.handlers.patch.Patch.patch_set_list")
|
||||
|
||||
Patch.run(args, "x86_64", configuration, True)
|
||||
application_mock.assert_called_once()
|
||||
|
||||
|
||||
def test_run_remove(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must run command with remove flag
|
||||
"""
|
||||
args = _default_args(args)
|
||||
args.action = Action.Remove
|
||||
mocker.patch("pathlib.Path.mkdir")
|
||||
application_mock = mocker.patch("ahriman.application.handlers.patch.Patch.patch_set_remove")
|
||||
|
||||
Patch.run(args, "x86_64", configuration, True)
|
||||
application_mock.assert_called_once()
|
||||
|
||||
|
||||
def test_patch_set_list(application: Application, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must list available patches for the command
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=True)
|
||||
glob_mock = mocker.patch("pathlib.Path.glob", return_value=[Path("local")])
|
||||
print_mock = mocker.patch("ahriman.application.handlers.patch.Patch._print")
|
||||
|
||||
Patch.patch_set_list(application, "ahriman")
|
||||
glob_mock.assert_called_with("*.patch")
|
||||
print_mock.assert_called()
|
||||
|
||||
|
||||
def test_patch_set_list_no_dir(application: Application, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must not fail if no patches directory found
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=False)
|
||||
glob_mock = mocker.patch("pathlib.Path.glob")
|
||||
print_mock = mocker.patch("ahriman.application.handlers.patch.Patch._print")
|
||||
|
||||
Patch.patch_set_list(application, "ahriman")
|
||||
glob_mock.assert_not_called()
|
||||
print_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_patch_set_create(application: Application, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must create patch set for the package
|
||||
"""
|
||||
mocker.patch("ahriman.models.package.Package.load", return_value=package_ahriman)
|
||||
create_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.patch_create")
|
||||
patch_dir = application.repository.paths.patches_for(package_ahriman.base)
|
||||
|
||||
Patch.patch_set_create(application, Path("path"), ["*.patch"])
|
||||
create_mock.assert_called_with(Path("path"), patch_dir / "00-main.patch", "*.patch")
|
||||
|
||||
|
||||
def test_patch_set_create_clear(application: Application, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must clear patches directory before new set creation
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=True)
|
||||
mocker.patch("ahriman.models.package.Package.load", return_value=package_ahriman)
|
||||
mocker.patch("ahriman.core.build_tools.sources.Sources.patch_create")
|
||||
remove_mock = mocker.patch("shutil.rmtree")
|
||||
|
||||
Patch.patch_set_create(application, Path("path"), ["*.patch"])
|
||||
remove_mock.assert_called()
|
||||
|
||||
|
||||
def test_patch_set_remove(application: Application, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must remove patch set for the package
|
||||
"""
|
||||
remove_mock = mocker.patch("shutil.rmtree")
|
||||
patch_dir = application.repository.paths.patches_for(package_ahriman.base)
|
||||
|
||||
Patch.patch_set_remove(application, package_ahriman.base)
|
||||
remove_mock.assert_called_with(patch_dir, ignore_errors=True)
|
@ -4,6 +4,7 @@ from pathlib import Path
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.application.handlers import Handler
|
||||
from ahriman.models.action import Action
|
||||
from ahriman.models.build_status import BuildStatusEnum
|
||||
from ahriman.models.sign_settings import SignSettings
|
||||
from ahriman.models.user_access import UserAccess
|
||||
@ -126,12 +127,77 @@ def test_subparsers_key_import(parser: argparse.ArgumentParser) -> None:
|
||||
|
||||
def test_subparsers_key_import_architecture(parser: argparse.ArgumentParser) -> None:
|
||||
"""
|
||||
check command must correctly parse architecture list
|
||||
key-import command must correctly parse architecture list
|
||||
"""
|
||||
args = parser.parse_args(["-a", "x86_64", "key-import", "key"])
|
||||
assert args.architecture == [""]
|
||||
|
||||
|
||||
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"])
|
||||
assert args.action == Action.Update
|
||||
assert args.architecture == [""]
|
||||
assert args.lock is None
|
||||
assert args.no_report
|
||||
|
||||
|
||||
def test_subparsers_patch_add_architecture(parser: argparse.ArgumentParser) -> None:
|
||||
"""
|
||||
patch-add command must correctly parse architecture list
|
||||
"""
|
||||
args = parser.parse_args(["-a", "x86_64", "patch-add", "ahriman"])
|
||||
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
|
||||
"""
|
||||
args = parser.parse_args(["patch-list", "ahriman"])
|
||||
assert args.action == Action.List
|
||||
assert args.architecture == [""]
|
||||
assert args.lock is None
|
||||
assert args.no_report
|
||||
|
||||
|
||||
def test_subparsers_patch_list_architecture(parser: argparse.ArgumentParser) -> None:
|
||||
"""
|
||||
patch-list command must correctly parse architecture list
|
||||
"""
|
||||
args = parser.parse_args(["-a", "x86_64", "patch-list", "ahriman"])
|
||||
assert args.architecture == [""]
|
||||
|
||||
|
||||
def test_subparsers_patch_remove(parser: argparse.ArgumentParser) -> None:
|
||||
"""
|
||||
patch-remove command must imply action, architecture list, lock and no-report
|
||||
"""
|
||||
args = parser.parse_args(["patch-remove", "ahriman"])
|
||||
assert args.action == Action.Remove
|
||||
assert args.architecture == [""]
|
||||
assert args.lock is None
|
||||
assert args.no_report
|
||||
|
||||
|
||||
def test_subparsers_patch_remove_architecture(parser: argparse.ArgumentParser) -> None:
|
||||
"""
|
||||
patch-remove command must correctly parse architecture list
|
||||
"""
|
||||
args = parser.parse_args(["-a", "x86_64", "patch-remove", "ahriman"])
|
||||
assert args.architecture == [""]
|
||||
|
||||
|
||||
def test_subparsers_rebuild_architecture(parser: argparse.ArgumentParser) -> None:
|
||||
"""
|
||||
rebuild command must correctly parse architecture list
|
||||
|
Reference in New Issue
Block a user