mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-07-31 22:59:55 +00:00
add config validator subcommand (#80)
* add config validator subcommand * add --exit-code flag * docs & faq update
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
|
||||
from ahriman.core.formatters import AurPrinter, ConfigurationPrinter, PackagePrinter, PatchPrinter, StatusPrinter, \
|
||||
StringPrinter, TreePrinter, UpdatePrinter, UserPrinter, VersionPrinter
|
||||
StringPrinter, TreePrinter, UpdatePrinter, UserPrinter, ValidationPrinter, VersionPrinter
|
||||
from ahriman.models.aur_package import AURPackage
|
||||
from ahriman.models.build_status import BuildStatus
|
||||
from ahriman.models.package import Package
|
||||
@ -126,6 +126,29 @@ def user_printer(user: User) -> UserPrinter:
|
||||
return UserPrinter(user)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def validation_printer() -> ValidationPrinter:
|
||||
"""
|
||||
fixture for validation printer
|
||||
|
||||
Returns:
|
||||
ValidationPrinter: validation printer test instance
|
||||
"""
|
||||
return ValidationPrinter("root", [
|
||||
"root error",
|
||||
{
|
||||
"child": [
|
||||
"child error",
|
||||
{
|
||||
"grandchild": [
|
||||
"grandchild error",
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
])
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def version_printer(package_ahriman: Package) -> VersionPrinter:
|
||||
"""
|
||||
|
@ -1,7 +1,9 @@
|
||||
from unittest.mock import MagicMock
|
||||
from pytest_mock import MockerFixture
|
||||
from unittest.mock import MagicMock, call as MockCall
|
||||
|
||||
from ahriman.core.formatters import PackagePrinter
|
||||
from ahriman.core.formatters import Printer
|
||||
from ahriman.models.property import Property
|
||||
|
||||
|
||||
def test_print(package_ahriman_printer: PackagePrinter) -> None:
|
||||
@ -31,6 +33,24 @@ def test_print_verbose(package_ahriman_printer: PackagePrinter) -> None:
|
||||
log_mock.assert_called()
|
||||
|
||||
|
||||
def test_print_indent(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must correctly use indentation
|
||||
"""
|
||||
log_mock = MagicMock()
|
||||
|
||||
mocker.patch("ahriman.core.formatters.Printer.properties", return_value=[Property("key", "value", indent=0)])
|
||||
Printer().print(verbose=True, log_fn=log_mock)
|
||||
|
||||
mocker.patch("ahriman.core.formatters.Printer.properties", return_value=[Property("key", "value", indent=1)])
|
||||
Printer().print(verbose=True, log_fn=log_mock)
|
||||
|
||||
mocker.patch("ahriman.core.formatters.Printer.properties", return_value=[Property("key", "value", indent=2)])
|
||||
Printer().print(verbose=True, log_fn=log_mock)
|
||||
|
||||
log_mock.assert_has_calls([MockCall("key: value"), MockCall("\tkey: value"), MockCall("\t\tkey: value")])
|
||||
|
||||
|
||||
def test_properties() -> None:
|
||||
"""
|
||||
must return empty properties list
|
||||
|
28
tests/ahriman/core/formatters/test_validation_printer.py
Normal file
28
tests/ahriman/core/formatters/test_validation_printer.py
Normal file
@ -0,0 +1,28 @@
|
||||
from ahriman.core.formatters import ValidationPrinter
|
||||
from ahriman.models.property import Property
|
||||
|
||||
|
||||
def test_properties(validation_printer: ValidationPrinter) -> None:
|
||||
"""
|
||||
must return non-empty properties list
|
||||
"""
|
||||
assert validation_printer.properties()
|
||||
|
||||
|
||||
def test_title(validation_printer: ValidationPrinter) -> None:
|
||||
"""
|
||||
must return non-empty title
|
||||
"""
|
||||
assert validation_printer.title() is not None
|
||||
|
||||
|
||||
def test_get_error_messages(validation_printer: ValidationPrinter) -> None:
|
||||
"""
|
||||
must get error messages from plain list
|
||||
"""
|
||||
result = ValidationPrinter.get_error_messages(validation_printer.node, validation_printer.errors)
|
||||
assert list(result) == [
|
||||
Property("root", "root error", is_required=True, indent=1),
|
||||
Property("child", "child error", is_required=True, indent=2),
|
||||
Property("grandchild", "grandchild error", is_required=True, indent=3),
|
||||
]
|
Reference in New Issue
Block a user