예제 #1
0
def test_canonshortname():
    class X:
        ...

    X.__module__ = "__main__"
    x = X()

    class Y:
        ...

    y = Y()

    assert canonshortname(X, main_name="faust") == "faust.X"
    assert canonshortname(x, main_name="faust") == "faust.X"
    assert canonshortname(Y, main_name="faust") == ".".join([
        __name__,
        "Y",
    ])
    assert canonshortname(y, main_name="faust") == ".".join([
        __name__,
        "Y",
    ])
예제 #2
0
def test_canonshortname():
    class X:
        ...

    X.__module__ = '__main__'
    x = X()

    class Y:
        ...

    y = Y()

    assert canonshortname(X, main_name='faust') == 'faust.X'
    assert canonshortname(x, main_name='faust') == 'faust.X'
    assert canonshortname(Y, main_name='faust') == '.'.join([
        __name__,
        'Y',
    ])
    assert canonshortname(y, main_name='faust') == '.'.join([
        __name__,
        'Y',
    ])
예제 #3
0
 def __init__(
     self,
     fun: AgentFun,
     *,
     app: AppT,
     name: str = None,
     channel: Union[str, ChannelT] = None,
     concurrency: int = 1,
     sink: Iterable[SinkT] = None,
     on_error: AgentErrorHandler = None,
     supervisor_strategy: Type[SupervisorStrategyT] = None,
     help: str = None,
     schema: SchemaT = None,
     key_type: ModelArg = None,
     value_type: ModelArg = None,
     isolated_partitions: bool = False,
     use_reply_headers: bool = None,
     **kwargs: Any,
 ) -> None:
     self.app = app
     self.fun: AgentFun = fun
     self.name = name or canonshortname(self.fun)
     # key-type/value_type arguments only apply when a channel
     # is not set
     if schema is not None:
         assert channel is None or isinstance(channel, str)
     if key_type is not None:
         assert channel is None or isinstance(channel, str)
     self._key_type = key_type
     if value_type is not None:
         assert channel is None or isinstance(channel, str)
     self._schema = schema
     self._value_type = value_type
     self._channel_arg = channel
     self._channel_kwargs = kwargs
     self.concurrency = concurrency or 1
     self.isolated_partitions = isolated_partitions
     self.help = help or ""
     self._sinks = list(sink) if sink is not None else []
     self._on_error: Optional[AgentErrorHandler] = on_error
     self.supervisor_strategy = supervisor_strategy
     self._actors = WeakSet()
     self._actor_by_partition = WeakValueDictionary()
     if self.isolated_partitions and self.concurrency > 1:
         raise ImproperlyConfigured(
             "Agent concurrency must be 1 when using isolated partitions"
         )
     self.use_reply_headers = use_reply_headers
     Service.__init__(self)