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')
def test_MakeTool(self): self.assertSimple(MakeTool('foo', 'bar', 'knife'), { 'action': 'maketool', 'subject': 'foo', 'ore': 'bar', 'tool': 'knife' })
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)
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")
def test_makeTool(self): """ Making a tool will destroy the ore, make a lifesource in its place, and equip the maker with the tool. """ world = World(MagicMock()) ore = world.create('ore') bot = world.create('bot') MakeTool(bot['id'], ore['id'], 'knife').execute(world) self.assertEqual(ore['kind'], 'lifesource', "Should have converted " "the ore into a lifesource") self.assertEqual(bot['tool'], 'knife', "Should have given the bot " "the tool")
def test_revertToOreWhenBotDies(self): """ If the thing dies that made the tool, revert to ore and set the tool to None """ world = World(MagicMock()) ore = world.create('ore') bot = world.create('bot') MakeTool(bot['id'], ore['id'], 'knife').execute(world) # moving to None is death Move(bot['id'], None).execute(world) self.assertNotIn('tool', bot, "Should unequip the tool") self.assertEqual(ore['kind'], 'ore', "Should revert to ore")
def test_subject(self): self.assertEqual(MakeTool('foo', 'ore', 'tool').subject(), 'foo')
def test_emitters(self): self.assertEqual( MakeTool('me', 'ore', 'tool').emitters(), ['me', 'ore'])
def test_IAction(self): verifyObject(IAction, MakeTool('me', 'ore', 'tool'))
def test_MakeTool(self): self.assertSimple(MakeTool('foo', 'bar', 'knife'), 'foo made bar into knife')