Add retry_utils, update docstrings, add tests

This commit is contained in:
2025-05-01 00:35:36 -04:00
parent b9529d85ce
commit 4b1a9ef718
10 changed files with 205 additions and 52 deletions

View File

@ -1,23 +1,12 @@
import pytest
from falyx.action import Action, ChainedAction, ActionGroup, FallbackAction
from falyx.action import Action, ChainedAction
from falyx.execution_registry import ExecutionRegistry as er
from falyx.hook_manager import HookManager, HookType
from falyx.context import ExecutionContext
from falyx.retry_utils import enable_retries_recursively
asyncio_default_fixture_loop_scope = "function"
# --- Helpers ---
async def capturing_hook(context: ExecutionContext):
context.extra["hook_triggered"] = True
# --- Fixtures ---
@pytest.fixture
def hook_manager():
hm = HookManager()
hm.register(HookType.BEFORE, capturing_hook)
return hm
@pytest.fixture(autouse=True)
def clean_registry():
er.clear()
@ -27,4 +16,19 @@ def clean_registry():
def test_action_enable_retry():
"""Test if Action can be created with retry=True."""
action = Action("test_action", lambda: "Hello, World!", retry=True)
assert action.retry_policy.enabled is True
assert action.retry_policy.enabled is True
@pytest.mark.asyncio
async def test_enable_retries_recursively():
"""Test if Action can be created with retry=True."""
action = Action("test_action", lambda: "Hello, World!")
assert action.retry_policy.enabled is False
chained_action = ChainedAction(
name="Chained Action",
actions=[action],
)
enable_retries_recursively(chained_action, policy=None)
assert action.retry_policy.enabled is True