rename orchestrator method start_polling to run_repl

This commit is contained in:
2026-02-10 14:03:37 +03:00
parent 6ed1d35e8a
commit de6d35205c
23 changed files with 79 additions and 81 deletions
+2 -2
View File
@@ -12,6 +12,6 @@ orchestrator = Orchestrator(
if __name__ == "__main__": if __name__ == "__main__":
if arg_parser.parsed_argspace.get_by_name("dev"): if arg_parser.parsed_argspace.get_by_name("dev"):
orchestrator.start_polling(App(initial_message="ArgentaDev")) orchestrator.run_repl(App(initial_message="ArgentaDev"))
else: else:
orchestrator.start_polling(App()) orchestrator.run_repl(App())
+1 -1
View File
@@ -22,7 +22,7 @@ def main():
print(f" Host: {host.value}") print(f" Host: {host.value}")
print(f" Port: {port.value}") print(f" Port: {port.value}")
orchestrator.start_polling(app) orchestrator.run_repl(app)
if __name__ == "__main__": if __name__ == "__main__":
+1 -1
View File
@@ -24,4 +24,4 @@ orchestrator = Orchestrator(custom_providers=[ConnectionProvider()])
# 4. Start the application # 4. Start the application
if __name__ == "__main__": if __name__ == "__main__":
orchestrator.start_polling(app) orchestrator.run_repl(app)
@@ -60,7 +60,7 @@ orchestrator = Orchestrator()
def main(): def main():
app.include_router(router) app.include_router(router)
orchestrator.start_polling(app) orchestrator.run_repl(app)
if __name__ == "__main__": if __name__ == "__main__":
+1 -1
View File
@@ -9,7 +9,7 @@ orchestrator: Orchestrator = Orchestrator()
def main() -> None: def main() -> None:
app.include_router(router) app.include_router(router)
orchestrator.start_polling(app) orchestrator.run_repl(app)
if __name__ == "__main__": if __name__ == "__main__":
+1 -1
View File
@@ -30,4 +30,4 @@ app.include_router(main_router)
# 5. Start application # 5. Start application
if __name__ == "__main__": if __name__ == "__main__":
orchestrator.start_polling(app) orchestrator.run_repl(app)
@@ -15,4 +15,4 @@ app.include_router(router)
# 3. Start polling via orchestrator # 3. Start polling via orchestrator
if __name__ == "__main__": if __name__ == "__main__":
orchestrator.start_polling(app) orchestrator.run_repl(app)
+1 -1
View File
@@ -25,7 +25,7 @@ def test_input_incorrect_command(capsys: CaptureFixture[str]):
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"]): with patch("builtins.input", side_effect=["help", "q"]):
orchestrator.start_polling(app) orchestrator.run_repl(app)
output = capsys.readouterr().out output = capsys.readouterr().out
assert "\nUnknown command: help\n" in output assert "\nUnknown command: help\n" in output
+1 -1
View File
@@ -159,7 +159,7 @@ PredefinedMessages
app.add_message_on_startup(PredefinedMessages.AUTOCOMPLETE) app.add_message_on_startup(PredefinedMessages.AUTOCOMPLETE)
app.add_message_on_startup(PredefinedMessages.HELP) app.add_message_on_startup(PredefinedMessages.HELP)
orchestrator.start_polling(app) orchestrator.run_repl(app)
if __name__ == "__main__": if __name__ == "__main__":
main() main()
+1 -1
View File
@@ -36,7 +36,7 @@ Orchestrator
Основные методы Основные методы
---------------- ----------------
.. py:method:: start_polling(self, app: App) -> None .. py:method:: run_repl(self, app: App) -> None
Это главный метод, который запускает приложение. Он запускает бесконечный цикл ввода -> вывода. Это главный метод, который запускает приложение. Он запускает бесконечный цикл ввода -> вывода.
+1 -1
View File
@@ -45,7 +45,7 @@
E2E-тестирование цикла E2E-тестирование цикла
---------------------- ----------------------
Полный запуск цикла ``start_polling`` можно покрывать через подпроцесс с передачей строк в ``stdin``. Это тяжелее и обычно не требуется. Если всё же необходимо — пример ниже. Полный запуск цикла ``run_repl`` можно покрывать через подпроцесс с передачей строк в ``stdin``. Это тяжелее и обычно не требуется. Если всё же необходимо — пример ниже.
.. danger:: .. danger::
**Важно:** Обязательно передавайте строковый триггер команды выхода последним элементом в списке ``side_effects`` при патче ``input``. **Важно:** Обязательно передавайте строковый триггер команды выхода последним элементом в списке ``side_effects`` при патче ``input``.
+1 -1
View File
@@ -12,7 +12,7 @@ def main() -> None:
app.set_description_message_pattern( app.set_description_message_pattern(
lambda command, description: f'[bold cyan]▸[/bold cyan] [bold white]{command}[/bold white] [dim]│[/dim] [yellow italic]{description}[/yellow italic]' lambda command, description: f'[bold cyan]▸[/bold cyan] [bold white]{command}[/bold white] [dim]│[/dim] [yellow italic]{description}[/yellow italic]'
) )
orchestrator.start_polling(app) orchestrator.run_repl(app)
if __name__ == "__main__": if __name__ == "__main__":
+1 -1
View File
@@ -9,7 +9,7 @@ orchestrator: Orchestrator = Orchestrator()
def main() -> None: def main() -> None:
app.include_router(router) app.include_router(router)
orchestrator.start_polling(app) orchestrator.run_repl(app)
if __name__ == '__main__': if __name__ == '__main__':
main() main()
+1 -1
View File
@@ -19,7 +19,7 @@ def main():
app.add_message_on_startup(PredefinedMessages.AUTOCOMPLETE) app.add_message_on_startup(PredefinedMessages.AUTOCOMPLETE)
app.add_message_on_startup(PredefinedMessages.HELP) app.add_message_on_startup(PredefinedMessages.HELP)
orchestrator.start_polling(app) orchestrator.run_repl(app)
if __name__ == "__main__": if __name__ == "__main__":
main() main()
+4 -4
View File
@@ -3,11 +3,11 @@ from typer import Typer
from .commands import run_handler, init_handler, new_handler from .commands import run_handler, init_handler, new_handler
def main(): def main() -> None:
app = Typer() app = Typer()
app.command("run")(run_handler) app.command("run", help='Command to start the orchestrator repl; the path to the orchestrator is required')(run_handler)
app.command("init")(init_handler) app.command("init", help="Creates a flat/src boilerplate architecture in an existing project")(init_handler)
app.command("new")(new_handler) app.command("new", help="Creates a project and in it flat/src boilerplate architecture")(new_handler)
app() app()
if __name__ == '__main__': if __name__ == '__main__':
+2 -2
View File
@@ -22,7 +22,7 @@ def main():
app.include_router(router) app.include_router(router)
orchestrator = Orchestrator() orchestrator = Orchestrator()
orchestrator.start_polling(app) orchestrator.run_repl(app)
if __name__ == "__main__": if __name__ == "__main__":
main() main()
@@ -49,7 +49,7 @@ def main():
app.include_router(router) app.include_router(router)
orchestrator = Orchestrator() orchestrator = Orchestrator()
orchestrator.start_polling(app) orchestrator.run_repl(app)
if __name__ == "__main__": if __name__ == "__main__":
main() main()
+2 -2
View File
@@ -24,7 +24,7 @@ def main():
app.include_router(router) app.include_router(router)
orchestrator = Orchestrator() orchestrator = Orchestrator()
orchestrator.start_polling(app) orchestrator.run_repl(app)
if __name__ == "__main__": if __name__ == "__main__":
main() main()
@@ -51,7 +51,7 @@ def main():
app.include_router(router) app.include_router(router)
orchestrator = Orchestrator() orchestrator = Orchestrator()
orchestrator.start_polling(app) orchestrator.run_repl(app)
if __name__ == "__main__": if __name__ == "__main__":
main() main()
+1 -1
View File
@@ -144,7 +144,7 @@ class BaseApp(BehaviorHandlersSettersMixin):
is_stdout_redirected_by_router=processing_router.is_redirect_stdout_disabled is_stdout_redirected_by_router=processing_router.is_redirect_stdout_disabled
) )
def _run_polling(self) -> None: def _run_repl(self) -> None:
self._viewer.view_initial_message(self._initial_message) self._viewer.view_initial_message(self._initial_message)
self._pre_cycle_setup() self._pre_cycle_setup()
while True: while True:
-1
View File
@@ -9,7 +9,6 @@ __all__ = [
from typing import Any, Protocol, TypeVar, Callable from typing import Any, Protocol, TypeVar, Callable
from argenta.response import Response
T = TypeVar("T", contravariant=True) T = TypeVar("T", contravariant=True)
+2 -2
View File
@@ -30,7 +30,7 @@ class Orchestrator:
if self._arg_parser is not None: if self._arg_parser is not None:
self._arg_parser._parse_args() self._arg_parser._parse_args()
def start_polling(self, app: App) -> None: def run_repl(self, app: App) -> None:
""" """
Public. Starting the user input processing cycle Public. Starting the user input processing cycle
:param app: a running application :param app: a running application
@@ -41,4 +41,4 @@ class Orchestrator:
) )
setup_dishka(app, container, auto_inject=self._auto_inject_handlers) setup_dishka(app, container, auto_inject=self._auto_inject_handlers)
app._run_polling() app._run_repl()
@@ -38,7 +38,7 @@ def test_empty_input_triggers_empty_command_handler(monkeypatch: pytest.MonkeyPa
app = App(override_system_messages=True, printer=print) app = App(override_system_messages=True, printer=print)
app.include_router(router) app.include_router(router)
app.set_empty_command_handler(lambda: print('Empty input command')) app.set_empty_command_handler(lambda: print('Empty input command'))
orchestrator.start_polling(app) orchestrator.run_repl(app)
output = capsys.readouterr().out output = capsys.readouterr().out
@@ -64,7 +64,7 @@ def test_unknown_command_triggers_unknown_command_handler(monkeypatch: pytest.Mo
app = App(override_system_messages=True, printer=print) app = App(override_system_messages=True, printer=print)
app.include_router(router) 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}'))
orchestrator.start_polling(app) orchestrator.run_repl(app)
output = capsys.readouterr().out output = capsys.readouterr().out
@@ -85,7 +85,7 @@ def test_mixed_valid_and_unknown_commands_handled_correctly(monkeypatch: pytest.
app = App(override_system_messages=True, printer=print) app = App(override_system_messages=True, printer=print)
app.include_router(router) 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}'))
orchestrator.start_polling(app) orchestrator.run_repl(app)
output = capsys.readouterr().out output = capsys.readouterr().out
@@ -110,7 +110,7 @@ def test_multiple_commands_with_unknown_command_in_between(monkeypatch: pytest.M
app = App(override_system_messages=True, printer=print) app = App(override_system_messages=True, printer=print)
app.include_router(router) 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}'))
orchestrator.start_polling(app) orchestrator.run_repl(app)
output = capsys.readouterr().out output = capsys.readouterr().out
@@ -137,7 +137,7 @@ def test_unregistered_flag_without_value_is_accessible(monkeypatch: pytest.Monke
app = App(override_system_messages=True, printer=print) app = App(override_system_messages=True, printer=print)
app.include_router(router) app.include_router(router)
orchestrator.start_polling(app) orchestrator.run_repl(app)
output = capsys.readouterr().out output = capsys.readouterr().out
@@ -161,7 +161,7 @@ def test_unregistered_flag_with_value_is_accessible(monkeypatch: pytest.MonkeyPa
app = App(override_system_messages=True, printer=print) app = App(override_system_messages=True, printer=print)
app.include_router(router) app.include_router(router)
orchestrator.start_polling(app) orchestrator.run_repl(app)
output = capsys.readouterr().out output = capsys.readouterr().out
@@ -184,7 +184,7 @@ def test_registered_and_unregistered_flags_coexist(monkeypatch: pytest.MonkeyPat
app = App(override_system_messages=True, printer=print) app = App(override_system_messages=True, printer=print)
app.include_router(router) app.include_router(router)
orchestrator.start_polling(app) orchestrator.run_repl(app)
output = capsys.readouterr().out output = capsys.readouterr().out
@@ -210,7 +210,7 @@ def test_flag_without_value_triggers_incorrect_syntax_handler(monkeypatch: pytes
app = App(override_system_messages=True, printer=print) app = App(override_system_messages=True, printer=print)
app.include_router(router) app.include_router(router)
app.set_incorrect_input_syntax_handler(lambda command: print(f'Incorrect flag syntax: "{command}"')) app.set_incorrect_input_syntax_handler(lambda command: print(f'Incorrect flag syntax: "{command}"'))
orchestrator.start_polling(app) orchestrator.run_repl(app)
output = capsys.readouterr().out output = capsys.readouterr().out
@@ -236,7 +236,7 @@ def test_repeated_flags_trigger_repeated_flags_handler(monkeypatch: pytest.Monke
app = App(override_system_messages=True, printer=print) app = App(override_system_messages=True, printer=print)
app.include_router(router) app.include_router(router)
app.set_repeated_input_flags_handler(lambda command: print(f'Repeated input flags: "{command}"')) app.set_repeated_input_flags_handler(lambda command: print(f'Repeated input flags: "{command}"'))
orchestrator.start_polling(app) orchestrator.run_repl(app)
output = capsys.readouterr().out output = capsys.readouterr().out
@@ -38,7 +38,7 @@ def test_simple_command_executes_successfully(monkeypatch: pytest.MonkeyPatch, c
app = App(override_system_messages=True, printer=print) app = App(override_system_messages=True, printer=print)
app.include_router(router) app.include_router(router)
orchestrator.start_polling(app) orchestrator.run_repl(app)
output = capsys.readouterr().out output = capsys.readouterr().out
@@ -62,7 +62,7 @@ def test_two_commands_execute_sequentially(monkeypatch: pytest.MonkeyPatch, caps
app = App(override_system_messages=True, printer=print) app = App(override_system_messages=True, printer=print)
app.include_router(router) app.include_router(router)
orchestrator.start_polling(app) orchestrator.run_repl(app)
output = capsys.readouterr().out output = capsys.readouterr().out
@@ -90,7 +90,7 @@ def test_three_commands_execute_sequentially(monkeypatch: pytest.MonkeyPatch, ca
app = App(override_system_messages=True, printer=print) app = App(override_system_messages=True, printer=print)
app.include_router(router) app.include_router(router)
orchestrator.start_polling(app) orchestrator.run_repl(app)
output = capsys.readouterr().out output = capsys.readouterr().out
@@ -118,7 +118,7 @@ def test_custom_flag_without_value_is_recognized(monkeypatch: pytest.MonkeyPatch
app = App(override_system_messages=True, printer=print) app = App(override_system_messages=True, printer=print)
app.include_router(router) app.include_router(router)
orchestrator.start_polling(app) orchestrator.run_repl(app)
output = capsys.readouterr().out output = capsys.readouterr().out
@@ -141,7 +141,7 @@ def test_custom_flag_with_regex_validation_accepts_valid_value(monkeypatch: pyte
app = App(override_system_messages=True, repeat_command_groups_printing=True, printer=print) app = App(override_system_messages=True, repeat_command_groups_printing=True, printer=print)
app.include_router(router) app.include_router(router)
orchestrator.start_polling(app) orchestrator.run_repl(app)
output = capsys.readouterr().out output = capsys.readouterr().out
@@ -169,7 +169,7 @@ def test_predefined_short_help_flag_is_recognized(monkeypatch: pytest.MonkeyPatc
app = App(override_system_messages=True, printer=print) app = App(override_system_messages=True, printer=print)
app.include_router(router) app.include_router(router)
orchestrator.start_polling(app) orchestrator.run_repl(app)
output = capsys.readouterr().out output = capsys.readouterr().out
@@ -192,7 +192,7 @@ def test_predefined_info_flag_is_recognized(monkeypatch: pytest.MonkeyPatch, cap
app = App(override_system_messages=True, printer=print) app = App(override_system_messages=True, printer=print)
app.include_router(router) app.include_router(router)
orchestrator.start_polling(app) orchestrator.run_repl(app)
output = capsys.readouterr().out output = capsys.readouterr().out
@@ -215,7 +215,7 @@ def test_predefined_host_flag_with_value_is_recognized(monkeypatch: pytest.Monke
app = App(override_system_messages=True, printer=print) app = App(override_system_messages=True, printer=print)
app.include_router(router) app.include_router(router)
orchestrator.start_polling(app) orchestrator.run_repl(app)
output = capsys.readouterr().out output = capsys.readouterr().out
@@ -244,7 +244,7 @@ def test_two_predefined_flags_are_recognized_together(monkeypatch: pytest.Monkey
app = App(override_system_messages=True, printer=print) app = App(override_system_messages=True, printer=print)
app.include_router(router) app.include_router(router)
orchestrator.start_polling(app) orchestrator.run_repl(app)
output = capsys.readouterr().out output = capsys.readouterr().out
+35 -36
View File
@@ -45,12 +45,11 @@ def sample_router() -> Router:
# ============================================================================ # ============================================================================
def test_orchestrator_initializes_with_default_argparser(mocker: MockerFixture) -> None: def test_orchestrator_initializes_with_no_argparser(mocker: MockerFixture) -> None:
"""Test Orchestrator initialization with default ArgParser""" """Test Orchestrator initialization with no ArgParser"""
mocker.patch('sys.argv', ['test_program']) mocker.patch('sys.argv', ['test_program'])
orchestrator = Orchestrator() orchestrator = Orchestrator()
assert orchestrator._arg_parser is not None assert orchestrator._arg_parser is None
assert isinstance(orchestrator._arg_parser, ArgParser)
def test_orchestrator_initializes_with_custom_argparser(mock_argparser: ArgParser) -> None: def test_orchestrator_initializes_with_custom_argparser(mock_argparser: ArgParser) -> None:
@@ -89,80 +88,80 @@ def test_orchestrator_parses_args_on_initialization(mocker: MockerFixture, mock_
# ============================================================================ # ============================================================================
# Tests for start_polling method # Tests for run_repl method
# ============================================================================ # ============================================================================
def test_start_polling_creates_dishka_container( def test_run_repl_creates_dishka_container(
mocker: MockerFixture, mock_argparser: ArgParser, sample_app: App mocker: MockerFixture, mock_argparser: ArgParser, sample_app: App
) -> None: ) -> None:
"""Test that start_polling creates a dishka container""" """Test that run_repl creates a dishka container"""
mock_make_container = mocker.patch('argenta.orchestrator.entity.make_container') mock_make_container = mocker.patch('argenta.orchestrator.entity.make_container')
_mock_setup_dishka = mocker.patch('argenta.orchestrator.entity.setup_dishka') _mock_setup_dishka = mocker.patch('argenta.orchestrator.entity.setup_dishka')
mocker.patch.object(sample_app, '_run_polling') mocker.patch.object(sample_app, '_run_repl')
orchestrator = Orchestrator(arg_parser=mock_argparser) orchestrator = Orchestrator(arg_parser=mock_argparser)
orchestrator.start_polling(sample_app) orchestrator.run_repl(sample_app)
mock_make_container.assert_called_once() mock_make_container.assert_called_once()
assert mock_make_container.call_args[1]['context'] == {ArgParser: mock_argparser} assert mock_make_container.call_args[1]['context'] == {ArgParser: mock_argparser}
def test_start_polling_calls_setup_dishka_with_auto_inject_enabled( def test_run_repl_calls_setup_dishka_with_auto_inject_enabled(
mocker: MockerFixture, mock_argparser: ArgParser, sample_app: App mocker: MockerFixture, mock_argparser: ArgParser, sample_app: App
) -> None: ) -> None:
"""Test that start_polling calls setup_dishka with auto_inject=True""" """Test that run_repl calls setup_dishka with auto_inject=True"""
mock_container = mocker.MagicMock() # pyright: ignore[reportUnknownMemberType, reportUnknownVariableType] mock_container = mocker.MagicMock() # pyright: ignore[reportUnknownMemberType, reportUnknownVariableType]
mocker.patch('argenta.orchestrator.entity.make_container', return_value=mock_container) mocker.patch('argenta.orchestrator.entity.make_container', return_value=mock_container)
mock_setup_dishka = mocker.patch('argenta.orchestrator.entity.setup_dishka') mock_setup_dishka = mocker.patch('argenta.orchestrator.entity.setup_dishka')
mocker.patch.object(sample_app, '_run_polling') mocker.patch.object(sample_app, '_run_repl')
orchestrator = Orchestrator(arg_parser=mock_argparser, auto_inject_handlers=True) orchestrator = Orchestrator(arg_parser=mock_argparser, auto_inject_handlers=True)
orchestrator.start_polling(sample_app) orchestrator.run_repl(sample_app)
mock_setup_dishka.assert_called_once_with(sample_app, mock_container, auto_inject=True) mock_setup_dishka.assert_called_once_with(sample_app, mock_container, auto_inject=True)
def test_start_polling_calls_setup_dishka_with_auto_inject_disabled( def test_run_repl_calls_setup_dishka_with_auto_inject_disabled(
mocker: MockerFixture, mock_argparser: ArgParser, sample_app: App mocker: MockerFixture, mock_argparser: ArgParser, sample_app: App
) -> None: ) -> None:
"""Test that start_polling calls setup_dishka with auto_inject=False""" """Test that run_repl calls setup_dishka with auto_inject=False"""
mock_container = mocker.MagicMock() # pyright: ignore[reportUnknownMemberType, reportUnknownVariableType] mock_container = mocker.MagicMock() # pyright: ignore[reportUnknownMemberType, reportUnknownVariableType]
mocker.patch('argenta.orchestrator.entity.make_container', return_value=mock_container) mocker.patch('argenta.orchestrator.entity.make_container', return_value=mock_container)
mock_setup_dishka = mocker.patch('argenta.orchestrator.entity.setup_dishka') mock_setup_dishka = mocker.patch('argenta.orchestrator.entity.setup_dishka')
mocker.patch.object(sample_app, '_run_polling') mocker.patch.object(sample_app, '_run_repl')
orchestrator = Orchestrator(arg_parser=mock_argparser, auto_inject_handlers=False) orchestrator = Orchestrator(arg_parser=mock_argparser, auto_inject_handlers=False)
orchestrator.start_polling(sample_app) orchestrator.run_repl(sample_app)
mock_setup_dishka.assert_called_once_with(sample_app, mock_container, auto_inject=False) mock_setup_dishka.assert_called_once_with(sample_app, mock_container, auto_inject=False)
def test_start_polling_calls_app_run_polling( def test_run_repl_calls_app_run_repl(
mocker: MockerFixture, mock_argparser: ArgParser, sample_app: App mocker: MockerFixture, mock_argparser: ArgParser, sample_app: App
) -> None: ) -> None:
"""Test that start_polling calls app.run_polling()""" """Test that run_repl calls app.run_polling()"""
mocker.patch('argenta.orchestrator.entity.make_container') mocker.patch('argenta.orchestrator.entity.make_container')
mocker.patch('argenta.orchestrator.entity.setup_dishka') mocker.patch('argenta.orchestrator.entity.setup_dishka')
mock_run_polling = mocker.patch.object(sample_app, '_run_polling') mock_run_repl = mocker.patch.object(sample_app, '_run_repl')
orchestrator = Orchestrator(arg_parser=mock_argparser) orchestrator = Orchestrator(arg_parser=mock_argparser)
orchestrator.start_polling(sample_app) orchestrator.run_repl(sample_app)
mock_run_polling.assert_called_once() mock_run_repl.assert_called_once()
def test_start_polling_includes_custom_providers_in_container( def test_run_repl_includes_custom_providers_in_container(
mocker: MockerFixture, mock_argparser: ArgParser, sample_app: App mocker: MockerFixture, mock_argparser: ArgParser, sample_app: App
) -> None: ) -> None:
"""Test that start_polling includes custom providers in container""" """Test that run_repl includes custom providers in container"""
custom_provider = Provider() custom_provider = Provider()
mock_make_container = mocker.patch('argenta.orchestrator.entity.make_container') mock_make_container = mocker.patch('argenta.orchestrator.entity.make_container')
mocker.patch('argenta.orchestrator.entity.setup_dishka') mocker.patch('argenta.orchestrator.entity.setup_dishka')
mocker.patch.object(sample_app, '_run_polling') mocker.patch.object(sample_app, '_run_repl')
orchestrator = Orchestrator(arg_parser=mock_argparser, custom_providers=[custom_provider]) orchestrator = Orchestrator(arg_parser=mock_argparser, custom_providers=[custom_provider])
orchestrator.start_polling(sample_app) orchestrator.run_repl(sample_app)
# Check that custom_provider was passed to make_container # Check that custom_provider was passed to make_container
call_args = mock_make_container.call_args[0] call_args = mock_make_container.call_args[0]
@@ -180,14 +179,14 @@ def test_orchestrator_integrates_with_app_with_router(
"""Test that Orchestrator properly integrates with App that has routers""" """Test that Orchestrator properly integrates with App that has routers"""
mocker.patch('argenta.orchestrator.entity.make_container') mocker.patch('argenta.orchestrator.entity.make_container')
mocker.patch('argenta.orchestrator.entity.setup_dishka') mocker.patch('argenta.orchestrator.entity.setup_dishka')
mock_run_polling = mocker.patch.object(sample_app, '_run_polling') mock_run_repl = mocker.patch.object(sample_app, '_run_repl')
sample_app.include_router(sample_router) sample_app.include_router(sample_router)
orchestrator = Orchestrator(arg_parser=mock_argparser) orchestrator = Orchestrator(arg_parser=mock_argparser)
orchestrator.start_polling(sample_app) orchestrator.run_repl(sample_app)
mock_run_polling.assert_called_once() mock_run_repl.assert_called_once()
assert len(sample_app.registered_routers.registered_routers) == 1 assert len(sample_app.registered_routers.registered_routers) == 1
@@ -202,10 +201,10 @@ def test_orchestrator_passes_argparser_to_container_context(
"""Test that Orchestrator passes ArgParser instance to container context""" """Test that Orchestrator passes ArgParser instance to container context"""
mock_make_container = mocker.patch('argenta.orchestrator.entity.make_container') mock_make_container = mocker.patch('argenta.orchestrator.entity.make_container')
mocker.patch('argenta.orchestrator.entity.setup_dishka') mocker.patch('argenta.orchestrator.entity.setup_dishka')
mocker.patch.object(sample_app, '_run_polling') mocker.patch.object(sample_app, '_run_repl')
orchestrator = Orchestrator(arg_parser=mock_argparser) orchestrator = Orchestrator(arg_parser=mock_argparser)
orchestrator.start_polling(sample_app) orchestrator.run_repl(sample_app)
# Verify that ArgParser was passed in context # Verify that ArgParser was passed in context
call_kwargs = mock_make_container.call_args[1] call_kwargs = mock_make_container.call_args[1]
@@ -219,18 +218,18 @@ def test_orchestrator_passes_argparser_to_container_context(
# ============================================================================ # ============================================================================
def test_orchestrator_handles_app_run_polling_exception( def test_orchestrator_handles_app_run_repl_exception(
mocker: MockerFixture, mock_argparser: ArgParser, sample_app: App mocker: MockerFixture, mock_argparser: ArgParser, sample_app: App
) -> None: ) -> None:
"""Test that Orchestrator propagates exceptions from app.run_polling()""" """Test that Orchestrator propagates exceptions from app.run_polling()"""
mocker.patch('argenta.orchestrator.entity.make_container') mocker.patch('argenta.orchestrator.entity.make_container')
mocker.patch('argenta.orchestrator.entity.setup_dishka') mocker.patch('argenta.orchestrator.entity.setup_dishka')
mocker.patch.object(sample_app, '_run_polling', side_effect=RuntimeError("Test error")) mocker.patch.object(sample_app, '_run_repl', side_effect=RuntimeError("Test error"))
orchestrator = Orchestrator(arg_parser=mock_argparser) orchestrator = Orchestrator(arg_parser=mock_argparser)
with pytest.raises(RuntimeError, match="Test error"): with pytest.raises(RuntimeError, match="Test error"):
orchestrator.start_polling(sample_app) orchestrator.run_repl(sample_app)
# ============================================================================ # ============================================================================
@@ -246,13 +245,13 @@ def test_orchestrator_accepts_multiple_custom_providers(
provider2 = Provider() provider2 = Provider()
mock_make_container = mocker.patch('argenta.orchestrator.entity.make_container') mock_make_container = mocker.patch('argenta.orchestrator.entity.make_container')
mocker.patch('argenta.orchestrator.entity.setup_dishka') mocker.patch('argenta.orchestrator.entity.setup_dishka')
mocker.patch.object(sample_app, '_run_polling') mocker.patch.object(sample_app, '_run_repl')
orchestrator = Orchestrator( orchestrator = Orchestrator(
arg_parser=mock_argparser, arg_parser=mock_argparser,
custom_providers=[provider1, provider2] custom_providers=[provider1, provider2]
) )
orchestrator.start_polling(sample_app) orchestrator.run_repl(sample_app)
call_args = mock_make_container.call_args[0] call_args = mock_make_container.call_args[0]
assert provider1 in call_args assert provider1 in call_args