Update documentation and code snippets

This commit is contained in:
2025-12-08 19:29:54 +03:00
parent 75b1efb259
commit 183f069766
6 changed files with 179 additions and 4 deletions
+84
View File
@@ -221,6 +221,90 @@ def test_overlapping_aliases_raises_exception() -> None:
pass
def test_app_detects_trigger_collision_between_routers() -> None:
from argenta.router.exceptions import RepeatedTriggerNameException
app = App()
router1 = Router()
router2 = Router()
@router1.command('hello')
def handler1(_res: Response) -> None:
pass
@router2.command('hello')
def handler2(_res: Response) -> None:
pass
app.include_router(router1)
app.include_router(router2)
with pytest.raises(RepeatedTriggerNameException):
app._pre_cycle_setup()
def test_app_detects_alias_collision_between_routers() -> None:
app = App()
router1 = Router()
router2 = Router()
@router1.command(Command('hello', aliases={'hi'}))
def handler1(_res: Response) -> None:
pass
@router2.command(Command('world', aliases={'hi'}))
def handler2(_res: Response) -> None:
pass
app.include_router(router1)
app.include_router(router2)
with pytest.raises(RepeatedAliasNameException):
app._pre_cycle_setup()
def test_app_detects_trigger_alias_collision_between_routers() -> None:
app = App()
router1 = Router()
router2 = Router()
@router1.command('hello')
def handler1(_res: Response) -> None:
pass
@router2.command(Command('world', aliases={'hello'}))
def handler2(_res: Response) -> None:
pass
app.include_router(router1)
app.include_router(router2)
with pytest.raises(RepeatedAliasNameException):
app._pre_cycle_setup()
def test_app_detects_collision_case_insensitive() -> None:
from argenta.router.exceptions import RepeatedTriggerNameException
app = App()
router1 = Router()
router2 = Router()
@router1.command('Hello')
def handler1(_res: Response) -> None:
pass
@router2.command('hELLo')
def handler2(_res: Response) -> None:
pass
app.include_router(router1)
app.include_router(router2)
with pytest.raises(RepeatedTriggerNameException):
app._pre_cycle_setup()
# ============================================================================
# Tests for startup messages
# ============================================================================
+59 -1
View File
@@ -9,8 +9,9 @@ from argenta.command.flag.flags import Flags, InputFlags
from argenta.command.flag.models import PossibleValues, ValidationStatus
from argenta.response.entity import Response
from argenta.router import Router
from argenta.router.entity import _structuring_input_flags, _validate_func_args # pyright: ignore[reportPrivateUsage]
from argenta.router.entity import _structuring_input_flags, _validate_func_args
from argenta.router.exceptions import (
RepeatedAliasNameException,
RepeatedFlagNameException,
RepeatedTriggerNameException,
RequiredArgumentNotPassedException,
@@ -247,3 +248,60 @@ def test_finds_appropriate_handler_executes_handler_with_flags_by_alias(capsys:
output = capsys.readouterr()
assert "Hello World!" in output.out
# ============================================================================
# Tests for alias and trigger collision detection
# ============================================================================
def test_validate_command_raises_error_for_alias_collision_with_existing_trigger() -> None:
router = Router()
@router.command('hello')
def handler(_res: Response) -> None:
pass
with pytest.raises(RepeatedAliasNameException):
@router.command(Command('world', aliases={'hello'}))
def handler2(_res: Response) -> None:
pass
def test_validate_command_raises_error_for_alias_collision_with_existing_alias() -> None:
router = Router()
@router.command(Command('hello', aliases={'hi'}))
def handler(_res: Response) -> None:
pass
with pytest.raises(RepeatedAliasNameException):
@router.command(Command('world', aliases={'hi'}))
def handler2(_res: Response) -> None:
pass
def test_validate_command_raises_error_for_trigger_collision_with_existing_alias() -> None:
router = Router()
@router.command(Command('hello', aliases={'hi'}))
def handler(_res: Response) -> None:
pass
with pytest.raises(RepeatedAliasNameException):
@router.command('hi')
def handler2(_res: Response) -> None:
pass
def test_validate_command_raises_error_for_alias_collision_case_insensitive() -> None:
router = Router()
@router.command(Command('hello', aliases={'Hi'}))
def handler(_res: Response) -> None:
pass
with pytest.raises(RepeatedAliasNameException):
@router.command(Command('world', aliases={'hI'}))
def handler2(_res: Response) -> None:
pass