コード例 #1
0
ファイル: local.py プロジェクト: dlski/python-mediator
 async def publish(self, obj: Any, **kwargs):
     """
     Publishes given event.
     :param obj: event object
     :param kwargs: event extra arguments
     """
     await self._scheduler.schedule(
         ActionSubject(subject=obj, inject=kwargs))
コード例 #2
0
 async def execute(self, obj: Any, **kwargs):
     """
     Executes given request.
     :param obj: request object
     :param kwargs: request extra arguments
     :raises LookupHandlerStoreError:
     when there is no matching handler to process given request
     :return: request processing result
     """
     result = await self._executor(ActionSubject(subject=obj,
                                                 inject=kwargs))
     assert isinstance(
         result, ActionResult
     ), "modifier or handler should provide `ActionResult` type object"
     return result.result
コード例 #3
0
ファイル: test_utils.py プロジェクト: dlski/python-mediator
async def test_direct_handler_create_successful(
    obj,
    sig,
    name: Optional[str],
    arg_map: Dict[str, str],
    expected_result,
):
    get_details = CallableObjDetails()
    arg_get = HandlerSubjectArgGet(name=name)
    handler_create = CallableHandlerCreate(
        subject_as_keyword=name is not None,
        arg_map=arg_map,
        arg_strict=True,
    )

    details = get_details(sig)
    arg = arg_get(details)
    details.obj = obj
    handler = handler_create(details, arg, obj)

    result = await handler(ActionSubject(subject="test", inject={"x": 1, "y": 2}))
    assert isinstance(result, ActionResult)
    assert result.result == expected_result
コード例 #4
0
ファイル: test_cascade.py プロジェクト: dlski/python-mediator
async def _check_handler_works(handler: Handler):
    result = await handler(ActionSubject(subject="test", inject={}))
    assert result.result == "test"
コード例 #5
0
def action():
    return ActionSubject(subject="test", inject={"a": 10, "b": 20})
コード例 #6
0
ファイル: conftest.py プロジェクト: dlski/python-mediator
 def create_action():
     return ActionSubject("test", inject={})
コード例 #7
0
def action():
    return ActionSubject(subject="test", inject={})
コード例 #8
0
 async def _op(action: ActionSubject):
     if "seq" not in action.inject:
         action.inject["seq"] = []
     seq = action.inject["seq"]
     seq.append(seq_item)
     return await call(action)
コード例 #9
0
async def _check_handler(handler: Handler):
    action = ActionSubject(subject="test", inject={"x": 1, "y": 2})
    result: ActionResult = await handler(action)
    assert result.result == ("test", 1, 2)