mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 18:15:28 +03:00
rename orchestrator method start_polling to run_repl
This commit is contained in:
@@ -45,12 +45,11 @@ def sample_router() -> Router:
|
||||
# ============================================================================
|
||||
|
||||
|
||||
def test_orchestrator_initializes_with_default_argparser(mocker: MockerFixture) -> None:
|
||||
"""Test Orchestrator initialization with default ArgParser"""
|
||||
def test_orchestrator_initializes_with_no_argparser(mocker: MockerFixture) -> None:
|
||||
"""Test Orchestrator initialization with no ArgParser"""
|
||||
mocker.patch('sys.argv', ['test_program'])
|
||||
orchestrator = Orchestrator()
|
||||
assert orchestrator._arg_parser is not None
|
||||
assert isinstance(orchestrator._arg_parser, ArgParser)
|
||||
assert orchestrator._arg_parser is 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
|
||||
) -> 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_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.start_polling(sample_app)
|
||||
orchestrator.run_repl(sample_app)
|
||||
|
||||
mock_make_container.assert_called_once()
|
||||
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
|
||||
) -> 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]
|
||||
mocker.patch('argenta.orchestrator.entity.make_container', return_value=mock_container)
|
||||
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.start_polling(sample_app)
|
||||
orchestrator.run_repl(sample_app)
|
||||
|
||||
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
|
||||
) -> 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]
|
||||
mocker.patch('argenta.orchestrator.entity.make_container', return_value=mock_container)
|
||||
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.start_polling(sample_app)
|
||||
orchestrator.run_repl(sample_app)
|
||||
|
||||
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
|
||||
) -> 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.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.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
|
||||
) -> None:
|
||||
"""Test that start_polling includes custom providers in container"""
|
||||
"""Test that run_repl includes custom providers in container"""
|
||||
custom_provider = Provider()
|
||||
mock_make_container = mocker.patch('argenta.orchestrator.entity.make_container')
|
||||
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.start_polling(sample_app)
|
||||
orchestrator.run_repl(sample_app)
|
||||
|
||||
# Check that custom_provider was passed to make_container
|
||||
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"""
|
||||
mocker.patch('argenta.orchestrator.entity.make_container')
|
||||
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)
|
||||
|
||||
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
|
||||
|
||||
|
||||
@@ -202,10 +201,10 @@ def test_orchestrator_passes_argparser_to_container_context(
|
||||
"""Test that Orchestrator passes ArgParser instance to container context"""
|
||||
mock_make_container = mocker.patch('argenta.orchestrator.entity.make_container')
|
||||
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.start_polling(sample_app)
|
||||
orchestrator.run_repl(sample_app)
|
||||
|
||||
# Verify that ArgParser was passed in context
|
||||
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
|
||||
) -> None:
|
||||
"""Test that Orchestrator propagates exceptions from app.run_polling()"""
|
||||
mocker.patch('argenta.orchestrator.entity.make_container')
|
||||
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)
|
||||
|
||||
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()
|
||||
mock_make_container = mocker.patch('argenta.orchestrator.entity.make_container')
|
||||
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=[provider1, provider2]
|
||||
)
|
||||
orchestrator.start_polling(sample_app)
|
||||
orchestrator.run_repl(sample_app)
|
||||
|
||||
call_args = mock_make_container.call_args[0]
|
||||
assert provider1 in call_args
|
||||
|
||||
Reference in New Issue
Block a user