def __init__( self, policies: Optional[Sequence[PolicyType]] = None, cascade: Optional[HandlerFactoryCascade] = None, modifiers: Sequence[ModifierFactory] = (), sync_mode: bool = False, ): """ Initializes local event bus with given specification. :param policies: (optional) sequence of policies to be used as recipe to convert raw objects into handlers; if not provided default `CallableHandlerPolicy` will be used; overwritten when cascade is provided :param cascade: (optional) custom handler factory cascade to customize policy into handler factory mapping :param modifiers: sequence of modifiers to be applied on new handler entries """ scheduler_store = _EventSchedulerHandlerStore(sync_mode=sync_mode) HandlerRegistry.__init__( self, store=scheduler_store, policies=policies or [CallableHandlerPolicy()], cascade=cascade, modifiers=modifiers, ) self._scheduler = scheduler_store
def __init__( self, policies: Optional[Sequence[PolicyType]] = None, cascade: Optional[HandlerFactoryCascade] = None, modifiers: Sequence[ModifierFactory] = (), ): """ Initializes event handler registry. :param policies: (optional) sequence of policies to be used as recipe to convert raw objects into handlers; if not provided default CallableHandlerPolicy is used; overwritten when cascade is provided :param cascade: (optional/advanced) custom handler factory cascade to customize policy into handler factory mapping :param modifiers: sequence of modifiers to be applied on new handler entries """ HandlerRegistry.__init__( self, store=CollectionHandlerStore(), policies=policies or [CallableHandlerPolicy()], cascade=cascade, modifiers=modifiers, )
def _registry_cascade_factory(): return HandlerRegistry( store=CollectionHandlerStore(), cascade=HandlerFactoryCascade( policies=[CallableHandlerPolicy()], mapper=DefaultHandlerFactoryMapper(), ), )
async def test_handler_modifiers( global_modifiers: Sequence[ModifierFactory], local_modifiers: Sequence[ModifierFactory], seq: Sequence[str], mockup_action_factory: Callable[[], ActionSubject], ): registry = HandlerRegistry( store=CollectionHandlerStore(), policies=[CallableHandlerPolicy()], modifiers=global_modifiers, ) registry.register(_return_seq, modifiers=local_modifiers) registry.register(modifiers=local_modifiers)(_return_seq) for entry in registry: call = entry.handler_pipeline() result = await call(mockup_action_factory()) assert result.result == seq
def _registry_policies_factory(): return HandlerRegistry( store=CollectionHandlerStore(), policies=[CallableHandlerPolicy()], )
def test_handler_registry_config_error(): with pytest.raises(TypeError): HandlerRegistry(store=CollectionHandlerStore())