本文整理汇总了Python中xatro.world.World.setAttr方法的典型用法代码示例。如果您正苦于以下问题:Python World.setAttr方法的具体用法?Python World.setAttr怎么用?Python World.setAttr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xatro.world.World
的用法示例。
在下文中一共展示了World.setAttr方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_makeSecondTool
# 需要导入模块: from xatro.world import World [as 别名]
# 或者: from xatro.world.World import setAttr [as 别名]
def test_makeSecondTool(self):
"""
If you make a tool from a different piece of ore, your existing tool
is unequipped and the lifesource it was made from is reverted to ore.
"""
world = World(MagicMock())
ore1 = world.create('ore')
ore2 = world.create('ore')
bot = world.create('bot')
MakeTool(bot['id'], ore1['id'], 'knife').execute(world)
MakeTool(bot['id'], ore2['id'], 'butterfly net').execute(world)
self.assertEqual(bot['tool'], 'butterfly net',
"Should equip the new tool")
self.assertEqual(ore1['kind'], 'ore', "Should revert to ore")
self.assertEqual(ore2['kind'], 'lifesource')
# kill original
world.setAttr(ore1['id'], 'hp', 0)
self.assertEqual(bot['tool'], 'butterfly net', "should not change tool"
" when the original ore dies")
self.assertEqual(ore2['kind'], 'lifesource')
示例2: test_execute
# 需要导入模块: from xatro.world import World [as 别名]
# 或者: from xatro.world.World import setAttr [as 别名]
def test_execute(self):
"""
Listing squares should return a list of all the things in the world
which are squares. It should include their coordinates and number of
each kind of thing inside them.
"""
world = World(MagicMock())
s1 = world.create('square')['id']
s2 = world.create('square')['id']
world.setAttr(s2, 'coordinates', (0, 1))
thing1 = world.create('thing')['id']
Move(thing1, s2).execute(world)
output = ListSquares(thing1).execute(world)
self.assertIn({
'id': s1,
'kind': 'square',
'coordinates': None,
'contents': {},
}, output)
self.assertIn({
'id': s2,
'kind': 'square',
'coordinates': (0, 1),
'contents': {
'thing': 1,
}
}, output)
self.assertEqual(len(output), 2)
示例3: test_stayAbove0
# 需要导入模块: from xatro.world import World [as 别名]
# 或者: from xatro.world.World import setAttr [as 别名]
def test_stayAbove0(self):
"""
You can't damage something below 0 by shooting.
"""
world = World(MagicMock())
thing = world.create('foo')
target = world.create('foo')
world.setAttr(target['id'], 'hp', 30)
Shoot(thing['id'], target['id'], 500).execute(world)
self.assertEqual(target['hp'], 0, "Should reduce the hitpoints to 0")
示例4: test_revertWhenKilled
# 需要导入模块: from xatro.world import World [as 别名]
# 或者: from xatro.world.World import setAttr [as 别名]
def test_revertWhenKilled(self):
"""
If the lifesource is shot to death, then revert to ore and unequip.
"""
world = World(MagicMock())
ore = world.create('ore')
bot = world.create('bot')
MakeTool(bot['id'], ore['id'], 'knife').execute(world)
world.setAttr(ore['id'], 'hp', 0)
self.assertNotIn('tool', bot, "Should unequip the tool")
self.assertEqual(ore['kind'], 'ore', "Should revert to ore")
示例5: test_invulnerable
# 需要导入模块: from xatro.world import World [as 别名]
# 或者: from xatro.world.World import setAttr [as 别名]
def test_invulnerable(self):
"""
You can't repair something that is invulnerable.
"""
world = World(MagicMock())
thing = world.create('foo')
target = world.create('foo')
self.assertRaises(Invulnerable,
Repair(thing['id'], target['id'], 500).execute, world)
world.setAttr(target['id'], 'hp', None)
self.assertRaises(Invulnerable,
Repair(thing['id'], target['id'], 500).execute, world)
示例6: test_onNextChange_cancel
# 需要导入模块: from xatro.world import World [as 别名]
# 或者: from xatro.world.World import setAttr [as 别名]
def test_onNextChange_cancel(self):
"""
You can cancel the deferred returned by onNextChange
"""
world = World(MagicMock())
obj = world.create('foo')
d = world.onNextChange(obj['id'], 'hey')
d.cancel()
world.setAttr(obj['id'], 'hey', 3)
self.assertFailure(d, defer.CancelledError)
示例7: test_delAttr
# 需要导入模块: from xatro.world import World [as 别名]
# 或者: from xatro.world.World import setAttr [as 别名]
def test_delAttr(self):
"""
You can delete attributes.
"""
ev = MagicMock()
world = World(ev)
obj = world.create('foo')
world.setAttr(obj['id'], 'foo', 'bar')
ev.reset_mock()
world.delAttr(obj['id'], 'foo')
ev.assert_any_call(AttrDel(obj['id'], 'foo'))
self.assertNotIn('foo', world.get(obj['id']))
示例8: test_setAttr
# 需要导入模块: from xatro.world import World [as 别名]
# 或者: from xatro.world.World import setAttr [as 别名]
def test_setAttr(self):
"""
You can set the value of an attribute.
"""
ev = MagicMock()
world = World(ev)
obj = world.create('foo')
ev.reset_mock()
world.setAttr(obj['id'], 'foo', 'bar')
ev.assert_any_call(AttrSet(obj['id'], 'foo', 'bar'))
obj = world.get(obj['id'])
self.assertEqual(obj['foo'], 'bar')
示例9: test_onBecome
# 需要导入模块: from xatro.world import World [as 别名]
# 或者: from xatro.world.World import setAttr [as 别名]
def test_onBecome(self):
"""
You can get a Deferred which will fire when an attribute becomes a
particular value.
"""
world = World(MagicMock())
obj = world.create('foo')
d = world.onBecome(obj['id'], 'hey', 3)
self.assertFalse(d.called)
world.setAttr(obj['id'], 'hey', 3)
self.assertEqual(self.successResultOf(d), 3)
# make sure it isn't called again
world.setAttr(obj['id'], 'hey', 2)
world.setAttr(obj['id'], 'hey', 3)
示例10: test_onNextChange
# 需要导入模块: from xatro.world import World [as 别名]
# 或者: from xatro.world.World import setAttr [as 别名]
def test_onNextChange(self):
"""
You can get a Deferred which will fire when an attribute changes
"""
world = World(MagicMock())
obj = world.create('foo')
d = world.onNextChange(obj['id'], 'hey')
self.assertFalse(d.called)
world.setAttr(obj['id'], 'ho', 8)
self.assertFalse(d.called)
world.setAttr(obj['id'], 'hey', 3)
self.assertEqual(self.successResultOf(d), 3)
# make sure it isn't called again
world.setAttr(obj['id'], 'hey', 2)
示例11: UsePortalTest
# 需要导入模块: from xatro.world import World [as 别名]
# 或者: from xatro.world.World import setAttr [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)
#.........这里部分代码省略.........