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, ))
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,))
def test_onlyBotsCanExecute(self): """ Only bots can execute commands. """ world = World(MagicMock()) rules = StandardRules() bot = world.create('bot')['id'] rules.isAllowed(world, action.ListSquares(bot)) nonbot = world.create('foo')['id'] self.assertRaises(NotAllowed, rules.isAllowed, world, action.ListSquares(nonbot))
def test_failIfOnBoard(self): """ The following actions may only be done when NOT on a board. """ world = World(MagicMock()) rules = StandardRules() bot = world.create('bot')['id'] square = world.create('square')['id'] action.Move(bot, square).execute(world) actions = [ action.UsePortal(bot, 'foo'), action.JoinTeam(bot, 'team', 'foo'), action.CreateTeam(bot, 'team', 'foo'), ] for a in actions: try: rules.isAllowed(world, a) except NotAllowed: pass else: self.fail("You must be off of a square to do %r" % (a, ))
def test_failIfOnBoard(self): """ The following actions may only be done when NOT on a board. """ world = World(MagicMock()) rules = StandardRules() bot = world.create('bot')['id'] square = world.create('square')['id'] action.Move(bot, square).execute(world) actions = [ action.UsePortal(bot, 'foo'), action.JoinTeam(bot, 'team', 'foo'), action.CreateTeam(bot, 'team', 'foo'), ] for a in actions: try: rules.isAllowed(world, a) except NotAllowed: pass else: self.fail("You must be off of a square to do %r" % (a,))