mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-06-28 06:41:43 +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:
@ -2,6 +2,7 @@ from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.application.application import Application
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.result import Result
|
||||
|
||||
|
||||
def test_finalize(application: Application, mocker: MockerFixture) -> None:
|
||||
@ -11,8 +12,8 @@ def test_finalize(application: Application, mocker: MockerFixture) -> None:
|
||||
report_mock = mocker.patch("ahriman.application.application.Application.report")
|
||||
sync_mock = mocker.patch("ahriman.application.application.Application.sync")
|
||||
|
||||
application._finalize([])
|
||||
report_mock.assert_called_once_with([], [])
|
||||
application._finalize(Result())
|
||||
report_mock.assert_called_once_with([], Result())
|
||||
sync_mock.assert_called_once_with([], [])
|
||||
|
||||
|
||||
|
@ -9,6 +9,7 @@ from ahriman.application.application.packages import Packages
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.package_description import PackageDescription
|
||||
from ahriman.models.package_source import PackageSource
|
||||
from ahriman.models.result import Result
|
||||
|
||||
|
||||
def test_finalize(application_packages: Packages) -> None:
|
||||
@ -211,4 +212,4 @@ def test_remove(application_packages: Packages, mocker: MockerFixture) -> None:
|
||||
|
||||
application_packages.remove([])
|
||||
executor_mock.assert_called_once_with([])
|
||||
finalize_mock.assert_called_once_with([])
|
||||
finalize_mock.assert_called_once_with(Result())
|
||||
|
@ -6,6 +6,7 @@ from unittest import mock
|
||||
from ahriman.application.application.repository import Repository
|
||||
from ahriman.core.tree import Leaf, Tree
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.result import Result
|
||||
|
||||
|
||||
def test_finalize(application_repository: Repository) -> None:
|
||||
@ -98,7 +99,7 @@ def test_sign(application_repository: Repository, package_ahriman: Package, pack
|
||||
])
|
||||
update_mock.assert_called_once_with([])
|
||||
sign_repository_mock.assert_called_once_with(application_repository.repository.repo.repo_path)
|
||||
finalize_mock.assert_called_once_with([])
|
||||
finalize_mock.assert_called_once_with(Result())
|
||||
|
||||
|
||||
def test_sign_skip(application_repository: Repository, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
@ -132,7 +133,7 @@ def test_sign_specific(application_repository: Repository, package_ahriman: Pack
|
||||
application_repository.repository.paths.packages / filename.name)
|
||||
update_mock.assert_called_once_with([])
|
||||
sign_repository_mock.assert_called_once_with(application_repository.repository.repo.repo_path)
|
||||
finalize_mock.assert_called_once_with([])
|
||||
finalize_mock.assert_called_once_with(Result())
|
||||
|
||||
|
||||
def test_sync(application_repository: Repository, mocker: MockerFixture) -> None:
|
||||
@ -181,7 +182,8 @@ def test_unknown_no_local(application_repository: Repository, package_ahriman: P
|
||||
assert not application_repository.unknown()
|
||||
|
||||
|
||||
def test_update(application_repository: Repository, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
def test_update(application_repository: Repository, package_ahriman: Package, result: Result,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must process package updates
|
||||
"""
|
||||
@ -189,16 +191,33 @@ def test_update(application_repository: Repository, package_ahriman: Package, mo
|
||||
tree = Tree([Leaf(package_ahriman, set())])
|
||||
|
||||
mocker.patch("ahriman.core.tree.Tree.load", return_value=tree)
|
||||
mocker.patch("ahriman.core.repository.repository.Repository.packages_built", return_value=[])
|
||||
mocker.patch("ahriman.core.repository.repository.Repository.packages_built", return_value=paths)
|
||||
mocker.patch("ahriman.models.package.Package.load", return_value=package_ahriman)
|
||||
build_mock = mocker.patch("ahriman.core.repository.executor.Executor.process_build", return_value=paths)
|
||||
update_mock = mocker.patch("ahriman.core.repository.executor.Executor.process_update")
|
||||
build_mock = mocker.patch("ahriman.core.repository.executor.Executor.process_build", return_value=result)
|
||||
update_mock = mocker.patch("ahriman.core.repository.executor.Executor.process_update", return_value=result)
|
||||
finalize_mock = mocker.patch("ahriman.application.application.repository.Repository._finalize")
|
||||
|
||||
application_repository.update([package_ahriman])
|
||||
build_mock.assert_called_once_with([package_ahriman])
|
||||
update_mock.assert_called_once_with(paths)
|
||||
finalize_mock.assert_called_once_with([package_ahriman])
|
||||
update_mock.assert_has_calls([mock.call(paths), mock.call(paths)])
|
||||
finalize_mock.assert_has_calls([mock.call(result), mock.call(result)])
|
||||
|
||||
|
||||
def test_update_empty(application_repository: Repository, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must skip updating repository if no packages supplied
|
||||
"""
|
||||
paths = [package.filepath for package in package_ahriman.packages.values()]
|
||||
tree = Tree([Leaf(package_ahriman, set())])
|
||||
|
||||
mocker.patch("ahriman.core.tree.Tree.load", return_value=tree)
|
||||
mocker.patch("ahriman.core.repository.repository.Repository.packages_built", return_value=[])
|
||||
mocker.patch("ahriman.models.package.Package.load", return_value=package_ahriman)
|
||||
mocker.patch("ahriman.core.repository.executor.Executor.process_build")
|
||||
update_mock = mocker.patch("ahriman.core.repository.executor.Executor.process_update")
|
||||
|
||||
application_repository.update([package_ahriman])
|
||||
update_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_updates_all(application_repository: Repository, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
|
@ -11,7 +11,7 @@ def test_run(args: argparse.Namespace, configuration: Configuration, mocker: Moc
|
||||
must run command
|
||||
"""
|
||||
mocker.patch("ahriman.models.repository_paths.RepositoryPaths.tree_create")
|
||||
print_mock = mocker.patch("ahriman.application.formatters.printer.Printer.print")
|
||||
print_mock = mocker.patch("ahriman.core.formatters.printer.Printer.print")
|
||||
application_mock = mocker.patch("ahriman.core.configuration.Configuration.dump",
|
||||
return_value=configuration.dump())
|
||||
|
||||
|
@ -45,7 +45,7 @@ def test_run_dry_run(args: argparse.Namespace, configuration: Configuration, pac
|
||||
application_mock = mocker.patch("ahriman.application.application.Application.unknown",
|
||||
return_value=[package_ahriman])
|
||||
remove_mock = mocker.patch("ahriman.application.application.Application.remove")
|
||||
print_mock = mocker.patch("ahriman.application.formatters.printer.Printer.print")
|
||||
print_mock = mocker.patch("ahriman.core.formatters.printer.Printer.print")
|
||||
|
||||
RemoveUnknown.run(args, "x86_64", configuration, True, False)
|
||||
application_mock.assert_called_once_with()
|
||||
@ -65,7 +65,7 @@ def test_run_dry_run_verbose(args: argparse.Namespace, configuration: Configurat
|
||||
application_mock = mocker.patch("ahriman.application.application.Application.unknown",
|
||||
return_value=[package_ahriman])
|
||||
remove_mock = mocker.patch("ahriman.application.application.Application.remove")
|
||||
print_mock = mocker.patch("ahriman.application.formatters.printer.Printer.print")
|
||||
print_mock = mocker.patch("ahriman.core.formatters.printer.Printer.print")
|
||||
|
||||
RemoveUnknown.run(args, "x86_64", configuration, True, False)
|
||||
application_mock.assert_called_once_with()
|
||||
|
@ -4,6 +4,7 @@ from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.application.handlers import Report
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.models.result import Result
|
||||
|
||||
|
||||
def _default_args(args: argparse.Namespace) -> argparse.Namespace:
|
||||
@ -25,4 +26,4 @@ def test_run(args: argparse.Namespace, configuration: Configuration, mocker: Moc
|
||||
application_mock = mocker.patch("ahriman.application.application.Application.report")
|
||||
|
||||
Report.run(args, "x86_64", configuration, True, False)
|
||||
application_mock.assert_called_once_with(args.target, [])
|
||||
application_mock.assert_called_once_with(args.target, Result())
|
||||
|
@ -29,7 +29,7 @@ def test_run(args: argparse.Namespace, configuration: Configuration, aur_package
|
||||
"""
|
||||
args = _default_args(args)
|
||||
search_mock = mocker.patch("ahriman.core.alpm.aur.AUR.multisearch", return_value=[aur_package_ahriman])
|
||||
print_mock = mocker.patch("ahriman.application.formatters.printer.Printer.print")
|
||||
print_mock = mocker.patch("ahriman.core.formatters.printer.Printer.print")
|
||||
|
||||
Search.run(args, "x86_64", configuration, True, False)
|
||||
search_mock.assert_called_once_with("ahriman")
|
||||
|
@ -33,7 +33,7 @@ def test_run(args: argparse.Namespace, configuration: Configuration, package_ahr
|
||||
packages_mock = mocker.patch("ahriman.core.status.client.Client.get",
|
||||
return_value=[(package_ahriman, BuildStatus(BuildStatusEnum.Success)),
|
||||
(package_python_schedule, BuildStatus(BuildStatusEnum.Failed))])
|
||||
print_mock = mocker.patch("ahriman.application.formatters.printer.Printer.print")
|
||||
print_mock = mocker.patch("ahriman.core.formatters.printer.Printer.print")
|
||||
|
||||
Status.run(args, "x86_64", configuration, True, False)
|
||||
application_mock.assert_called_once_with()
|
||||
@ -51,7 +51,7 @@ def test_run_verbose(args: argparse.Namespace, configuration: Configuration, pac
|
||||
mocker.patch("ahriman.models.repository_paths.RepositoryPaths.tree_create")
|
||||
mocker.patch("ahriman.core.status.client.Client.get",
|
||||
return_value=[(package_ahriman, BuildStatus(BuildStatusEnum.Success))])
|
||||
print_mock = mocker.patch("ahriman.application.formatters.printer.Printer.print")
|
||||
print_mock = mocker.patch("ahriman.core.formatters.printer.Printer.print")
|
||||
|
||||
Status.run(args, "x86_64", configuration, True, False)
|
||||
print_mock.assert_has_calls([mock.call(True) for _ in range(2)])
|
||||
@ -83,7 +83,7 @@ def test_run_by_status(args: argparse.Namespace, configuration: Configuration, p
|
||||
return_value=[(package_ahriman, BuildStatus(BuildStatusEnum.Success)),
|
||||
(package_python_schedule, BuildStatus(BuildStatusEnum.Failed))])
|
||||
mocker.patch("ahriman.models.repository_paths.RepositoryPaths.tree_create")
|
||||
print_mock = mocker.patch("ahriman.application.formatters.printer.Printer.print")
|
||||
print_mock = mocker.patch("ahriman.core.formatters.printer.Printer.print")
|
||||
|
||||
Status.run(args, "x86_64", configuration, True, False)
|
||||
print_mock.assert_has_calls([mock.call(False) for _ in range(2)])
|
||||
|
@ -15,7 +15,7 @@ def test_run(args: argparse.Namespace, configuration: Configuration, mocker: Moc
|
||||
args.parser = _parser
|
||||
commands_mock = mocker.patch("ahriman.application.handlers.UnsafeCommands.get_unsafe_commands",
|
||||
return_value=["command"])
|
||||
print_mock = mocker.patch("ahriman.application.formatters.printer.Printer.print")
|
||||
print_mock = mocker.patch("ahriman.core.formatters.printer.Printer.print")
|
||||
|
||||
UnsafeCommands.run(args, "x86_64", configuration, True, False)
|
||||
commands_mock.assert_called_once_with(pytest.helpers.anyvar(int))
|
||||
|
@ -14,6 +14,7 @@ from ahriman.models.aur_package import AURPackage
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.package_description import PackageDescription
|
||||
from ahriman.models.repository_paths import RepositoryPaths
|
||||
from ahriman.models.result import Result
|
||||
from ahriman.models.user import User
|
||||
from ahriman.models.user_access import UserAccess
|
||||
|
||||
@ -234,6 +235,18 @@ def repository_paths(configuration: Configuration) -> RepositoryPaths:
|
||||
root=configuration.getpath("repository", "root"))
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def result(package_ahriman: Package) -> Result:
|
||||
"""
|
||||
result fixture
|
||||
:param package_ahriman: package fixture
|
||||
:return: result test instance
|
||||
"""
|
||||
result = Result()
|
||||
result.add_success(package_ahriman)
|
||||
return result
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def spawner(configuration: Configuration) -> Spawn:
|
||||
"""
|
||||
|
@ -1,11 +1,11 @@
|
||||
import pytest
|
||||
|
||||
from ahriman.application.formatters.aur_printer import AurPrinter
|
||||
from ahriman.application.formatters.configuration_printer import ConfigurationPrinter
|
||||
from ahriman.application.formatters.package_printer import PackagePrinter
|
||||
from ahriman.application.formatters.status_printer import StatusPrinter
|
||||
from ahriman.application.formatters.string_printer import StringPrinter
|
||||
from ahriman.application.formatters.update_printer import UpdatePrinter
|
||||
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
|
@ -1,4 +1,4 @@
|
||||
from ahriman.application.formatters.aur_printer import AurPrinter
|
||||
from ahriman.core.formatters.aur_printer import AurPrinter
|
||||
|
||||
|
||||
def test_properties(aur_package_ahriman_printer: AurPrinter) -> 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
|
@ -1,4 +1,4 @@
|
||||
from ahriman.application.formatters.configuration_printer import ConfigurationPrinter
|
||||
from ahriman.core.formatters.configuration_printer import ConfigurationPrinter
|
||||
|
||||
|
||||
def test_properties(configuration_printer: ConfigurationPrinter) -> None:
|
@ -1,4 +1,4 @@
|
||||
from ahriman.application.formatters.package_printer import PackagePrinter
|
||||
from ahriman.core.formatters.package_printer import PackagePrinter
|
||||
|
||||
|
||||
def test_properties(package_ahriman_printer: PackagePrinter) -> None:
|
@ -1,7 +1,7 @@
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from ahriman.application.formatters.package_printer import PackagePrinter
|
||||
from ahriman.application.formatters.printer import Printer
|
||||
from ahriman.core.formatters.package_printer import PackagePrinter
|
||||
from ahriman.core.formatters.printer import Printer
|
||||
|
||||
|
||||
def test_print(package_ahriman_printer: PackagePrinter) -> None:
|
@ -1,4 +1,4 @@
|
||||
from ahriman.application.formatters.status_printer import StatusPrinter
|
||||
from ahriman.core.formatters.status_printer import StatusPrinter
|
||||
|
||||
|
||||
def test_properties(status_printer: StatusPrinter) -> None:
|
@ -1,4 +1,4 @@
|
||||
from ahriman.application.formatters.string_printer import StringPrinter
|
||||
from ahriman.core.formatters.string_printer import StringPrinter
|
||||
|
||||
|
||||
def test_properties(string_printer: StringPrinter) -> None:
|
@ -1,4 +1,4 @@
|
||||
from ahriman.application.formatters.update_printer import UpdatePrinter
|
||||
from ahriman.core.formatters.update_printer import UpdatePrinter
|
||||
|
||||
|
||||
def test_properties(update_printer: UpdatePrinter) -> None:
|
20
tests/ahriman/core/report/test_console.py
Normal file
20
tests/ahriman/core/report/test_console.py
Normal file
@ -0,0 +1,20 @@
|
||||
from pytest_mock import MockerFixture
|
||||
from unittest import mock
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.report.console import Console
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.result import Result
|
||||
|
||||
|
||||
def test_generate(configuration: Configuration, result: Result, package_python_schedule: Package,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must print result to stdout
|
||||
"""
|
||||
print_mock = mocker.patch("ahriman.core.formatters.printer.Printer.print")
|
||||
result.add_failed(package_python_schedule)
|
||||
report = Console("x86_64", configuration, "console")
|
||||
|
||||
report.generate([], result)
|
||||
print_mock.assert_has_calls([mock.call(verbose=True), mock.call(verbose=True)])
|
@ -5,6 +5,7 @@ from pytest_mock import MockerFixture
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.report.email import Email
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.result import Result
|
||||
|
||||
|
||||
def test_send(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
@ -92,24 +93,26 @@ def test_generate(configuration: Configuration, package_ahriman: Package, mocker
|
||||
send_mock = mocker.patch("ahriman.core.report.email.Email._send")
|
||||
|
||||
report = Email("x86_64", configuration, "email")
|
||||
report.generate([package_ahriman], [])
|
||||
report.generate([package_ahriman], Result())
|
||||
send_mock.assert_called_once_with(pytest.helpers.anyvar(int), {})
|
||||
|
||||
|
||||
def test_generate_with_built(configuration: Configuration, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
def test_generate_with_built(configuration: Configuration, package_ahriman: Package, result: Result,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must generate report with built packages
|
||||
"""
|
||||
send_mock = mocker.patch("ahriman.core.report.email.Email._send")
|
||||
|
||||
report = Email("x86_64", configuration, "email")
|
||||
report.generate([package_ahriman], [package_ahriman])
|
||||
report.generate([package_ahriman], result)
|
||||
send_mock.assert_called_once_with(pytest.helpers.anyvar(int), {})
|
||||
|
||||
|
||||
def test_generate_with_built_and_full_path(
|
||||
configuration: Configuration,
|
||||
package_ahriman: Package,
|
||||
result: Result,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must generate report with built packages
|
||||
@ -118,7 +121,7 @@ def test_generate_with_built_and_full_path(
|
||||
|
||||
report = Email("x86_64", configuration, "email")
|
||||
report.full_template_path = report.template_path
|
||||
report.generate([package_ahriman], [package_ahriman])
|
||||
report.generate([package_ahriman], result)
|
||||
send_mock.assert_called_once_with(pytest.helpers.anyvar(int), pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
@ -130,11 +133,11 @@ def test_generate_no_empty(configuration: Configuration, package_ahriman: Packag
|
||||
send_mock = mocker.patch("ahriman.core.report.email.Email._send")
|
||||
|
||||
report = Email("x86_64", configuration, "email")
|
||||
report.generate([package_ahriman], [])
|
||||
report.generate([package_ahriman], Result())
|
||||
send_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_generate_no_empty_with_built(configuration: Configuration, package_ahriman: Package,
|
||||
def test_generate_no_empty_with_built(configuration: Configuration, package_ahriman: Package, result: Result,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must generate report with built packages if no_empty_report is set
|
||||
@ -143,5 +146,5 @@ def test_generate_no_empty_with_built(configuration: Configuration, package_ahri
|
||||
send_mock = mocker.patch("ahriman.core.report.email.Email._send")
|
||||
|
||||
report = Email("x86_64", configuration, "email")
|
||||
report.generate([package_ahriman], [package_ahriman])
|
||||
report.generate([package_ahriman], result)
|
||||
send_mock.assert_called_once_with(pytest.helpers.anyvar(int), {})
|
||||
|
@ -1,6 +1,7 @@
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.report.jinja_template import JinjaTemplate
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.result import Result
|
||||
|
||||
|
||||
def test_generate(configuration: Configuration, package_ahriman: Package) -> None:
|
||||
@ -9,4 +10,4 @@ def test_generate(configuration: Configuration, package_ahriman: Package) -> Non
|
||||
"""
|
||||
path = configuration.getpath("html", "template_path")
|
||||
report = JinjaTemplate("html", configuration)
|
||||
assert report.make_html([package_ahriman], path)
|
||||
assert report.make_html(Result(success=[package_ahriman]), path)
|
||||
|
@ -6,6 +6,7 @@ from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.exceptions import ReportFailed
|
||||
from ahriman.core.report.report import Report
|
||||
from ahriman.models.report_settings import ReportSettings
|
||||
from ahriman.models.result import Result
|
||||
|
||||
|
||||
def test_report_failure(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
@ -14,32 +15,41 @@ def test_report_failure(configuration: Configuration, mocker: MockerFixture) ->
|
||||
"""
|
||||
mocker.patch("ahriman.core.report.html.HTML.generate", side_effect=Exception())
|
||||
with pytest.raises(ReportFailed):
|
||||
Report.load("x86_64", configuration, "html").run([], [])
|
||||
Report.load("x86_64", configuration, "html").run([], Result())
|
||||
|
||||
|
||||
def test_report_dummy(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
def test_report_dummy(configuration: Configuration, result: Result, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must construct dummy report class
|
||||
"""
|
||||
mocker.patch("ahriman.models.report_settings.ReportSettings.from_option", return_value=ReportSettings.Disabled)
|
||||
report_mock = mocker.patch("ahriman.core.report.report.Report.generate")
|
||||
Report.load("x86_64", configuration, "disabled").run([], [])
|
||||
report_mock.assert_called_once_with([], [])
|
||||
Report.load("x86_64", configuration, "disabled").run([], result)
|
||||
report_mock.assert_called_once_with([], result)
|
||||
|
||||
|
||||
def test_report_email(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
def test_report_console(configuration: Configuration, result: Result, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must generate console report
|
||||
"""
|
||||
report_mock = mocker.patch("ahriman.core.report.console.Console.generate")
|
||||
Report.load("x86_64", configuration, "console").run([], result)
|
||||
report_mock.assert_called_once_with([], result)
|
||||
|
||||
|
||||
def test_report_email(configuration: Configuration, result: Result, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must generate email report
|
||||
"""
|
||||
report_mock = mocker.patch("ahriman.core.report.email.Email.generate")
|
||||
Report.load("x86_64", configuration, "email").run([], [])
|
||||
report_mock.assert_called_once_with([], [])
|
||||
Report.load("x86_64", configuration, "email").run([], result)
|
||||
report_mock.assert_called_once_with([], result)
|
||||
|
||||
|
||||
def test_report_html(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
def test_report_html(configuration: Configuration, result: Result, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must generate html report
|
||||
"""
|
||||
report_mock = mocker.patch("ahriman.core.report.html.HTML.generate")
|
||||
Report.load("x86_64", configuration, "html").run([], [])
|
||||
report_mock.assert_called_once_with([], [])
|
||||
Report.load("x86_64", configuration, "html").run([], result)
|
||||
report_mock.assert_called_once_with([], result)
|
||||
|
@ -35,7 +35,6 @@ def test_process_build(executor: Executor, package_ahriman: Package, mocker: Moc
|
||||
mocker.patch("ahriman.core.build_tools.task.Task.init")
|
||||
move_mock = mocker.patch("shutil.move")
|
||||
status_client_mock = mocker.patch("ahriman.core.status.client.Client.set_building")
|
||||
built_packages_mock = mocker.patch("ahriman.core.repository.executor.Executor.packages_built")
|
||||
|
||||
executor.process_build([package_ahriman])
|
||||
# must move files (once)
|
||||
@ -45,8 +44,6 @@ def test_process_build(executor: Executor, package_ahriman: Package, mocker: Moc
|
||||
# must clear directory
|
||||
from ahriman.core.repository.cleaner import Cleaner
|
||||
Cleaner.clear_build.assert_called_once_with()
|
||||
# must return build packages after all
|
||||
built_packages_mock.assert_called_once_with()
|
||||
|
||||
|
||||
def test_process_build_failure(executor: Executor, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
|
@ -21,3 +21,6 @@ def test_from_option_valid() -> None:
|
||||
|
||||
assert ReportSettings.from_option("email") == ReportSettings.Email
|
||||
assert ReportSettings.from_option("EmAil") == ReportSettings.Email
|
||||
|
||||
assert ReportSettings.from_option("console") == ReportSettings.Console
|
||||
assert ReportSettings.from_option("conSOle") == ReportSettings.Console
|
||||
|
119
tests/ahriman/models/test_result.py
Normal file
119
tests/ahriman/models/test_result.py
Normal file
@ -0,0 +1,119 @@
|
||||
import pytest
|
||||
|
||||
from ahriman.core.exceptions import SuccessFailed
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.result import Result
|
||||
|
||||
|
||||
def test_add_failed(package_ahriman: Package) -> None:
|
||||
"""
|
||||
must add package to failed list
|
||||
"""
|
||||
result = Result()
|
||||
result.add_failed(package_ahriman)
|
||||
assert result.failed == [package_ahriman]
|
||||
assert not result.success
|
||||
|
||||
|
||||
def test_add_success(package_ahriman: Package) -> None:
|
||||
"""
|
||||
must add package to success list
|
||||
"""
|
||||
result = Result()
|
||||
result.add_success(package_ahriman)
|
||||
assert result.success == [package_ahriman]
|
||||
assert not result.failed
|
||||
|
||||
|
||||
def test_merge(package_ahriman: Package, package_python_schedule: Package) -> None:
|
||||
"""
|
||||
must merge success packages
|
||||
"""
|
||||
left = Result()
|
||||
left.add_success(package_ahriman)
|
||||
right = Result()
|
||||
right.add_success(package_python_schedule)
|
||||
|
||||
result = left.merge(right)
|
||||
assert result.success == [package_ahriman, package_python_schedule]
|
||||
assert not left.failed
|
||||
|
||||
|
||||
def test_merge_failed(package_ahriman: Package) -> None:
|
||||
"""
|
||||
must merge and remove failed packages from success list
|
||||
"""
|
||||
left = Result()
|
||||
left.add_success(package_ahriman)
|
||||
right = Result()
|
||||
right.add_failed(package_ahriman)
|
||||
|
||||
result = left.merge(right)
|
||||
assert result.failed == [package_ahriman]
|
||||
assert not left.success
|
||||
|
||||
|
||||
def test_merge_exception(package_ahriman: Package) -> None:
|
||||
"""
|
||||
must raise exception in case if package was failed
|
||||
"""
|
||||
left = Result()
|
||||
left.add_failed(package_ahriman)
|
||||
right = Result()
|
||||
right.add_success(package_ahriman)
|
||||
|
||||
with pytest.raises(SuccessFailed):
|
||||
left.merge(right)
|
||||
|
||||
|
||||
def test_eq(package_ahriman: Package, package_python_schedule: Package) -> None:
|
||||
"""
|
||||
must return True for same objects
|
||||
"""
|
||||
left = Result()
|
||||
left.add_success(package_ahriman)
|
||||
left.add_failed(package_python_schedule)
|
||||
right = Result()
|
||||
right.add_success(package_ahriman)
|
||||
right.add_failed(package_python_schedule)
|
||||
|
||||
assert left == right
|
||||
|
||||
|
||||
def test_eq_false(package_ahriman: Package) -> None:
|
||||
"""
|
||||
must return False in case if lists do not match
|
||||
"""
|
||||
left = Result()
|
||||
left.add_success(package_ahriman)
|
||||
right = Result()
|
||||
right.add_failed(package_ahriman)
|
||||
|
||||
assert left != right
|
||||
|
||||
|
||||
def test_eq_false_failed(package_ahriman: Package) -> None:
|
||||
"""
|
||||
must return False in case if failed does not match
|
||||
"""
|
||||
left = Result()
|
||||
left.add_failed(package_ahriman)
|
||||
|
||||
assert left != Result()
|
||||
|
||||
|
||||
def test_eq_false_success(package_ahriman: Package) -> None:
|
||||
"""
|
||||
must return False in case if success does not match
|
||||
"""
|
||||
left = Result()
|
||||
left.add_success(package_ahriman)
|
||||
|
||||
assert left != Result()
|
||||
|
||||
|
||||
def test_eq_other() -> None:
|
||||
"""
|
||||
must return False in case if object is not an instance of result
|
||||
"""
|
||||
assert Result() != 42
|
@ -42,6 +42,9 @@ receivers = mail@example.com
|
||||
sender = mail@example.com
|
||||
template_path = ../web/templates/repo-index.jinja2
|
||||
|
||||
[console]
|
||||
use_utf = yes
|
||||
|
||||
[html]
|
||||
path =
|
||||
homepage =
|
||||
|
Reference in New Issue
Block a user