mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-06-28 06:41:43 +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
|
@ -492,6 +492,15 @@ def test_subparsers_repo_update_architecture(parser: argparse.ArgumentParser) ->
|
||||
assert args.architecture == ["x86_64"]
|
||||
|
||||
|
||||
def test_subparsers_shell(parser: argparse.ArgumentParser) -> None:
|
||||
"""
|
||||
shell command must imply lock and no-report
|
||||
"""
|
||||
args = parser.parse_args(["shell"])
|
||||
assert args.lock is None
|
||||
assert args.no_report
|
||||
|
||||
|
||||
def test_subparsers_user_add(parser: argparse.ArgumentParser) -> None:
|
||||
"""
|
||||
user-add command must imply action, architecture, lock, no-report, quiet and unsafe
|
||||
@ -575,6 +584,26 @@ def test_subparsers_user_remove_architecture(parser: argparse.ArgumentParser) ->
|
||||
assert args.architecture == [""]
|
||||
|
||||
|
||||
def test_subparsers_version(parser: argparse.ArgumentParser) -> None:
|
||||
"""
|
||||
version command must imply architecture, lock, no-report, quiet and unsafe
|
||||
"""
|
||||
args = parser.parse_args(["version"])
|
||||
assert args.architecture == [""]
|
||||
assert args.lock is None
|
||||
assert args.no_report
|
||||
assert args.quiet
|
||||
assert args.unsafe
|
||||
|
||||
|
||||
def test_subparsers_version_architecture(parser: argparse.ArgumentParser) -> None:
|
||||
"""
|
||||
version command must correctly parse architecture list
|
||||
"""
|
||||
args = parser.parse_args(["-a", "x86_64", "version"])
|
||||
assert args.architecture == [""]
|
||||
|
||||
|
||||
def test_subparsers_web(parser: argparse.ArgumentParser) -> None:
|
||||
"""
|
||||
web command must imply lock, no_report and parser
|
||||
|
@ -1,6 +1,7 @@
|
||||
import pytest
|
||||
|
||||
from ahriman.core.formatters import AurPrinter, ConfigurationPrinter, PackagePrinter, StatusPrinter, StringPrinter, UpdatePrinter, UserPrinter
|
||||
from ahriman.core.formatters import AurPrinter, ConfigurationPrinter, PackagePrinter, StatusPrinter, StringPrinter, \
|
||||
UpdatePrinter, UserPrinter, VersionPrinter
|
||||
from ahriman.models.aur_package import AURPackage
|
||||
from ahriman.models.build_status import BuildStatus
|
||||
from ahriman.models.package import Package
|
||||
@ -94,3 +95,17 @@ def user_printer(user: User) -> UserPrinter:
|
||||
UserPrinter: user printer test instance
|
||||
"""
|
||||
return UserPrinter(user)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def version_printer(package_ahriman: Package) -> VersionPrinter:
|
||||
"""
|
||||
fixture for version printer
|
||||
|
||||
Args:
|
||||
package_ahriman(Package): package fixture
|
||||
|
||||
Returns:
|
||||
VersionPrinter: version printer test instance
|
||||
"""
|
||||
return VersionPrinter("package", {package_ahriman.base: package_ahriman.version})
|
||||
|
15
tests/ahriman/core/formatters/test_version_printer.py
Normal file
15
tests/ahriman/core/formatters/test_version_printer.py
Normal file
@ -0,0 +1,15 @@
|
||||
from ahriman.core.formatters import VersionPrinter
|
||||
|
||||
|
||||
def test_properties(version_printer: VersionPrinter) -> None:
|
||||
"""
|
||||
must return empty properties list
|
||||
"""
|
||||
assert version_printer.properties()
|
||||
|
||||
|
||||
def test_title(version_printer: VersionPrinter) -> None:
|
||||
"""
|
||||
must return non empty title
|
||||
"""
|
||||
assert version_printer.title() is not None
|
@ -10,8 +10,9 @@ from unittest.mock import MagicMock
|
||||
|
||||
from ahriman.core.exceptions import BuildFailed, InvalidOption, UnsafeRun
|
||||
from ahriman.core.util import check_output, check_user, exception_response_text, filter_json, full_version, \
|
||||
package_like, pretty_datetime, pretty_size, tmpdir, walk
|
||||
enum_values, package_like, pretty_datetime, pretty_size, tmpdir, walk
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.package_source import PackageSource
|
||||
from ahriman.models.repository_paths import RepositoryPaths
|
||||
|
||||
|
||||
@ -177,6 +178,15 @@ def test_filter_json_empty_value(package_ahriman: Package) -> None:
|
||||
assert "base" not in filter_json(probe, probe.keys())
|
||||
|
||||
|
||||
def test_enum_values() -> None:
|
||||
"""
|
||||
must correctly generate choices from enumeration classes
|
||||
"""
|
||||
values = enum_values(PackageSource)
|
||||
for value in values:
|
||||
assert PackageSource(value).value == value
|
||||
|
||||
|
||||
def test_full_version() -> None:
|
||||
"""
|
||||
must construct full version
|
||||
@ -331,6 +341,7 @@ def test_walk(resource_path_root: Path) -> None:
|
||||
resource_path_root / "web" / "templates" / "build-status.jinja2",
|
||||
resource_path_root / "web" / "templates" / "email-index.jinja2",
|
||||
resource_path_root / "web" / "templates" / "repo-index.jinja2",
|
||||
resource_path_root / "web" / "templates" / "shell",
|
||||
resource_path_root / "web" / "templates" / "telegram-index.jinja2",
|
||||
])
|
||||
local_files = list(sorted(walk(resource_path_root)))
|
||||
|
Reference in New Issue
Block a user