mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-07-23 18:59:56 +00:00
add shell and version parser
This commit is contained in:
48
tests/ahriman/application/handlers/test_handler_shell.py
Normal file
48
tests/ahriman/application/handlers/test_handler_shell.py
Normal file
@ -0,0 +1,48 @@
|
||||
import argparse
|
||||
import pytest
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.application.handlers import Shell
|
||||
from ahriman.core.configuration import Configuration
|
||||
|
||||
|
||||
def _default_args(args: argparse.Namespace) -> argparse.Namespace:
|
||||
"""
|
||||
default arguments for these test cases
|
||||
|
||||
Args:
|
||||
args(argparse.Namespace): command line arguments fixture
|
||||
|
||||
Returns:
|
||||
argparse.Namespace: generated arguments for these test cases
|
||||
"""
|
||||
args.verbose = False
|
||||
return args
|
||||
|
||||
|
||||
def test_run(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must run command
|
||||
"""
|
||||
args = _default_args(args)
|
||||
mocker.patch("ahriman.models.repository_paths.RepositoryPaths.tree_create")
|
||||
application_mock = mocker.patch("code.interact")
|
||||
|
||||
Shell.run(args, "x86_64", configuration, True, False)
|
||||
application_mock.assert_called_once_with(local=pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
def test_run_verbose(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must run command with verbose option
|
||||
"""
|
||||
args = _default_args(args)
|
||||
args.verbose = True
|
||||
mocker.patch("ahriman.models.repository_paths.RepositoryPaths.tree_create")
|
||||
print_mock = mocker.patch("ahriman.core.formatters.Printer.print")
|
||||
application_mock = mocker.patch("code.interact")
|
||||
|
||||
Shell.run(args, "x86_64", configuration, True, False)
|
||||
application_mock.assert_called_once_with(local=pytest.helpers.anyvar(int))
|
||||
print_mock.assert_called_once_with(verbose=False)
|
38
tests/ahriman/application/handlers/test_handler_versions.py
Normal file
38
tests/ahriman/application/handlers/test_handler_versions.py
Normal file
@ -0,0 +1,38 @@
|
||||
import argparse
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
from unittest import mock
|
||||
|
||||
from ahriman.application.handlers import Versions
|
||||
from ahriman.core.configuration import Configuration
|
||||
|
||||
|
||||
def test_run(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must run command
|
||||
"""
|
||||
application_mock = mocker.patch("ahriman.application.handlers.Versions.package_dependencies")
|
||||
print_mock = mocker.patch("ahriman.core.formatters.Printer.print")
|
||||
|
||||
Versions.run(args, "x86_64", configuration, True, False)
|
||||
application_mock.assert_called_once_with("ahriman", ("pacman", "s3", "web"))
|
||||
print_mock.assert_has_calls([mock.call(verbose=False, separator=" "), mock.call(verbose=False, separator=" ")])
|
||||
|
||||
|
||||
def test_package_dependencies() -> None:
|
||||
"""
|
||||
must extract package dependencies
|
||||
"""
|
||||
packages = Versions.package_dependencies("srcinfo")
|
||||
assert packages
|
||||
assert packages.get("parse") is not None
|
||||
|
||||
|
||||
def test_package_dependencies_missing() -> None:
|
||||
"""
|
||||
must extract package dependencies even if some of them are missing
|
||||
"""
|
||||
packages = Versions.package_dependencies("ahriman", ("docs", "pacman", "s3", "web"))
|
||||
assert packages
|
||||
assert packages.get("pyalpm") is not None
|
||||
assert packages.get("Sphinx") is None
|
Reference in New Issue
Block a user