本文整理汇总了Python中agentzero.core.SocketManager.subscribe方法的典型用法代码示例。如果您正苦于以下问题:Python SocketManager.subscribe方法的具体用法?Python SocketManager.subscribe怎么用?Python SocketManager.subscribe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类agentzero.core.SocketManager
的用法示例。
在下文中一共展示了SocketManager.subscribe方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_socket_manager_subscribe_invalid_callable
# 需要导入模块: from agentzero.core import SocketManager [as 别名]
# 或者: from agentzero.core.SocketManager import subscribe [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",
)
示例2: test_socket_manager_subscribe
# 需要导入模块: from agentzero.core import SocketManager [as 别名]
# 或者: from agentzero.core.SocketManager import subscribe [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')
示例3: test_socket_manager_subscribe
# 需要导入模块: from agentzero.core import SocketManager [as 别名]
# 或者: from agentzero.core.SocketManager import subscribe [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'})
示例4: test_socket_manager_subscribe
# 需要导入模块: from agentzero.core import SocketManager [as 别名]
# 或者: from agentzero.core.SocketManager import subscribe [as 别名]
def test_socket_manager_subscribe(get_by_name):
("SocketManager().subscribe() should yield the topic and yield an Event")
# Background: wait_until_ready is mocked to return the socket
socket = Mock(name='<socket(name="foobar")>')
get_by_name.side_effect = [socket, socket, socket, socket, socket, None]
socket.recv_multipart.side_effect = [
["metrics:whatevs", "the-data"],
["action", "test"],
]
# 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
events = list(manager.subscribe("foobar"))
events.should.have.length_of(2)
event1, event2 = events
topic1, payload1 = event1.topic, event1.data
# Then it should have unpacked the payload after receiving
serializer.unpack.assert_has_calls([call("the-data"), call("test")])
# And the result should be the unpacked value
payload1.should.equal(serializer.unpack.return_value)
# And the topic should be the expected
topic1.should.equal("metrics:whatevs")
event2.should.be.an(Event)