new tests, upgrade tests coverage

This commit is contained in:
2025-12-05 22:57:19 +03:00
parent 913e7f16ca
commit 2423f57000
8 changed files with 104 additions and 58 deletions
+30 -31
View File
@@ -19,7 +19,6 @@ from argenta.app.protocols import (
)
from argenta.app.registered_routers.entity import RegisteredRouters
from argenta.command.exceptions import (
EmptyInputCommandException,
InputCommandException,
RepeatedInputFlagsException,
UnprocessedInputFlagException,
@@ -40,7 +39,7 @@ class BaseApp:
initial_message: str,
farewell_message: str,
exit_command: Command,
system_router_title: str | None,
system_router_title: str,
ignore_command_register: bool,
dividing_line: StaticDividingLine | DynamicDividingLine,
repeat_command_groups_printing: bool,
@@ -51,7 +50,7 @@ class BaseApp:
self._prompt: str = prompt
self._print_func: Printer = print_func
self._exit_command: Command = exit_command
self._system_router_title: str | None = system_router_title
self._system_router_title: str = system_router_title
self._dividing_line: StaticDividingLine | DynamicDividingLine = dividing_line
self._ignore_command_register: bool = ignore_command_register
self._repeat_command_groups_printing_description: bool = repeat_command_groups_printing
@@ -144,8 +143,7 @@ class BaseApp:
:return: None
"""
for registered_router in self.registered_routers:
if registered_router.title:
self._print_func(registered_router.title)
self._print_func(registered_router.title)
for command_handler in registered_router.command_handlers:
handled_command = command_handler.handled_command
self._print_func(
@@ -239,7 +237,7 @@ class BaseApp:
self._incorrect_input_syntax_handler(raw_command)
elif isinstance(error, RepeatedInputFlagsException):
self._repeated_input_flags_handler(raw_command)
elif isinstance(error, EmptyInputCommandException):
else:
self._empty_input_command_handler()
def _setup_system_router(self) -> None:
@@ -253,9 +251,8 @@ class BaseApp:
def _(response: Response) -> None:
self._exit_command_handler(response)
if system_router not in self.registered_routers.registered_routers:
system_router.command_register_ignore = self._ignore_command_register
self.registered_routers.add_registered_router(system_router)
system_router.command_register_ignore = self._ignore_command_register
self.registered_routers.add_registered_router(system_router)
def _most_similar_command(self, unknown_command: str) -> str | None:
all_commands = list(self._current_matching_triggers_with_routers.keys())
@@ -342,6 +339,28 @@ class BaseApp:
print("\n")
if not self._repeat_command_groups_printing_description:
self._print_command_group_description()
def _process_exist_and_valid_command(self, input_command: InputCommand):
processing_router = self._current_matching_triggers_with_routers[input_command.trigger.lower()]
if processing_router.disable_redirect_stdout:
dividing_line_unit_part: str = self._dividing_line.get_unit_part()
self._print_func(
StaticDividingLine(dividing_line_unit_part).get_full_static_line(
is_override=self._override_system_messages
)
)
processing_router.finds_appropriate_handler(input_command)
self._print_func(
StaticDividingLine(dividing_line_unit_part).get_full_static_line(
is_override=self._override_system_messages
)
)
else:
with redirect_stdout(io.StringIO()) as stdout:
processing_router.finds_appropriate_handler(input_command)
stdout_result: str = stdout.getvalue()
self._print_framed_text(stdout_result)
AVAILABLE_DIVIDING_LINES: TypeAlias = StaticDividingLine | DynamicDividingLine
@@ -360,7 +379,7 @@ class App(BaseApp):
initial_message: str = "Argenta\n",
farewell_message: str = "\nSee you\n",
exit_command: Command = DEFAULT_EXIT_COMMAND,
system_router_title: str | None = "System points:",
system_router_title: str = "System points:",
ignore_command_register: bool = True,
dividing_line: AVAILABLE_DIVIDING_LINES = DEFAULT_DIVIDING_LINE,
repeat_command_groups_printing: bool = False,
@@ -433,27 +452,7 @@ class App(BaseApp):
self._print_framed_text(stdout_res)
continue
processing_router = self._current_matching_triggers_with_routers[input_command.trigger.lower()]
if processing_router.disable_redirect_stdout:
dividing_line_unit_part: str = self._dividing_line.get_unit_part()
self._print_func(
StaticDividingLine(dividing_line_unit_part).get_full_static_line(
is_override=self._override_system_messages
)
)
processing_router.finds_appropriate_handler(input_command)
self._print_func(
StaticDividingLine(dividing_line_unit_part).get_full_static_line(
is_override=self._override_system_messages
)
)
else:
with redirect_stdout(io.StringIO()) as stdout:
processing_router.finds_appropriate_handler(input_command)
stdout_result: str = stdout.getvalue()
if stdout_result:
self._print_framed_text(stdout_result)
self._process_exist_and_valid_command(input_command)
def include_router(self, router: Router) -> None:
"""
+4 -3
View File
@@ -2,11 +2,12 @@ __all__ = ["NonStandardBehaviorHandler", "EmptyCommandHandler", "Printer", "Desc
from typing import Protocol, TypeVar
T = TypeVar("T", contravariant=True) # noqa: WPS111
class NonStandardBehaviorHandler(Protocol[T]):
def __call__(self, __param: T) -> None:
def __call__(self, _param: T, /) -> None:
raise NotImplementedError
@@ -16,10 +17,10 @@ class EmptyCommandHandler(Protocol):
class Printer(Protocol):
def __call__(self, __text: str) -> None:
def __call__(self, _text: str, /) -> None:
raise NotImplementedError
class DescriptionMessageGenerator(Protocol):
def __call__(self, __first_param: str, __second_param: str) -> str:
def __call__(self, _command: str, _description: str, /) -> str:
raise NotImplementedError
@@ -24,6 +24,3 @@ class RegisteredRouters:
def __iter__(self) -> Iterator[Router]:
return iter(self.registered_routers)
def __next__(self) -> Router:
return next(iter(self.registered_routers))
+2 -2
View File
@@ -22,7 +22,7 @@ HandlerFunc: TypeAlias = Callable[..., None]
class Router:
def __init__(
self,
title: str | None = "Default title",
title: str = "Default title",
*,
disable_redirect_stdout: bool = False,
):
@@ -36,7 +36,7 @@ class Router:
which is ambiguous behavior and can lead to unexpected work
:return: None
"""
self.title: str | None = title
self.title: str = title
self.disable_redirect_stdout: bool = disable_redirect_stdout
self.command_handlers: CommandHandlers = CommandHandlers()