mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-08-29 04:49:57 +00:00
100% coverage
This commit is contained in:
@ -1,8 +1,10 @@
|
||||
import argparse
|
||||
import pytest
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.application.handlers import Handler
|
||||
from ahriman.core.configuration import Configuration
|
||||
|
||||
|
||||
def test_call(args: argparse.Namespace, mocker: MockerFixture) -> None:
|
||||
@ -27,3 +29,22 @@ def test_call_exception(args: argparse.Namespace, mocker: MockerFixture) -> None
|
||||
"""
|
||||
mocker.patch("ahriman.application.lock.Lock.__enter__", side_effect=Exception())
|
||||
assert not Handler._call(args, "x86_64")
|
||||
|
||||
|
||||
def test_execute(args: argparse.Namespace, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must run execution in multiple processes
|
||||
"""
|
||||
args.architecture = ["i686", "x86_64"]
|
||||
starmap_mock = mocker.patch("multiprocessing.pool.Pool.starmap")
|
||||
|
||||
Handler.execute(args)
|
||||
starmap_mock.assert_called_once()
|
||||
|
||||
|
||||
def test_packages(args: argparse.Namespace, configuration: Configuration) -> None:
|
||||
"""
|
||||
must raise NotImplemented for missing method
|
||||
"""
|
||||
with pytest.raises(NotImplementedError):
|
||||
Handler.run(args, "x86_64", configuration)
|
||||
|
@ -4,6 +4,8 @@ from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.application.handlers import Status
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.models.build_status import BuildStatus
|
||||
from ahriman.models.package import Package
|
||||
|
||||
|
||||
def _default_args(args: argparse.Namespace) -> argparse.Namespace:
|
||||
@ -12,15 +14,33 @@ def _default_args(args: argparse.Namespace) -> argparse.Namespace:
|
||||
return args
|
||||
|
||||
|
||||
def test_run(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
def test_run(args: argparse.Namespace, configuration: Configuration, package_ahriman: Package,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must run command
|
||||
"""
|
||||
args = _default_args(args)
|
||||
mocker.patch("pathlib.Path.mkdir")
|
||||
application_mock = mocker.patch("ahriman.core.status.client.Client.get_self")
|
||||
packages_mock = mocker.patch("ahriman.core.status.client.Client.get")
|
||||
packages_mock = mocker.patch("ahriman.core.status.client.Client.get",
|
||||
return_value=[(package_ahriman, BuildStatus())])
|
||||
|
||||
Status.run(args, "x86_64", configuration)
|
||||
application_mock.assert_called_once()
|
||||
packages_mock.assert_called_once()
|
||||
|
||||
|
||||
def test_run_with_package_filter(args: argparse.Namespace, configuration: Configuration, package_ahriman: Package,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must run command
|
||||
"""
|
||||
args = _default_args(args)
|
||||
args.package = [package_ahriman.base]
|
||||
mocker.patch("pathlib.Path.mkdir")
|
||||
packages_mock = mocker.patch("ahriman.core.status.client.Client.get",
|
||||
return_value=[(package_ahriman, BuildStatus())])
|
||||
|
||||
Status.run(args, "x86_64", configuration)
|
||||
packages_mock.assert_called_once()
|
||||
|
||||
|
@ -2,6 +2,7 @@ import argparse
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.application.application import Application
|
||||
from ahriman.application.handlers import Update
|
||||
from ahriman.core.configuration import Configuration
|
||||
|
||||
@ -40,3 +41,12 @@ def test_run_dry_run(args: argparse.Namespace, configuration: Configuration, moc
|
||||
|
||||
Update.run(args, "x86_64", configuration)
|
||||
updates_mock.assert_called_once()
|
||||
|
||||
|
||||
def test_log_fn(application: Application, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must print package updates
|
||||
"""
|
||||
logger_mock = mocker.patch("logging.Logger.info")
|
||||
Update.log_fn(application, False)("hello")
|
||||
logger_mock.assert_called_once()
|
||||
|
@ -1,5 +1,9 @@
|
||||
import argparse
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.application.handlers import Handler
|
||||
|
||||
|
||||
def test_parser(parser: argparse.ArgumentParser) -> None:
|
||||
"""
|
||||
@ -81,3 +85,19 @@ def test_subparsers_web(parser: argparse.ArgumentParser) -> None:
|
||||
args = parser.parse_args(["-a", "x86_64", "web"])
|
||||
assert args.lock is None
|
||||
assert args.no_report
|
||||
|
||||
|
||||
def test_run(args: argparse.Namespace, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
application must be run
|
||||
"""
|
||||
args.architecture = "x86_64"
|
||||
args.handler = Handler
|
||||
|
||||
from ahriman.application import ahriman
|
||||
mocker.patch.object(ahriman, "__name__", "__main__")
|
||||
mocker.patch("argparse.ArgumentParser.parse_args", return_value=args)
|
||||
exit_mock = mocker.patch("sys.exit")
|
||||
|
||||
ahriman.run()
|
||||
exit_mock.assert_called_once()
|
||||
|
@ -20,11 +20,22 @@ def test_finalize(application: Application, mocker: MockerFixture) -> None:
|
||||
sync_mock.assert_called_once()
|
||||
|
||||
|
||||
def test_get_updates_all(application: Application, mocker: MockerFixture) -> None:
|
||||
def test_known_packages(application: Application, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must return not empty list of known packages
|
||||
"""
|
||||
mocker.patch("ahriman.core.repository.repository.Repository.packages", return_value=[package_ahriman])
|
||||
packages = application._known_packages()
|
||||
assert len(packages) > 1
|
||||
assert package_ahriman.base in packages
|
||||
|
||||
|
||||
def test_get_updates_all(application: Application, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must get updates for all
|
||||
"""
|
||||
updates_aur_mock = mocker.patch("ahriman.core.repository.update_handler.UpdateHandler.updates_aur")
|
||||
updates_aur_mock = mocker.patch("ahriman.core.repository.update_handler.UpdateHandler.updates_aur",
|
||||
return_value=[package_ahriman])
|
||||
updates_manual_mock = mocker.patch("ahriman.core.repository.update_handler.UpdateHandler.updates_manual")
|
||||
|
||||
application.get_updates([], no_aur=False, no_manual=False, no_vcs=False, log_fn=print)
|
||||
@ -233,6 +244,17 @@ def test_sign(application: Application, package_ahriman: Package, package_python
|
||||
finalize_mock.assert_called_once()
|
||||
|
||||
|
||||
def test_sign_skip(application: Application, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must skip sign packages with empty filename
|
||||
"""
|
||||
package_ahriman.packages[package_ahriman.base].filename = None
|
||||
mocker.patch("ahriman.core.repository.repository.Repository.packages", return_value=[package_ahriman])
|
||||
mocker.patch("ahriman.application.application.Application.update")
|
||||
|
||||
application.sign([])
|
||||
|
||||
|
||||
def test_sign_specific(application: Application, package_ahriman: Package, package_python_schedule: Package,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
|
Reference in New Issue
Block a user