예제 #1
0
    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, ))
예제 #2
0
    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,))
예제 #3
0
    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))
예제 #4
0
    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))
예제 #5
0
    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, ))
예제 #6
0
    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,))