当前位置: 首页>>代码示例>>Python>>正文


Python SocketManager.create方法代码示例

本文整理汇总了Python中agentzero.core.SocketManager.create方法的典型用法代码示例。如果您正苦于以下问题:Python SocketManager.create方法的具体用法?Python SocketManager.create怎么用?Python SocketManager.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在agentzero.core.SocketManager的用法示例。


在下文中一共展示了SocketManager.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_socket_manager_raises_exception_when_creating_existing_socket

# 需要导入模块: from agentzero.core import SocketManager [as 别名]
# 或者: from agentzero.core.SocketManager import create [as 别名]
def test_socket_manager_raises_exception_when_creating_existing_socket():
    ("SocketManager().create() should raise AgentZeroSocketError when "
     "a given socket already exists")

    # Given a zmq mock
    zmq = Mock()

    # And a context
    context = Mock()

    # And a socket manager
    manager = SocketManager(zmq, context)

    # And a couple of sockets
    manager.create('foo', zmq.REQ)
    manager.create('bar', zmq.PUB)

    # When I call create on an existing socket name
    when_called = manager.create.when.called_with('foo', zmq.PUB)

    # Then it should have
    when_called.should.have.raised(
        SocketAlreadyExists,
        "SocketManager(sockets=['foo', 'bar']) already has a socket named 'foo'"
    )
开发者ID:adamchainz,项目名称:agentzero,代码行数:27,代码来源:test_socket_manager.py

示例2: test_socket_manager_raises_exception_when_retrieving_socket_with_bad_name

# 需要导入模块: from agentzero.core import SocketManager [as 别名]
# 或者: from agentzero.core.SocketManager import create [as 别名]
def test_socket_manager_raises_exception_when_retrieving_socket_with_bad_name():
    ("SocketManager().get_by_name() should raise AgentZeroSocketError when "
     "a given socket does not exist")

    # Given a zmq mock
    zmq = Mock()

    # And a context
    context = Mock()

    # And a socket manager
    manager = SocketManager(zmq, context)

    # And a couple of sockets
    manager.create('foo', zmq.REQ)
    manager.create('bar', zmq.PUB)

    # When I call get_by_name with an unexpected name
    when_called = manager.get_by_name.when.called_with('boom')

    # Then it should have
    when_called.should.have.raised(
        SocketNotFound,
        "SocketManager(sockets=['foo', 'bar']) has no sockets named 'boom'."
    )
开发者ID:adamchainz,项目名称:agentzero,代码行数:27,代码来源:test_socket_manager.py

示例3: Pipeline

# 需要导入模块: from agentzero.core import SocketManager [as 别名]
# 或者: from agentzero.core.SocketManager import create [as 别名]
class Pipeline(object):
    steps = []

    def __init__(self):
        self.context = zmq.Context()
        self.sockets = SocketManager(zmq, self.context)
        self.sockets.create("pipe-sub", zmq.SUB)
        self.sockets.create("pipe-in", zmq.PULL)
        self.sockets.create("pipe-out", zmq.PUSH)
        self.children = []
开发者ID:gabrielfalcao,项目名称:agentzero,代码行数:12,代码来源:guide01-pipeline.py

示例4: test_socket_manager_send_safe_not_ready

# 需要导入模块: from agentzero.core import SocketManager [as 别名]
# 或者: from agentzero.core.SocketManager import create [as 别名]
def test_socket_manager_send_safe_not_ready():
    ("SocketManager.send_safe should return False when the socket is not ready")

    # Given a manager
    manager = SocketManager(zmq, context)

    # And a couple of sockets
    manager.create('foo', zmq.REP)

    # When I call .send_safe()
    result = manager.send_safe('foo', {'some': 'value'})

    # Then it should be false
    result.should.be.false
开发者ID:adamchainz,项目名称:agentzero,代码行数:16,代码来源:test_socket_manager.py

示例5: test_socket_manager_send_safe

