better perf

This commit is contained in:
2025-12-08 14:17:31 +03:00
parent cb6549452d
commit 75b1efb259
9 changed files with 190 additions and 88 deletions
+6 -12
View File
@@ -1,3 +1,4 @@
from argenta.router.exceptions import RepeatedAliasNameException
import pytest
from pytest import CaptureFixture
@@ -207,24 +208,17 @@ def test_include_routers_registers_multiple_routers() -> None:
assert app.registered_routers.registered_routers == [router, router2]
def test_overlapping_aliases_prints_warning(capsys: CaptureFixture[str]) -> None:
app = App(override_system_messages=True)
def test_overlapping_aliases_raises_exception() -> None:
router = Router()
@router.command(Command('test', aliases={'alias'}))
def handler(_res: Response) -> None:
pass
@router.command(Command('test2', aliases={'alias'}))
def handler2(_res: Response) -> None:
pass
app.include_routers(router)
app._pre_cycle_setup()
captured = capsys.readouterr()
assert "Overlapping" in captured.out
with pytest.raises(RepeatedAliasNameException):
@router.command(Command('test2', aliases={'alias'}))
def handler2(_res: Response) -> None:
pass
# ============================================================================
+42 -1
View File
@@ -12,6 +12,7 @@ from argenta.router import Router
from argenta.router.entity import _structuring_input_flags, _validate_func_args # pyright: ignore[reportPrivateUsage]
from argenta.router.exceptions import (
RepeatedFlagNameException,
RepeatedTriggerNameException,
RequiredArgumentNotPassedException,
TriggerContainSpacesException,
)
@@ -26,7 +27,20 @@ def test_validate_command_raises_error_for_trigger_with_spaces() -> None:
router = Router()
with pytest.raises(TriggerContainSpacesException):
router._validate_command(Command(trigger='command with spaces'))
def test_validate_command_raises_error_for_same_trigger() -> None:
router = Router()
@router.command('comm')
def handler(res: Response):
pass
with pytest.raises(RepeatedTriggerNameException):
@router.command('comm')
def handler2(res: Response):
pass
def test_validate_command_raises_error_for_repeated_flag_names() -> None:
router = Router()
@@ -192,6 +206,33 @@ def test_finds_appropriate_handler_executes_handler_by_alias(capsys: CaptureFixt
output = capsys.readouterr()
assert "Hello World!" in output.out
def test_finds_appropriate_handler_executes_handler_by_alias_with_differrent_register(capsys: CaptureFixture[str]) -> None:
router = Router()
@router.command(Command('hello', aliases={'hI'}))
def handler(_res: Response) -> None:
print("Hello World!")
router.finds_appropriate_handler(InputCommand('HI'))
output = capsys.readouterr()
assert "Hello World!" in output.out
def test_finds_appropriate_handler_executes_handler_by_trigger_with_differrent_register(capsys: CaptureFixture[str]) -> None:
router = Router()
@router.command(Command('heLLo'))
def handler(_res: Response) -> None:
print("Hello World!")
router.finds_appropriate_handler(InputCommand('HellO'))
output = capsys.readouterr()
assert "Hello World!" in output.out
def test_finds_appropriate_handler_executes_handler_with_flags_by_alias(capsys: CaptureFixture[str]) -> None: