add shell and version parser

This commit is contained in:
2022-05-23 19:10:26 +03:00
parent 9f134e37b6
commit f4131b8cd7
22 changed files with 511 additions and 26 deletions

View 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)

View 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