# 需要导入模块: from agentzero.core import SocketManager [as 别名]
# 或者: from agentzero.core.SocketManager import create [as 别名]
def test_socket_manager_send_safe(wait_until_ready):
    ("SocketManager().send_safe() should serialize "
     "before sending, using the configured backend")

    # Background: wait_until_ready is mocked to return the socket
    wait_until_ready.side_effect = lambda name, *args: manager.sockets[name]

    # Given a zmq mock
    zmq = Mock()

    # And a context
    context = Mock()

    # And a serializer
    serializer = Mock(name='serializer')

    # And a socket manager
    manager = SocketManager(zmq, context, serialization_backend=serializer)

    # And a socket
    socket = manager.create('foobar', zmq.REP)

    # When I call .send_safe()
    sent = manager.send_safe('foobar', 'PAYLOAD')

    # Then it should have sent successfully
    sent.should.be.true

    # And it should have packed the payload before sending
    serializer.pack.assert_called_once_with('PAYLOAD')
    packed = serializer.pack.return_value

    socket.send.assert_called_once_with(packed)
开发者ID:adamchainz,项目名称:agentzero,代码行数:35,代码来源:test_socket_manager.py

示例6: test_socket_manager_subscribe_invalid_callable

# 需要导入模块: from agentzero.core import SocketManager [as 别名]
# 或者: from agentzero.core.SocketManager import create [as 别名]
def test_socket_manager_subscribe_invalid_callable(get_by_name):
    (
        "SocketManager().subscribe() should raise TypeError "
        "if the keep_polling callable is not callable"
    )

    # Background: wait_until_ready is mocked to return the socket
    socket = get_by_name.return_value
    socket.recv_multipart.return_value = ["metrics:whatevs", "the-data"]

    # Given a zmq mock
    zmq = Mock()

    # And a context
    context = Mock()

    # And a serializer
    serializer = Mock(name="serializer")

    # And a socket manager
    manager = SocketManager(zmq, context, serialization_backend=serializer)

    # And a socket
    socket = manager.create("foobar", zmq.REP)

    # When I perform one iteration in the subscriber
    when_called = list.when.called_with(
        manager.subscribe("foobar", keep_polling="not a callable")
    )
    when_called.should.have.raised(
        TypeError,
        "SocketManager.subscribe parameter keep_polling must be a function or callable that returns a boolean",
    )
开发者ID:gabrielfalcao,项目名称:agentzero,代码行数:35,代码来源:test_socket_manager.py

示例7: test_socket_manager_recv_safe

# 需要导入模块: from agentzero.core import SocketManager [as 别名]
# 或者: from agentzero.core.SocketManager import create [as 别名]
def test_socket_manager_recv_safe(wait_until_ready):
    ("SocketManager().recv_safe() should deserialize "
     "after receiving, using the configured backend")

    # Background: wait_until_ready is mocked to return the socket
    wait_until_ready.side_effect = lambda name, *args: manager.sockets[name]

    # Given a zmq mock
    zmq = Mock()

    # And a context
    context = Mock()

    # And a serializer
    serializer = Mock(name='serializer')

    # And a socket manager
    manager = SocketManager(zmq, context, serialization_backend=serializer)

    # And a socket
    socket = manager.create('foobar', zmq.REP)

    # When I call .recv_safe()
    result = manager.recv_safe('foobar')

    # Then it should have unpacked the payload after receiving
    serializer.unpack.assert_called_once_with(socket.recv.return_value)

    # And the result should be the unpacked value
    result.should.equal(serializer.unpack.return_value)
开发者ID:adamchainz,项目名称:agentzero,代码行数:32,代码来源:test_socket_manager.py

示例8: test_socket_manager_publish_safe

# 需要导入模块: from agentzero.core import SocketManager [as 别名]
# 或者: from agentzero.core.SocketManager import create [as 别名]
def test_socket_manager_publish_safe():
    ("SocketManager().publish_safe() should serialize "
     "before sending, using the configured backend")

    # Given a zmq mock
    zmq = Mock()

    # And a context
    context = Mock()

    # And a serializer
    serializer = Mock(name='serializer')

    # And a socket manager
    manager = SocketManager(zmq, context, serialization_backend=serializer)

    # And a socket
    socket = manager.create('foobar', zmq.REP)

    # When I call .publish_safe()
    manager.publish_safe('foobar', 'topic', 'PAYLOAD')

    # Then it should have packed the payload before sending
    serializer.pack.assert_called_once_with('PAYLOAD')
    packed = serializer.pack.return_value

    socket.send_multipart.assert_called_once_with(['topic', packed])
