mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-07-21 09:49:55 +00:00
add configurable exit codes to some commands (#55)
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
import argparse
|
||||
import pytest
|
||||
|
||||
from pathlib import Path
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.application.application import Application
|
||||
@ -18,6 +17,7 @@ def _default_args(args: argparse.Namespace) -> argparse.Namespace:
|
||||
:return: generated arguments for these test cases
|
||||
"""
|
||||
args.package = "ahriman"
|
||||
args.exit_code = False
|
||||
args.remove = False
|
||||
args.track = ["*.diff", "*.patch"]
|
||||
return args
|
||||
@ -46,7 +46,7 @@ def test_run_list(args: argparse.Namespace, configuration: Configuration, mocker
|
||||
application_mock = mocker.patch("ahriman.application.handlers.patch.Patch.patch_set_list")
|
||||
|
||||
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, False)
|
||||
|
||||
|
||||
def test_run_remove(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
@ -66,25 +66,25 @@ 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)
|
||||
get_mock = mocker.patch("ahriman.core.database.sqlite.SQLite.patches_list", return_value={"ahriman": "patch"})
|
||||
print_mock = mocker.patch("ahriman.core.formatters.printer.Printer.print")
|
||||
check_mock = mocker.patch("ahriman.application.handlers.handler.Handler.check_if_empty")
|
||||
|
||||
Patch.patch_set_list(application, "ahriman")
|
||||
Patch.patch_set_list(application, "ahriman", False)
|
||||
get_mock.assert_called_once_with("ahriman")
|
||||
print_mock.assert_called_once_with(verbose=True)
|
||||
check_mock.assert_called_once_with(False, False)
|
||||
|
||||
|
||||
def test_patch_set_list_no_patches(application: Application, mocker: MockerFixture) -> None:
|
||||
def test_patch_set_list_empty_exception(application: Application, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must not fail if no patches directory found
|
||||
must raise ExitCode exception on empty patch list
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=False)
|
||||
mocker.patch("ahriman.core.database.sqlite.SQLite.patches_get", return_value=None)
|
||||
print_mock = mocker.patch("ahriman.core.formatters.printer.Printer.print")
|
||||
mocker.patch("ahriman.core.database.sqlite.SQLite.patches_list", return_value={})
|
||||
check_mock = mocker.patch("ahriman.application.handlers.handler.Handler.check_if_empty")
|
||||
|
||||
Patch.patch_set_list(application, "ahriman")
|
||||
print_mock.assert_not_called()
|
||||
Patch.patch_set_list(application, "ahriman", True)
|
||||
check_mock.assert_called_once_with(True, True)
|
||||
|
||||
|
||||
def test_patch_set_create(application: Application, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
|
Reference in New Issue
Block a user