當前位置: 首頁>>代碼示例>>Python>>正文


Python World.emitterFor方法代碼示例

本文整理匯總了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")
開發者ID:iffy,項目名稱:xatrobots,代碼行數:35,代碼來源:test_world.py

示例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'))
開發者ID:iffy,項目名稱:xatrobots,代碼行數:9,代碼來源:test_world.py

示例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, [])
開發者ID:iffy,項目名稱:xatrobots,代碼行數:30,代碼來源:test_world.py

示例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')
開發者ID:iffy,項目名稱:xatrobots,代碼行數:18,代碼來源:test_world.py


注:本文中的xatro.world.World.emitterFor方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。