开发者ID:adamchainz,项目名称:agentzero,代码行数:29,代码来源:test_socket_manager.py

示例9: test_socket_manager_publish_safe

# 需要导入模块: from agentzero.core import SocketManager [as 别名]
# 或者: from agentzero.core.SocketManager import create [as 别名]
def test_socket_manager_publish_safe():
    (
        "SocketManager().publish_safe() should serialize "
        "before sending, using the configured backend"
    )

    # Given a zmq mock
    zmq = Mock()

    # And a context
    context = Mock()

    # And a serializer
    serializer = Mock(name="serializer")
    serializer.pack.side_effect = lambda x: "<pac({})ked>".format(repr(x))
    # And a socket manager
    manager = SocketManager(zmq, context, serialization_backend=serializer)

    # And a socket
    socket = manager.create("foobar", zmq.REP)

    # When I call .publish_safe()
    manager.publish_safe("foobar", "topic", "PAYLOAD")

    # Then it should have packed the payload before sending
    serializer.pack.assert_called_once_with("PAYLOAD")
    serializer.pack.return_value = "packed"

    socket.send_multipart.assert_called_once_with(
        [cast_bytes("topic"), cast_bytes("<pac('PAYLOAD')ked>")]
    )
开发者ID:gabrielfalcao,项目名称:agentzero,代码行数:33,代码来源:test_socket_manager.py

示例10: test_socket_manager_recv_event_safe_no_topic

# 需要导入模块: from agentzero.core import SocketManager [as 别名]
# 或者: from agentzero.core.SocketManager import create [as 别名]
def test_socket_manager_recv_event_safe_no_topic(wait_until_ready, set_topic):
    ("SocketManager().recv_event_safe() should raise an exeption when the topic is not a string")

    # Background: wait_until_ready is mocked to return the socket
    wait_until_ready.side_effect = lambda name, *args: manager.sockets[name]

    # Given a zmq mock
    zmq = Mock()

    # And a context
    context = Mock()

    # And a serializer
    serializer = Mock(name='serializer')

    # And a socket manager
    manager = SocketManager(zmq, context, serialization_backend=serializer)

    # And a socket
    socket = manager.create('foobar', zmq.REP)
    socket.recv_multipart.return_value = b'a fake topic', 'the-raw-payload'

    # When I call .recv_event_safe()
    when_called = manager.recv_event_safe.when.called_with('foobar', topic={'boom'})

    # Then it should have raised and exception
    when_called.should.have.raised(
        TypeError,
        "recv_event_safe() takes a string, None "
        "or False as argument, received "
        "set(['boom'])(<type 'set'>) instead"
    )
开发者ID:adamchainz,项目名称:agentzero,代码行数:34,代码来源:test_socket_manager.py

示例11: test_socket_manager_recv_event_safe_missing_socket

# 需要导入模块: from agentzero.core import SocketManager [as 别名]
# 或者: from agentzero.core.SocketManager import create [as 别名]
def test_socket_manager_recv_event_safe_missing_socket(wait_until_ready, set_topic):
    ("SocketManager().recv_event_safe() should return None when the socket is not ready")

    # Background: wait_until_ready is mocked to return None
    wait_until_ready.return_value = None

    # Given a zmq mock
    zmq = Mock()

    # And a context
    context = Mock()

    # And a serializer
    serializer = Mock(name='serializer')

    # And a socket manager
    manager = SocketManager(zmq, context, serialization_backend=serializer)

    # And a socket
    socket = manager.create('foobar', zmq.REP)
    socket.recv_multipart.return_value = b'a fake topic', 'the-raw-payload'

    # When I call .recv_event_safe()
    result = manager.recv_event_safe('foobar', topic=b'helloworld')

    # And the result should be None
    result.should.be.none
开发者ID:adamchainz,项目名称:agentzero,代码行数:29,代码来源:test_socket_manager.py

示例12: test_socket_manager_recv_event_safe

