本文整理匯總了Python中xatro.world.World.emitterFor方法的典型用法代碼示例。如果您正苦於以下問題:Python World.emitterFor方法的具體用法?Python World.emitterFor怎麽用?Python World.emitterFor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類xatro.world.World
的用法示例。
在下文中一共展示了World.emitterFor方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_emit_receiveOnce
# 需要導入模塊: from xatro.world import World [as 別名]
# 或者: from xatro.world.World import emitterFor [as 別名]
def test_emit_receiveOnce(self):
"""
Events should only be received by each object once.
"""
world = World(MagicMock())
obj1 = world.create('foo')['id']
obj2 = world.create('foo')['id']
obj1_received = []
world.receiveFor(obj1, obj1_received.append)
obj2_received = []
world.receiveFor(obj2, obj2_received.append)
# obj1 emits everything it receives
world.receiveFor(obj1, world.emitterFor(obj1))
# obj2 emits everything it receives
world.receiveFor(obj2, world.emitterFor(obj2))
# obj2 receives emissions from obj1
world.subscribeTo(obj1, world.receiverFor(obj2))
# obj1 receives emissions from obj2
world.subscribeTo(obj2, world.receiverFor(obj1))
# we have a nice loop set up. When this test fails, it is likely to
# continue spinning forever.
world.emit('echo', obj1)
self.assertEqual(obj1_received, ['echo'], "Should have received the "
"message once")
self.assertEqual(obj2_received, ['echo'], "Should have received the "
"message once")
示例2: test_emitterFor_same
# 需要導入模塊: from xatro.world import World [as 別名]
# 或者: from xatro.world.World import emitterFor [as 別名]
def test_emitterFor_same(self):
"""
You should get the same function each time you ask for an emitter for
the same object.
"""
world = World(MagicMock())
self.assertEqual(world.emitterFor('foo'), world.emitterFor('foo'))
示例3: test_destroy_disableSubscribers
# 需要導入模塊: from xatro.world import World [as 別名]
# 或者: from xatro.world.World import emitterFor [as 別名]
def test_destroy_disableSubscribers(self):
"""
When an object is destroyed, things subscribed to its events will
no longer receive events.
"""
world = World(MagicMock())
thing = world.create('foo')
received = []
world.receiveFor(thing['id'], received.append)
emitted = []
world.subscribeTo(thing['id'], emitted.append)
receiver = world.receiverFor(thing['id'])
emitter = world.emitterFor(thing['id'])
world.destroy(thing['id'])
received.pop()
emitted.pop()
receiver('foo')
self.assertEqual(received, [])
self.assertEqual(emitted, [])
emitter('foo')
self.assertEqual(received, [])
self.assertEqual(emitted, [])
示例4: test_emitterFor
# 需要導入模塊: from xatro.world import World [as 別名]
# 或者: from xatro.world.World import emitterFor [as 別名]
def test_emitterFor(self):
"""
You can get a function that takes a single argument and emits events
for a particular object.
"""
ev1 = MagicMock()
world = World(ev1)
ev2 = MagicMock()
world.subscribeTo('1234', ev2)
emitter = world.emitterFor('1234')
emitter('foo')
ev1.assert_called_once_with('foo')
ev2.assert_called_once_with('foo')