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


Python World.destroy方法代码示例

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


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

示例1: test_destroy_disableSubscribers

# 需要导入模块: from xatro.world import World [as 别名]
# 或者: from xatro.world.World import destroy [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

示例2: test_envelope_ids

# 需要导入模块: from xatro.world import World [as 别名]
# 或者: from xatro.world.World import destroy [as 别名]
    def test_envelope_ids(self):
        """
        You can read/write on the envelope of things in the world (using their
        id).
        """
        world = World(MagicMock())
        obj_id = world.create('foo')['id']
        env = world.envelope(obj_id)
        self.assertTrue(isinstance(env, dict))
        env['foo'] = 'bar'

        # destruction should destroy the envelope too
        world.destroy(obj_id)
        self.assertRaises(KeyError, world.envelope, obj_id)
开发者ID:iffy,项目名称:xatrobots,代码行数:16,代码来源:test_world.py

示例3: test_energyDestroyed

# 需要导入模块: from xatro.world import World [as 别名]
# 或者: from xatro.world.World import destroy [as 别名]
    def test_energyDestroyed(self):
        """
        When energy is destroyed, it should decrement the creator's
        created_energy amount.
        """
        world = World(MagicMock())
        thing = world.create('thing')

        Charge(thing['id']).execute(world)

        energy = thing['energy'][0]
        world.destroy(energy)

        self.assertEqual(thing['energy'], [], "Should remove the energy from "
                         "the energy list of the user")
        self.assertEqual(thing['created_energy'], 0, "Should decrement "
                         "the created_energy attribute")
开发者ID:iffy,项目名称:xatrobots,代码行数:19,代码来源:test_action.py

示例4: test_destroy

# 需要导入模块: from xatro.world import World [as 别名]
# 或者: from xatro.world.World import destroy [as 别名]
    def test_destroy(self):
        """
        You can destroy an object, and be notified about it.
        """
        ev = MagicMock()
        world = World(ev)
        obj = world.create('foo')

        ev.reset_mock()
        called = []
        world.receiveFor(obj['id'], called.append)

        world.destroy(obj['id'])

        ev.assert_any_call(Destroyed(obj['id']))
        self.assertEqual(called, [Destroyed(obj['id'])], "Should notify things"
                         " receiving events for the object")
        self.assertNotIn(obj['id'], world.objects)
开发者ID:iffy,项目名称:xatrobots,代码行数:20,代码来源:test_world.py

示例5: test_sharedEnergy_destroyed

# 需要导入模块: from xatro.world import World [as 别名]
# 或者: from xatro.world.World import destroy [as 别名]
    def test_sharedEnergy_destroyed(self):
        """
        When shared energy is destroyed, it should be removed from the
        energy pool of whoever has it and still decrement the creator's
        created_energy amount.
        """
        world = World(MagicMock())
        giver = world.create('thing')
        receiver = world.create('thing')

        Charge(giver['id']).execute(world)
        ShareEnergy(giver['id'], receiver['id'], 1).execute(world)

        e = receiver['energy'][0]
        world.destroy(e)

        self.assertEqual(giver['created_energy'], 0,
                         "Should decrement creator's created count")
        self.assertEqual(len(receiver['energy']), 0,
                         "Should deplete receiver's energy")
开发者ID:iffy,项目名称:xatrobots,代码行数:22,代码来源:test_action.py

示例6: UsePortalTest

# 需要导入模块: from xatro.world import World [as 别名]
# 或者: from xatro.world.World import destroy [as 别名]
class UsePortalTest(TestCase):


    def test_IAction(self):
        verifyObject(IAction, UsePortal('me', 'portal_id'))


    def test_emitters(self):
        self.assertEqual(UsePortal('me', 'portal_id').emitters(), ['me'])


    def test_subject(self):
        self.assertEqual(UsePortal('foo', 'bar').subject(), 'foo')


    def usedPortal(self):
        self.world = World(MagicMock())
        self.place = self.world.create('place')
        self.ore = self.world.create('ore')
        self.bot = self.world.create('bot')
        self.lander = self.world.create('lander')
        
        Move(self.ore['id'], self.place['id']).execute(self.world)
        OpenPortal(self.bot['id'], self.ore['id'],
                   self.lander['id']).execute(self.world)
        UsePortal(self.lander['id'], self.ore['id']).execute(self.world)


    def test_use(self):
        """
        Using a portal will cause the thing that used it to be moved to the
        location where the portal is, remove the portal_user attribute from
        the portal.
        """
        self.usedPortal()
        lander = self.lander
        ore = self.ore

        self.assertEqual(lander['location'], ore['location'], "Should move "
                         "the lander into the location")


    def test_portalDestroyed(self):
        """
        If a portal is destroyed, the user of the portal is sent to the void.
        """
        self.usedPortal()

        # destroy the portal
        self.world.destroy(self.ore['id'])

        self.assertEqual(self.lander['location'], None, "Should send lander "
                         "to the void")


    def test_portalKilled(self):
        """
        If a portal is killed (by hp reaching 0) the user of the portal is sent
        to the void and the portal reverts to ore.
        """
        self.usedPortal()

        # kill the portal
        self.world.setAttr(self.ore['id'], 'hp', 0)

        self.assertEqual(self.lander['location'], None, "Should send lander "
                         "to the void")
        self.assertEqual(self.ore['kind'], 'ore', "Should revert to ore")
        self.assertNotIn('portal_user', self.ore, "Should delete portal_user "
                         "attribute")


    def test_portal_user_noMatch(self):
        """
        It is NotAllowed to use a portal with a portal_user different than the
        thing trying to use the portal.
        """
        world = World(MagicMock())
        place = world.create('place')
        ore = world.create('ore')
        bot = world.create('bot')
        lander = world.create('lander')
        imposter = world.create('imposter')
        
        Move(ore['id'], place['id']).execute(world)
        OpenPortal(bot['id'], ore['id'],
                   lander['id']).execute(world)
        self.assertRaises(NotAllowed,
                          UsePortal(imposter['id'], ore['id']).execute, world)


    def test_openerDiesAfterUse(self):
        """
        If the opener dies or is destroyed AFTER a portal is used, it should
        not affect the portal.
        """
        self.usedPortal()

        # kill the opener (send them to the void)
        Move(self.bot['id'], None).execute(self.world)
#.........这里部分代码省略.........
开发者ID:iffy,项目名称:xatrobots,代码行数:103,代码来源:test_action.py


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