# 需要导入模块: from agentzero.core import SocketManager [as 别名]
# 或者: from agentzero.core.SocketManager import create [as 别名]
def test_socket_manager_recv_event_safe(wait_until_ready, set_topic):
    ("SocketManager().recv_event_safe() should set the topic "
     "on the given socket, wait for data to become available "
     "and return it")

    # Background: wait_until_ready is mocked to return the socket
    wait_until_ready.side_effect = lambda name, *args: manager.sockets[name]

    # Given a zmq mock
    zmq = Mock()

    # And a context
    context = Mock()

    # And a serializer
    serializer = Mock(name='serializer')

    # And a socket manager
    manager = SocketManager(zmq, context, serialization_backend=serializer)

    # And a socket
    socket = manager.create('foobar', zmq.REP)
    socket.recv_multipart.return_value = b'a fake topic', 'the-raw-payload'

    # When I call .recv_event_safe()
    result = manager.recv_event_safe('foobar', topic=b'helloworld')

    # Then it should have unpacked the payload after receiving
    serializer.unpack.assert_called_once_with('the-raw-payload')

    # And the result should be the unpacked value
    result.should.be.an(Event)
开发者ID:adamchainz,项目名称:agentzero,代码行数:34,代码来源:test_socket_manager.py

示例13: test_socket_manager_subscribe

# 需要导入模块: from agentzero.core import SocketManager [as 别名]
# 或者: from agentzero.core.SocketManager import create [as 别名]
def test_socket_manager_subscribe(get_by_name):
    ("SocketManager().subscribe() should yield the topic and ")

    # Background: wait_until_ready is mocked to return the socket
    socket = get_by_name.return_value
    socket.recv_multipart.return_value = ['metrics:whatevs', 'the-data']

    # Given a zmq mock
    zmq = Mock()

    # And a context
    context = Mock()

    # And a serializer
    serializer = Mock(name='serializer')

    # And a socket manager
    manager = SocketManager(zmq, context, serialization_backend=serializer)

    # And a socket
    socket = manager.create('foobar', zmq.REP)

    # When I perform one iteration in the subscriber
    topic, payload = next(manager.subscribe('foobar'))

    # Then it should have unpacked the payload after receiving
    serializer.unpack.assert_called_once_with('the-data')

    # And the result should be the unpacked value
    payload.should.equal(serializer.unpack.return_value)

    # And the topic should be the expected
    topic.should.equal('metrics:whatevs')
开发者ID:adamchainz,项目名称:agentzero,代码行数:35,代码来源:test_socket_manager.py

示例14: test_socket_manager_subscribe

# 需要导入模块: from agentzero.core import SocketManager [as 别名]
# 或者: from agentzero.core.SocketManager import create [as 别名]
def test_socket_manager_subscribe():
    ("SocketManager.subscribe should subscribe from a topic")

    # Given a manager
    manager = SocketManager(zmq, context)

    # And a couple of sockets
    manager.ensure_and_bind('foo', zmq.PUB, 'inproc://test.publisher.2', zmq.POLLOUT)
    manager.create('bar', zmq.SUB)
    manager.connect('bar', 'inproc://test.publisher.2', zmq.POLLIN)

    gevent.spawn(manager.publish_safe, 'foo', 'some-topic', {'some': 'value'})

    # Then it should have received
    topic, result = next(manager.subscribe('bar'))
    topic.should.equal('some-topic')
    result.should.equal({'some': 'value'})
开发者ID:adamchainz,项目名称:agentzero,代码行数:19,代码来源:test_socket_manager.py

示例15: test_socket_create

# 需要导入模块: from agentzero.core import SocketManager [as 别名]
# 或者: from agentzero.core.SocketManager import create [as 别名]
def test_socket_create():
    ("SocketManager().create() should create a socket")

    # Given a zmq mock
    zmq = Mock()

    # And a context
    context = Mock()

    # And a socket manager
    manager = SocketManager(zmq, context)

    # When I create a socket
    manager.create('foobar', 'SOME_SOCKET_TYPE')

    # Then it should have been added to the socket pool
    manager.sockets.should.have.key("foobar")
    manager.sockets["foobar"].should.equal(context.socket.return_value)

    # And the socket should have been created with the given type
    context.socket.assert_called_once_with('SOME_SOCKET_TYPE')
开发者ID:adamchainz,项目名称:agentzero,代码行数:23,代码来源:test_socket_manager.py


注:本文中的agentzero.core.SocketManager.create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。