refactor tests and add new

This commit is contained in:
2025-12-06 11:55:50 +03:00
parent a2ef2652ed
commit 1d2ab6f6bb
17 changed files with 294 additions and 31 deletions
+49 -1
View File
@@ -1,7 +1,7 @@
import re
import pytest
from argenta.command import Command
from argenta.command import Command, InputCommand
from argenta.command.flag import Flag, InputFlag
from argenta.command.flag.flags import Flags, InputFlags
from argenta.command.flag.models import PossibleValues, ValidationStatus
@@ -102,3 +102,51 @@ def test_get_router_aliases3():
def handler(response: Response):
pass
assert router.aliases == set()
def test_find_appropiate_handler(capsys: pytest.CaptureFixture[str]):
router = Router()
@router.command(Command('hello', aliases={'hi'}))
def handler(res: Response):
print("Hello World!")
router.finds_appropriate_handler(InputCommand('hi'))
output = capsys.readouterr()
assert "Hello World!" in output.out
def test_find_appropiate_handler2(capsys: CaptureFixture[str]):
router = Router()
@router.command(Command('hello', flags=Flag('flag'), aliases={'hi'}))
def handler(res: Response):
print("Hello World!")
router.finds_appropriate_handler(InputCommand('hi'))
output = capsys.readouterr()
assert "Hello World!" in output.out
def test_wrong_typehint(capsys: pytest.CaptureFixture[str]):
class NotResponse: pass
def func(response: NotResponse): pass
_validate_func_args(func)
output = capsys.readouterr()
assert "WARNING" in output.out
def test_missing_typehint(capsys: pytest.CaptureFixture[str]):
def func(response): pass # pyright: ignore[reportMissingParameterType, reportUnknownParameterType]
_validate_func_args(func) # pyright: ignore[reportUnknownArgumentType]
output = capsys.readouterr()
assert output.out == ''