本文整理匯總了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, [])
示例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)
示例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")
示例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)
示例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")
示例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)
#.........這裏部分代碼省略.........