本文整理汇总了Python中xatro.world.World类的典型用法代码示例。如果您正苦于以下问题:Python World类的具体用法?Python World怎么用?Python World使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了World类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_execute_energyRequired_command_fails
def test_execute_energyRequired_command_fails(self):
"""
If there is energy required and the command fails to run, the energy
should not be consumed.
"""
e = self.friendlyEngine()
# require some energy
e.engine.energyRequirement.return_value = 2
# make some energy
world = World(MagicMock())
actor = world.create('thing')
yield Charge(actor['id']).execute(world)
yield Charge(actor['id']).execute(world)
self.assertEqual(len(actor['energy']), 2)
# do the action and consume the energy
action = MagicMock()
action.subject.return_value = actor['id']
# synchronous
action.execute.side_effect = NotAllowed('foo')
self.assertFailure(e.execute(world, action), NotAllowed)
self.assertEqual(len(actor['energy']), 2, "Should not have consumed "
"the energy")
# asynchronous
action.execute.side_effect = None
action.execute.return_value = defer.fail(NotAllowed('foo'))
self.assertFailure(e.execute(world, action), NotAllowed)
self.assertEqual(len(actor['energy']), 2, "Should not have consumed "
"the energy")
开发者ID:iffy,项目名称:xatrobots,代码行数:34,代码来源:test_engine.py
示例2: test_failIfNotOnBoard
def test_failIfNotOnBoard(self):
"""
The following actions require a bot to be on the board.
"""
world = World(MagicMock())
rules = StandardRules()
bot = world.create('bot')['id']
actions = [
action.Charge(bot),
action.ShareEnergy(bot, 'foo', 2),
action.ConsumeEnergy(bot, 2),
action.Shoot(bot, 'foo', 1),
action.Repair(bot, 'foo', 1),
action.MakeTool(bot, 'foo', 'foo'),
action.OpenPortal(bot, 'foo', 'foo'),
action.AddLock(bot, 'foo'),
action.BreakLock(bot, 'foo'),
action.LookAt(bot, 'foo'),
]
for a in actions:
try:
rules.isAllowed(world, a)
except NotAllowed:
pass
else:
self.fail("You must be on a square to do %r" % (a,))
开发者ID:iffy,项目名称:xatrobots,代码行数:29,代码来源:test_standard.py
示例3: test_execute_Deferred
def test_execute_Deferred(self):
"""
If a command returns a successful deferred, wait to emit.
"""
engine = MagicMock()
d = defer.Deferred()
engine.execute.return_value = d
world = World(MagicMock(), engine)
world.emit = MagicMock()
action = MagicMock()
action.emitters.return_value = ['I did it']
r = world.execute(action)
self.assertEqual(r, d, "Should return the result of the execution")
engine.execute.assert_called_once_with(world, action)
self.assertEqual(world.emit.call_count, 0, "Should not have emitted "
"the ActionPerformed event yet, because it hasn't "
"finished")
d.callback('foo')
self.assertEqual(self.successResultOf(r), 'foo',
"Should return the result of execution")
world.emit.assert_called_once_with(ActionPerformed(action), 'I did it')
开发者ID:iffy,项目名称:xatrobots,代码行数:25,代码来源:test_world.py
示例4: test_receiverFor_same
def test_receiverFor_same(self):
"""
You should get the same function each time you ask for a receiver for
the same object.
"""
world = World(MagicMock())
self.assertEqual(world.receiverFor('foo'), world.receiverFor('foo'))
开发者ID:iffy,项目名称:xatrobots,代码行数:7,代码来源:test_world.py
示例5: test_destroy_disableSubscribers
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,代码行数:28,代码来源:test_world.py
示例6: test_makeSecondTool
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')
开发者ID:iffy,项目名称:xatrobots,代码行数:25,代码来源:test_action.py
示例7: test_execute
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)
开发者ID:iffy,项目名称:xatrobots,代码行数:30,代码来源:test_action.py
示例8: test_execute_energyRequired_succeed
def test_execute_energyRequired_succeed(self):
"""
If energy is required and the actor has enough energy, do the action.
"""
e = self.friendlyEngine()
# require some energy
e.engine.energyRequirement.return_value = 2
# make some energy
world = World(MagicMock())
actor = world.create('thing')
yield Charge(actor['id']).execute(world)
yield Charge(actor['id']).execute(world)
self.assertEqual(len(actor['energy']), 2)
# do the action and consume the energy
action = MagicMock()
action.subject.return_value = actor['id']
action.execute.return_value = 'foo'
ret = yield e.execute(world, action)
self.assertEqual(ret, 'foo', "Should have executed the action")
self.assertEqual(len(actor['energy']), 0, "Should have consumed "
"the energy")
开发者ID:iffy,项目名称:xatrobots,代码行数:26,代码来源:test_engine.py
示例9: test_emit
def test_emit(self):
"""
All emissions are sent to my event_receiver
"""
ev = MagicMock()
world = World(ev)
world.emit('something', 'foo')
ev.assert_called_once_with('something')
开发者ID:iffy,项目名称:xatrobots,代码行数:8,代码来源:test_world.py
示例10: test_badPassword
def test_badPassword(self):
auth = FileStoredPasswords(self.mktemp())
world = World(MagicMock(), auth=auth)
thing = world.create('thing')
yield CreateTeam(thing['id'], 'teamA', 'password').execute(world)
self.assertFailure(JoinTeam(thing['id'], 'teamA',
'not password').execute(world), BadPassword)
开发者ID:iffy,项目名称:xatrobots,代码行数:8,代码来源:test_action.py
示例11: test_create_uniqueId
def test_create_uniqueId(self):
"""
The id of an object should be unique
"""
world = World(MagicMock())
o1 = world.create('foo')
o2 = world.create('bar')
self.assertNotEqual(o1['id'], o2['id'])
开发者ID:iffy,项目名称:xatrobots,代码行数:8,代码来源:test_world.py
示例12: test_get
def test_get(self):
"""
You can get objects.
"""
world = World(MagicMock())
obj = world.create('foo')
obj2 = world.get(obj['id'])
self.assertEqual(obj, obj2)
开发者ID:iffy,项目名称:xatrobots,代码行数:8,代码来源:test_world.py
示例13: test_invalidLocation
def test_invalidLocation(self):
"""
It is an error to move to a non-entity.
"""
world = World(MagicMock())
thing = world.create('thing')['id']
self.assertRaises(NotAllowed, Move(thing, 4).execute, world)
开发者ID:iffy,项目名称:xatrobots,代码行数:8,代码来源:test_action.py
示例14: test_nowhere
def test_nowhere(self):
"""
If you are nowhere, return an empty list.
"""
world = World(MagicMock())
thing = world.create('thing')
self.assertEqual(Look(thing['id']).execute(world), [])
开发者ID:iffy,项目名称:xatrobots,代码行数:8,代码来源:test_action.py
示例15: test_emit_toEngine
def test_emit_toEngine(self):
"""
All emissions are sent to the engine.
"""
ev = MagicMock()
engine = MagicMock()
world = World(ev, engine)
world.emit('foo', 'object_id')
engine.worldEventReceived.assert_called_once_with(world, 'foo')
开发者ID:iffy,项目名称:xatrobots,代码行数:9,代码来源:test_world.py
示例16: test_basic
def test_basic(self):
"""
Should return information about the object.
"""
world = World(MagicMock())
thing = world.create('thing')
r = LookAt(thing['id'], thing['id']).execute(world)
self.assertEqual(r, world.get(thing['id']))
开发者ID:iffy,项目名称:xatrobots,代码行数:9,代码来源:test_action.py
示例17: test_envelope
def test_envelope(self):
"""
You can read/write on the envelope of objects.
"""
world = World(MagicMock())
obj = MagicMock()
env = world.envelope(obj)
self.assertTrue(isinstance(env, dict))
env['foo'] = 'bar'
开发者ID:iffy,项目名称:xatrobots,代码行数:9,代码来源:test_world.py
示例18: test_onlyOre
def test_onlyOre(self):
"""
Only ore can be turned into tools.
"""
world = World(MagicMock())
ore = world.create('flower')
bot = world.create('bot')
self.assertRaises(NotAllowed,
MakeTool(bot['id'], ore['id'], 'knife').execute, world)
开发者ID:iffy,项目名称:xatrobots,代码行数:10,代码来源:test_action.py
示例19: test_open
def test_open(self):
"""
You can open a portal on from some ore.
"""
world = World(MagicMock())
ore = world.create('ore')
bot = world.create('bot')
OpenPortal(bot['id'], ore['id'], 'user').execute(world)
self.assertEqual(ore['portal_user'], 'user', "Should set the portal "
"user to the id of the user that can use the portal")
self.assertEqual(ore['kind'], 'portal')
开发者ID:iffy,项目名称:xatrobots,代码行数:12,代码来源:test_action.py
示例20: test_stayAbove0
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")
开发者ID:iffy,项目名称:xatrobots,代码行数:12,代码来源:test_action.py
注:本文中的xatro.world.World类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论