当前位置: 首页>>代码示例>>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;未经允许,请勿转载。