mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 10:05:28 +03:00
Update documentation
This commit is contained in:
@@ -8,22 +8,21 @@ from argenta import App, Orchestrator, Router, Command, Response
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def patched_argv():
|
||||
with patch.object(sys, 'argv', ['program.py']):
|
||||
with patch.object(sys, "argv", ["program.py"]):
|
||||
yield
|
||||
|
||||
|
||||
def test_input_incorrect_command(capsys: CaptureFixture[str]):
|
||||
router = Router()
|
||||
orchestrator = Orchestrator()
|
||||
|
||||
@router.command(Command('test'))
|
||||
@router.command(Command("test"))
|
||||
def test(response: Response) -> None:
|
||||
print('test command')
|
||||
print("test command")
|
||||
|
||||
app = App(override_system_messages=True, printer=print)
|
||||
app.include_router(router)
|
||||
app.set_unknown_command_handler(
|
||||
lambda command: print(f'Unknown command: {command.trigger}')
|
||||
)
|
||||
app.set_unknown_command_handler(lambda command: print(f"Unknown command: {command.trigger}"))
|
||||
|
||||
with patch("builtins.input", side_effect=["help", "q"]):
|
||||
orchestrator.start_polling(app)
|
||||
|
||||
@@ -17,5 +17,5 @@ def test_simple_app() -> None:
|
||||
|
||||
with redirect_stdout(io.StringIO()) as stdout:
|
||||
router.finds_appropriate_handler(InputCommand.parse("HELP"))
|
||||
|
||||
|
||||
assert "Available commands:" in stdout.getvalue()
|
||||
|
||||
@@ -11,18 +11,20 @@ from argenta.di.integration import setup_dishka, FromDishka
|
||||
class Service:
|
||||
def hello(self) -> str:
|
||||
return "world"
|
||||
|
||||
|
||||
|
||||
def get_service() -> Service:
|
||||
return Service()
|
||||
|
||||
|
||||
|
||||
router = Router(title="DI")
|
||||
|
||||
|
||||
@router.command("HELLO")
|
||||
def hello(response: Response, service: FromDishka[Service]) -> None:
|
||||
print(f"hello {service.hello()}")
|
||||
|
||||
|
||||
|
||||
|
||||
class _FakeApp:
|
||||
# Minimal stub for setup_dishka; app object is not used in unit tests
|
||||
registered_routers = [router]
|
||||
@@ -31,12 +33,12 @@ class _FakeApp:
|
||||
def test_hello_uses_service():
|
||||
provider = Provider(scope=Scope.APP)
|
||||
provider.provide(get_service)
|
||||
|
||||
|
||||
container = make_container(provider)
|
||||
setup_dishka(app=_FakeApp(), container=container, auto_inject=True)
|
||||
|
||||
# Call handler
|
||||
with redirect_stdout(io.StringIO()) as stdout:
|
||||
router.finds_appropriate_handler(InputCommand.parse('HELLO'))
|
||||
router.finds_appropriate_handler(InputCommand.parse("HELLO"))
|
||||
|
||||
assert "hello world" in stdout.getvalue()
|
||||
|
||||
@@ -7,6 +7,7 @@ from argenta.command import InputCommand
|
||||
|
||||
router = Router(title="Demo")
|
||||
|
||||
|
||||
@router.command(Command("PING", description="Ping command"))
|
||||
def ping(response: Response):
|
||||
print("PONG")
|
||||
|
||||
Reference in New Issue
Block a user