本文整理匯總了Python中xatro.world.World.get方法的典型用法代碼示例。如果您正苦於以下問題:Python World.get方法的具體用法?Python World.get怎麽用?Python World.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類xatro.world.World
的用法示例。
在下文中一共展示了World.get方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_execute_inRoom
# 需要導入模塊: from xatro.world import World [as 別名]
# 或者: from xatro.world.World import get [as 別名]
def test_execute_inRoom(self):
"""
If an object is already located in another container, then moving it
should:
- Unsubscribe from the location's events
- Unsubscribe the location from the thing's events
- Cause C{contents} to be updated.
"""
world = World(MagicMock())
thing = world.create('thing')['id']
room1 = world.create('room1')['id']
room2 = world.create('room2')['id']
move1 = Move(thing, room1)
move1.execute(world)
move2 = Move(thing, room2)
move2.execute(world)
room1_called = []
world.receiveFor(room1, room1_called.append)
room2_called = []
world.receiveFor(room2, room2_called.append)
thing_called = []
world.receiveFor(thing, thing_called.append)
# emit from room1
world.emit('foo', room1)
self.assertEqual(thing_called, [], "Thing should detach from previous "
"room events")
room1_called.pop()
# emit from thing
world.emit('bar', thing)
self.assertEqual(thing_called, ['bar'], "Thing should see own events")
self.assertEqual(room1_called, [], "Room1 should detach from thing"
" events")
# room1 contents
room1_obj = world.get(room1)
self.assertEqual(room1_obj['contents'], [], "Should remove from "
"contents of room1")
location = world.get(thing)['location']
self.assertEqual(location, room2, "Should update the "
"location of the thing. This is mostly to confirm "
"that the default moving behavior tested in the other "
"test happened.")
示例2: test_get
# 需要導入模塊: from xatro.world import World [as 別名]
# 或者: from xatro.world.World import get [as 別名]
def test_get(self):
"""
You can get objects.
"""
world = World(MagicMock())
obj = world.create('foo')
obj2 = world.get(obj['id'])
self.assertEqual(obj, obj2)
示例3: test_basic
# 需要導入模塊: from xatro.world import World [as 別名]
# 或者: from xatro.world.World import get [as 別名]
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']))
示例4: test_moveToNone
# 需要導入模塊: from xatro.world import World [as 別名]
# 或者: from xatro.world.World import get [as 別名]
def test_moveToNone(self):
"""
Moving something to nowhere should result in the location being
None.
"""
world = World(MagicMock())
thing = world.create('thing')['id']
room1 = world.create('room1')['id']
move1 = Move(thing, room1)
move1.execute(world)
move2 = Move(thing, None)
move2.execute(world)
room1_called = []
world.receiveFor(room1, room1_called.append)
thing_called = []
world.receiveFor(thing, thing_called.append)
# emit from room1
world.emit('foo', room1)
self.assertEqual(thing_called, [], "Thing should detach from previous "
"room events")
room1_called.pop()
# emit from thing
world.emit('bar', thing)
self.assertEqual(thing_called, ['bar'], "Thing should see own events")
self.assertEqual(room1_called, [], "Room1 should detach from thing"
" events")
# room1 contents
room1_obj = world.get(room1)
self.assertEqual(room1_obj['contents'], [], "Should remove from "
"contents of room1")
location = world.get(thing)['location']
self.assertEqual(location, None, "Should update the location")
示例5: test_delAttr
# 需要導入模塊: from xatro.world import World [as 別名]
# 或者: from xatro.world.World import get [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']))
示例6: test_removeItem
# 需要導入模塊: from xatro.world import World [as 別名]
# 或者: from xatro.world.World import get [as 別名]
def test_removeItem(self):
"""
You can remove items from a list
"""
ev = MagicMock()
world = World(ev)
obj = world.create('foo')
world.addItem(obj['id'], 'foo', 'bar')
ev.reset_mock()
world.removeItem(obj['id'], 'foo', 'bar')
ev.assert_any_call(ItemRemoved(obj['id'], 'foo', 'bar'))
self.assertEqual(world.get(obj['id'])['foo'], [])
示例7: test_setAttr
# 需要導入模塊: from xatro.world import World [as 別名]
# 或者: from xatro.world.World import get [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')
示例8: test_addItem
# 需要導入模塊: from xatro.world import World [as 別名]
# 或者: from xatro.world.World import get [as 別名]
def test_addItem(self):
"""
You can add items to a list
"""
ev = MagicMock()
world = World(ev)
obj = world.create('foo')
ev.reset_mock()
world.addItem(obj['id'], 'foo', 'bar')
ev.assert_any_call(ItemAdded(obj['id'], 'foo', 'bar'))
obj = world.get(obj['id'])
self.assertEqual(obj['foo'], ['bar'])
示例9: test_charge
# 需要導入模塊: from xatro.world import World [as 別名]
# 或者: from xatro.world.World import get [as 別名]
def test_charge(self):
"""
Charging should add energy to the thing's energy pool and to the
thing's created energy pool.
"""
world = World(MagicMock())
thing = world.create('thing')
charge = Charge(thing['id'])
charge.execute(world)
self.assertEqual(len(thing['energy']), 1)
self.assertEqual(thing['created_energy'], 1, "Should keep track "
"of the energy it created")
e = world.get(thing['energy'][0])
self.assertEqual(e['kind'], 'energy')
示例10: test_buildProtocol
# 需要導入模塊: from xatro.world import World [as 別名]
# 或者: from xatro.world.World import get [as 別名]
def test_buildProtocol(self):
"""
When a protocol is made, the protocol should be given an Avatar
that is connected to a 'bot' in the world. Also, the avatar should be
given a copy of the available commands.
"""
world = World(MagicMock())
f = BotFactory(world, {'foo': 'bar'})
proto = f.buildProtocol(None)
self.assertEqual(proto.factory, f)
self.assertTrue(isinstance(proto, BotLineProtocol))
self.assertTrue(isinstance(proto.avatar, Avatar))
self.assertEqual(proto.avatar._world, world, "Should be connected to "
"the world")
self.assertNotEqual(proto.avatar._game_piece, None, "Should have a game"
" piece")
self.assertEqual(proto.avatar.availableCommands(), {'foo': 'bar'})
obj = world.get(proto.avatar._game_piece)
self.assertEqual(obj['kind'], 'bot', "Should make a bot in the world")
self.assertTrue(isinstance(proto.event_transformer,
ToStringTransformer))