mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 10:05:28 +03:00
refactor tests and add new
This commit is contained in:
@@ -39,9 +39,6 @@ class BaseFlags(Generic[FlagType]):
|
||||
def __iter__(self) -> Iterator[FlagType]:
|
||||
return iter(self.flags)
|
||||
|
||||
def __next__(self) -> FlagType:
|
||||
return next(iter(self))
|
||||
|
||||
def __getitem__(self, flag_index: int) -> FlagType:
|
||||
return self.flags[flag_index]
|
||||
|
||||
@@ -61,7 +58,7 @@ class Flags(BaseFlags[Flag]):
|
||||
@override
|
||||
def __eq__(self, other: object) -> bool:
|
||||
if not isinstance(other, Flags):
|
||||
return NotImplemented
|
||||
return False
|
||||
|
||||
if len(self.flags) != len(other.flags):
|
||||
return False
|
||||
@@ -91,7 +88,7 @@ class InputFlags(BaseFlags[InputFlag]):
|
||||
@override
|
||||
def __eq__(self, other: object) -> bool:
|
||||
if not isinstance(other, InputFlags):
|
||||
raise NotImplementedError
|
||||
return False
|
||||
|
||||
if len(self.flags) != len(other.flags):
|
||||
return False
|
||||
|
||||
@@ -53,10 +53,7 @@ class Flag:
|
||||
if isinstance(self.possible_values, Pattern):
|
||||
return bool(self.possible_values.match(input_flag_value))
|
||||
|
||||
if isinstance(self.possible_values, list):
|
||||
return input_flag_value in self.possible_values
|
||||
|
||||
return False
|
||||
return input_flag_value in self.possible_values
|
||||
|
||||
@property
|
||||
def string_entity(self) -> str:
|
||||
@@ -88,9 +85,9 @@ class InputFlag:
|
||||
self,
|
||||
name: str,
|
||||
*,
|
||||
prefix: PREFIX_TYPE = "--",
|
||||
input_value: str,
|
||||
status: ValidationStatus | None,
|
||||
prefix: PREFIX_TYPE = "--",
|
||||
status: ValidationStatus | None = None,
|
||||
):
|
||||
"""
|
||||
Public. The entity of the flag of the entered command
|
||||
|
||||
@@ -104,9 +104,6 @@ class InputCommand:
|
||||
else:
|
||||
raise UnprocessedInputFlagException
|
||||
|
||||
if not name:
|
||||
raise UnprocessedInputFlagException
|
||||
|
||||
if i + 1 < len(tokens) and not tokens[i + 1].startswith("-"):
|
||||
input_value = tokens[i + 1]
|
||||
i += 2
|
||||
|
||||
@@ -20,16 +20,16 @@ def inject(func: Callable[..., T]) -> Callable[..., T]:
|
||||
|
||||
|
||||
def setup_dishka(app: App, container: Container, *, auto_inject: bool = False) -> None:
|
||||
Response.patch_by_container(container)
|
||||
if auto_inject:
|
||||
_auto_inject_handlers(app)
|
||||
Response.patch_by_container(container)
|
||||
|
||||
|
||||
def _get_container_from_response(args: tuple[Any, ...], kwargs: dict[str, Any]) -> Container:
|
||||
for arg in args:
|
||||
if isinstance(arg, Response):
|
||||
if hasattr(arg, "_dishka_container"):
|
||||
return arg._dishka_container # pyright: ignore[reportPrivateUsage]
|
||||
if hasattr(arg, "__dishka_container__"):
|
||||
return arg.__dishka_container__ # pyright: ignore[reportPrivateUsage]
|
||||
break
|
||||
raise RuntimeError("dishka container not found in Response")
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ from time import time
|
||||
from argenta import App
|
||||
|
||||
|
||||
def get_time_of_pre_cycle_setup(app: App) -> float:
|
||||
def get_time_of_pre_cycle_setup(app: App) -> float:
|
||||
"""
|
||||
Public. Return time of pre cycle setup
|
||||
:param app: app instance for testing time of pre cycle setup
|
||||
|
||||
@@ -94,7 +94,7 @@ class ArgParser:
|
||||
namespace=self._core.parse_args(), processed_args=self.processed_args
|
||||
)
|
||||
|
||||
def _register_args(self, processed_args: list[ValueArgument | BooleanArgument]) -> None:
|
||||
def _register_args(self, processed_args: list[ValueArgument | BooleanArgument]) -> None: # pragma: no cover
|
||||
if sys.version_info >= (3, 13):
|
||||
for arg in processed_args:
|
||||
if isinstance(arg, BooleanArgument):
|
||||
|
||||
@@ -26,7 +26,7 @@ class Orchestrator:
|
||||
self._custom_providers: list[Provider] = custom_providers
|
||||
self._auto_inject_handlers: bool = auto_inject_handlers
|
||||
|
||||
self._arg_parser._parse_args()
|
||||
self._arg_parser._parse_args() # pyright: ignore[reportPrivateUsage]
|
||||
|
||||
def start_polling(self, app: App) -> None:
|
||||
"""
|
||||
|
||||
@@ -9,7 +9,7 @@ EMPTY_INPUT_FLAGS: InputFlags = InputFlags()
|
||||
|
||||
|
||||
class Response:
|
||||
_dishka_container: Container
|
||||
__dishka_container__: Container
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -26,4 +26,4 @@ class Response:
|
||||
|
||||
@classmethod
|
||||
def patch_by_container(cls, container: Container) -> None:
|
||||
cls._dishka_container = container
|
||||
cls.__dishka_container__ = container
|
||||
|
||||
@@ -44,6 +44,3 @@ class CommandHandlers:
|
||||
|
||||
def __iter__(self) -> Iterator[CommandHandler]:
|
||||
return iter(self.command_handlers)
|
||||
|
||||
def __next__(self) -> CommandHandler:
|
||||
return next(iter(self.command_handlers))
|
||||
|
||||
@@ -20,7 +20,7 @@ class RequiredArgumentNotPassedException(Exception):
|
||||
|
||||
@override
|
||||
def __str__(self) -> str:
|
||||
return "Required argument not passed"
|
||||
return "Required argument with type Response not passed"
|
||||
|
||||
|
||||
class TriggerContainSpacesException(Exception):
|
||||
|
||||
Reference in New Issue
Block a user