mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-07-31 06:39:56 +00:00
add console printer
also add python-requests as explicit dependency and escape symbols in repository name for badges in default tempate
This commit is contained in:
67
tests/ahriman/core/formatters/conftest.py
Normal file
67
tests/ahriman/core/formatters/conftest.py
Normal file
@ -0,0 +1,67 @@
|
||||
import pytest
|
||||
|
||||
from ahriman.core.formatters.aur_printer import AurPrinter
|
||||
from ahriman.core.formatters.configuration_printer import ConfigurationPrinter
|
||||
from ahriman.core.formatters.package_printer import PackagePrinter
|
||||
from ahriman.core.formatters.status_printer import StatusPrinter
|
||||
from ahriman.core.formatters.string_printer import StringPrinter
|
||||
from ahriman.core.formatters.update_printer import UpdatePrinter
|
||||
from ahriman.models.aur_package import AURPackage
|
||||
from ahriman.models.build_status import BuildStatus
|
||||
from ahriman.models.package import Package
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def aur_package_ahriman_printer(aur_package_ahriman: AURPackage) -> AurPrinter:
|
||||
"""
|
||||
fixture for AUR package printer
|
||||
:param aur_package_ahriman: AUR package fixture
|
||||
:return: AUR package printer test instance
|
||||
"""
|
||||
return AurPrinter(aur_package_ahriman)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def configuration_printer() -> ConfigurationPrinter:
|
||||
"""
|
||||
fixture for configuration printer
|
||||
:return: configuration printer test instance
|
||||
"""
|
||||
return ConfigurationPrinter("section", {"key_one": "value_one", "key_two": "value_two"})
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def package_ahriman_printer(package_ahriman: Package) -> PackagePrinter:
|
||||
"""
|
||||
fixture for package printer
|
||||
:param package_ahriman: package fixture
|
||||
:return: package printer test instance
|
||||
"""
|
||||
return PackagePrinter(package_ahriman, BuildStatus())
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def status_printer() -> StatusPrinter:
|
||||
"""
|
||||
fixture for build status printer
|
||||
:return: build status printer test instance
|
||||
"""
|
||||
return StatusPrinter(BuildStatus())
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def string_printer() -> StringPrinter:
|
||||
"""
|
||||
fixture for any string printer
|
||||
:return: any string printer test instance
|
||||
"""
|
||||
return StringPrinter("hello, world")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def update_printer(package_ahriman: Package) -> UpdatePrinter:
|
||||
"""
|
||||
fixture for build status printer
|
||||
:return: build status printer test instance
|
||||
"""
|
||||
return UpdatePrinter(package_ahriman, None)
|
15
tests/ahriman/core/formatters/test_aur_printer.py
Normal file
15
tests/ahriman/core/formatters/test_aur_printer.py
Normal file
@ -0,0 +1,15 @@
|
||||
from ahriman.core.formatters.aur_printer import AurPrinter
|
||||
|
||||
|
||||
def test_properties(aur_package_ahriman_printer: AurPrinter) -> None:
|
||||
"""
|
||||
must return non empty properties list
|
||||
"""
|
||||
assert aur_package_ahriman_printer.properties()
|
||||
|
||||
|
||||
def test_title(aur_package_ahriman_printer: AurPrinter) -> None:
|
||||
"""
|
||||
must return non empty title
|
||||
"""
|
||||
assert aur_package_ahriman_printer.title() is not None
|
36
tests/ahriman/core/formatters/test_build_printer.py
Normal file
36
tests/ahriman/core/formatters/test_build_printer.py
Normal file
@ -0,0 +1,36 @@
|
||||
import pytest
|
||||
|
||||
from ahriman.core.formatters.build_printer import BuildPrinter
|
||||
from ahriman.models.package import Package
|
||||
|
||||
|
||||
def test_properties(package_ahriman: Package) -> None:
|
||||
"""
|
||||
must return empty properties list
|
||||
"""
|
||||
assert not BuildPrinter(package_ahriman, is_success=True, use_utf=False).properties()
|
||||
|
||||
|
||||
def test_sign_ascii(package_ahriman: Package) -> None:
|
||||
"""
|
||||
must correctly generate sign in ascii
|
||||
"""
|
||||
BuildPrinter(package_ahriman, is_success=True, use_utf=False).title().encode("ascii")
|
||||
BuildPrinter(package_ahriman, is_success=False, use_utf=False).title().encode("ascii")
|
||||
|
||||
|
||||
def test_sign_utf8(package_ahriman: Package) -> None:
|
||||
"""
|
||||
must correctly generate sign in ascii
|
||||
"""
|
||||
with pytest.raises(UnicodeEncodeError):
|
||||
BuildPrinter(package_ahriman, is_success=True, use_utf=True).title().encode("ascii")
|
||||
with pytest.raises(UnicodeEncodeError):
|
||||
BuildPrinter(package_ahriman, is_success=False, use_utf=True).title().encode("ascii")
|
||||
|
||||
|
||||
def test_title(package_ahriman: Package) -> None:
|
||||
"""
|
||||
must return non empty title
|
||||
"""
|
||||
assert BuildPrinter(package_ahriman, is_success=True, use_utf=False).title() is not None
|
22
tests/ahriman/core/formatters/test_configuration_printer.py
Normal file
22
tests/ahriman/core/formatters/test_configuration_printer.py
Normal file
@ -0,0 +1,22 @@
|
||||
from ahriman.core.formatters.configuration_printer import ConfigurationPrinter
|
||||
|
||||
|
||||
def test_properties(configuration_printer: ConfigurationPrinter) -> None:
|
||||
"""
|
||||
must return non empty properties list
|
||||
"""
|
||||
assert configuration_printer.properties()
|
||||
|
||||
|
||||
def test_properties_required(configuration_printer: ConfigurationPrinter) -> None:
|
||||
"""
|
||||
must return all properties as required
|
||||
"""
|
||||
assert all(prop.is_required for prop in configuration_printer.properties())
|
||||
|
||||
|
||||
def test_title(configuration_printer: ConfigurationPrinter) -> None:
|
||||
"""
|
||||
must return non empty title
|
||||
"""
|
||||
assert configuration_printer.title() == "[section]"
|
15
tests/ahriman/core/formatters/test_package_printer.py
Normal file
15
tests/ahriman/core/formatters/test_package_printer.py
Normal file
@ -0,0 +1,15 @@
|
||||
from ahriman.core.formatters.package_printer import PackagePrinter
|
||||
|
||||
|
||||
def test_properties(package_ahriman_printer: PackagePrinter) -> None:
|
||||
"""
|
||||
must return non empty properties list
|
||||
"""
|
||||
assert package_ahriman_printer.properties()
|
||||
|
||||
|
||||
def test_title(package_ahriman_printer: PackagePrinter) -> None:
|
||||
"""
|
||||
must return non empty title
|
||||
"""
|
||||
assert package_ahriman_printer.title() is not None
|
45
tests/ahriman/core/formatters/test_printer.py
Normal file
45
tests/ahriman/core/formatters/test_printer.py
Normal file
@ -0,0 +1,45 @@
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from ahriman.core.formatters.package_printer import PackagePrinter
|
||||
from ahriman.core.formatters.printer import Printer
|
||||
|
||||
|
||||
def test_print(package_ahriman_printer: PackagePrinter) -> None:
|
||||
"""
|
||||
must print content
|
||||
"""
|
||||
log_mock = MagicMock()
|
||||
package_ahriman_printer.print(verbose=False, log_fn=log_mock)
|
||||
log_mock.assert_called()
|
||||
|
||||
|
||||
def test_print_empty() -> None:
|
||||
"""
|
||||
must not print empty object
|
||||
"""
|
||||
log_mock = MagicMock()
|
||||
Printer().print(verbose=True, log_fn=log_mock)
|
||||
log_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_print_verbose(package_ahriman_printer: PackagePrinter) -> None:
|
||||
"""
|
||||
must print content with increased verbosity
|
||||
"""
|
||||
log_mock = MagicMock()
|
||||
package_ahriman_printer.print(verbose=True, log_fn=log_mock)
|
||||
log_mock.assert_called()
|
||||
|
||||
|
||||
def test_properties() -> None:
|
||||
"""
|
||||
must return empty properties list
|
||||
"""
|
||||
assert Printer().properties() == []
|
||||
|
||||
|
||||
def test_title() -> None:
|
||||
"""
|
||||
must return empty title
|
||||
"""
|
||||
assert Printer().title() is None
|
15
tests/ahriman/core/formatters/test_status_printer.py
Normal file
15
tests/ahriman/core/formatters/test_status_printer.py
Normal file
@ -0,0 +1,15 @@
|
||||
from ahriman.core.formatters.status_printer import StatusPrinter
|
||||
|
||||
|
||||
def test_properties(status_printer: StatusPrinter) -> None:
|
||||
"""
|
||||
must return empty properties list
|
||||
"""
|
||||
assert not status_printer.properties()
|
||||
|
||||
|
||||
def test_title(status_printer: StatusPrinter) -> None:
|
||||
"""
|
||||
must return non empty title
|
||||
"""
|
||||
assert status_printer.title() is not None
|
15
tests/ahriman/core/formatters/test_string_printer.py
Normal file
15
tests/ahriman/core/formatters/test_string_printer.py
Normal file
@ -0,0 +1,15 @@
|
||||
from ahriman.core.formatters.string_printer import StringPrinter
|
||||
|
||||
|
||||
def test_properties(string_printer: StringPrinter) -> None:
|
||||
"""
|
||||
must return empty properties list
|
||||
"""
|
||||
assert not string_printer.properties()
|
||||
|
||||
|
||||
def test_title(string_printer: StringPrinter) -> None:
|
||||
"""
|
||||
must return non empty title
|
||||
"""
|
||||
assert string_printer.title() is not None
|
15
tests/ahriman/core/formatters/test_update_printer.py
Normal file
15
tests/ahriman/core/formatters/test_update_printer.py
Normal file
@ -0,0 +1,15 @@
|
||||
from ahriman.core.formatters.update_printer import UpdatePrinter
|
||||
|
||||
|
||||
def test_properties(update_printer: UpdatePrinter) -> None:
|
||||
"""
|
||||
must return empty properties list
|
||||
"""
|
||||
assert update_printer.properties()
|
||||
|
||||
|
||||
def test_title(update_printer: UpdatePrinter) -> None:
|
||||
"""
|
||||
must return non empty title
|
||||
"""
|
||||
assert update_printer.title() is not None
|
Reference in New Issue
Block a user