当前位置: 首页>>代码示例>>Python>>正文


Python MemcachedDatabase.get_robot方法代码示例

本文整理汇总了Python中database.memcached_database.MemcachedDatabase.get_robot方法的典型用法代码示例。如果您正苦于以下问题:Python MemcachedDatabase.get_robot方法的具体用法?Python MemcachedDatabase.get_robot怎么用?Python MemcachedDatabase.get_robot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在database.memcached_database.MemcachedDatabase的用法示例。


在下文中一共展示了MemcachedDatabase.get_robot方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_locked_robot

# 需要导入模块: from database.memcached_database import MemcachedDatabase [as 别名]
# 或者: from database.memcached_database.MemcachedDatabase import get_robot [as 别名]
    def test_locked_robot(self):
        '''Tests with a locked robot.'''
        population_control = PopulationControl()
        database = MemcachedDatabase()
        database.get_robot(TestGiveBirth.ROBOT_ID, for_update=True)

        with self.assertRaises(LockAlreadyAquiredError):
            population_control.execute_command("123", "give_birth", [TestGiveBirth.ROBOT_ID])

        database.rollback()
开发者ID:aidin36,项目名称:beneath-a-binary-sky,代码行数:12,代码来源:test_give_birth.py

示例2: test_rollback

# 需要导入模块: from database.memcached_database import MemcachedDatabase [as 别名]
# 或者: from database.memcached_database.MemcachedDatabase import get_robot [as 别名]
    def test_rollback(self):
        '''Tests if calling rollback works correctly.'''
        database = MemcachedDatabase()

        new_robot = Robot("test_rollback_87162", "123")
        database.add_robot(new_robot, (1, 1))

        database.rollback()
        database.commit()

        with self.assertRaises(RobotNotFoundError):
            database.get_robot("test_rollback_87162")
开发者ID:aidin36,项目名称:beneath-a-binary-sky,代码行数:14,代码来源:test_add_robot.py

示例3: test_locked

# 需要导入模块: from database.memcached_database import MemcachedDatabase [as 别名]
# 或者: from database.memcached_database.MemcachedDatabase import get_robot [as 别名]
    def test_locked(self):
        '''Tests with a locked square.'''
        database = MemcachedDatabase()
        world = World()

        robot = Robot("test_locked_robot_190083", "123")
        # Setting the energy to zero, so the updater tries to update the square too.
        robot.set_energy(0)

        world.add_robot(robot, (5, 9))
        database.commit()

        world.get_square((5, 9), for_update=True)

        with self.assertRaises(LockAlreadyAquiredError):
            database.get_robot(robot.get_id(), for_update=True)
开发者ID:aidin36,项目名称:beneath-a-binary-sky,代码行数:18,代码来源:test_object_updater_robot.py

示例4: test_rollback

# 需要导入模块: from database.memcached_database import MemcachedDatabase [as 别名]
# 或者: from database.memcached_database.MemcachedDatabase import get_robot [as 别名]
    def test_rollback(self):
        '''Tests if changes rolls back correctly.'''
        database = MemcachedDatabase()

        robot_id = "test_rollback_18098"
        robot = Robot(robot_id, "123")
        database.add_robot(robot, (11, 0))
        database.commit()

        new_robot = database.get_robot(robot_id, for_update=True)
        new_robot.set_alive(False)

        database.rollback()
        database.commit()

        new_robot_2 = database.get_robot(robot_id)
        self.assertNotEqual(new_robot.get_alive(), new_robot_2.get_alive())
开发者ID:aidin36,项目名称:beneath-a-binary-sky,代码行数:19,代码来源:test_get_robot.py

示例5: test_for_update

# 需要导入模块: from database.memcached_database import MemcachedDatabase [as 别名]
# 或者: from database.memcached_database.MemcachedDatabase import get_robot [as 别名]
    def test_for_update(self):
        '''Tests of for_update flag works correctly.'''
        database = MemcachedDatabase()

        robot_id = "test_for_update_18762"
        robot = Robot(robot_id, "123")
        database.add_robot(robot, (10, 0))
        database.commit()

        new_robot = database.get_robot(robot_id, for_update=True)

        # Testing lock
        with self.assertRaises(LockAlreadyAquiredError):
            database.get_robot(robot_id, for_update=True)

        # Testing commit.
        new_robot.set_alive(False)

        # It shouldn't be changed yet.
        new_robot_2 = database.get_robot(robot_id)
        self.assertNotEqual(new_robot.get_alive(), new_robot_2.get_alive())

        # Actually committing changes.
        database.commit()
        new_robot_2 = database.get_robot(robot_id)
        self.assertEqual(new_robot.get_alive(), new_robot_2.get_alive())

        # Lock should be freed.
        database.get_robot(robot_id, for_update=True)
        database.rollback()
开发者ID:aidin36,项目名称:beneath-a-binary-sky,代码行数:32,代码来源:test_get_robot.py

示例6: test_ok

# 需要导入模块: from database.memcached_database import MemcachedDatabase [as 别名]
# 或者: from database.memcached_database.MemcachedDatabase import get_robot [as 别名]
    def test_ok(self):
        '''Tests a valid situation.'''
        population_control = PopulationControl()
        database = MemcachedDatabase()
        configs = Configs()

        robot = database.get_robot(TestGiveBirth.ROBOT_ID, for_update=True)
        robot.set_honor(configs.get_robots_birth_required_honor() + 1)
        database.commit()

        new_password = population_control.execute_command("123", "give_birth", [TestGiveBirth.ROBOT_ID])
        database.commit()

        updated_robot = database.get_robot(TestGiveBirth.ROBOT_ID, for_update=False)

        self.assertEqual(updated_robot.get_honor(), 1)
        self.assertTrue(isinstance(new_password, str))
        self.assertEqual(len(new_password), 16)
开发者ID:aidin36,项目名称:beneath-a-binary-sky,代码行数:20,代码来源:test_give_birth.py

示例7: test_eating_not_matured

# 需要导入模块: from database.memcached_database import MemcachedDatabase [as 别名]
# 或者: from database.memcached_database.MemcachedDatabase import get_robot [as 别名]
    def test_eating_not_matured(self):
        '''Tests when robot eat a non matured plant.'''
        world = World()
        database = MemcachedDatabase()
        action_manager = ActionManager()
        plant = Plant()
        plant.set_age(1)

        world.plant(plant, TestEatAction.LOCATION)
        database.commit()

        robot = database.get_robot(TestEatAction.ROBOT_ID, for_update=True)
        robot.set_energy(10)
        database.commit()

        action_manager.do_action("123", "eat", [TestEatAction.ROBOT_ID])
        database.commit()

        updated_robot = database.get_robot(TestEatAction.ROBOT_ID)
        self.assertEqual(updated_robot.get_energy(), robot.get_energy() - 1)
开发者ID:aidin36,项目名称:beneath-a-binary-sky,代码行数:22,代码来源:test_eat_action.py

示例8: test_directions

# 需要导入模块: from database.memcached_database import MemcachedDatabase [as 别名]
# 或者: from database.memcached_database.MemcachedDatabase import get_robot [as 别名]
    def test_directions(self):
        '''Tests if moving in different directions works correctly.'''
        robot_id = "test_directions_154332"
        robot = Robot(robot_id, "123")
        world = World()
        database = MemcachedDatabase()

        world.add_robot(robot, (10, 2))
        database.commit()

        action_manager = ActionManager()

        action_manager.do_action("123", "move", [robot_id, "N"])
        database.commit()
        robot = database.get_robot(robot_id)
        self.assertEqual(robot.get_location(), (10, 1))

        action_manager.do_action("123", "move", [robot_id, "NE"])
        database.commit()
        robot = database.get_robot(robot_id)
        self.assertEqual(robot.get_location(), (11, 0))

        action_manager.do_action("123", "move", [robot_id, "E"])
        database.commit()
        robot = database.get_robot(robot_id)
        self.assertEqual(robot.get_location(), (12, 0))

        action_manager.do_action("123", "move", [robot_id, "SE"])
        database.commit()
        robot = database.get_robot(robot_id)
        self.assertEqual(robot.get_location(), (13, 1))

        action_manager.do_action("123", "move", [robot_id, "S"])
        database.commit()
        robot = database.get_robot(robot_id)
        self.assertEqual(robot.get_location(), (13, 2))

        action_manager.do_action("123", "move", [robot_id, "SW"])
        database.commit()
        robot = database.get_robot(robot_id)
        self.assertEqual(robot.get_location(), (12, 3))

        action_manager.do_action("123", "move", [robot_id, "W"])
        database.commit()
        robot = database.get_robot(robot_id)
        self.assertEqual(robot.get_location(), (11, 3))

        action_manager.do_action("123", "move", [robot_id, "NW"])
        database.commit()
        robot = database.get_robot(robot_id)
        self.assertEqual(robot.get_location(), (10, 2))
开发者ID:aidin36,项目名称:beneath-a-binary-sky,代码行数:53,代码来源:test_move_action.py

示例9: test_blocked_location

# 需要导入模块: from database.memcached_database import MemcachedDatabase [as 别名]
# 或者: from database.memcached_database.MemcachedDatabase import get_robot [as 别名]
    def test_blocked_location(self):
        '''Tests adding the robot to a blocked square.'''
        database = MemcachedDatabase()
        robot = Robot("test_blocked_location_91882", "123")

        # There's a rock here.
        self._world.add_robot(robot, (6, 1))
        database.commit()

        received_robot = database.get_robot(robot.get_id())

        self.assertNotEqual(received_robot.get_location(), (6, 1))
开发者ID:aidin36,项目名称:beneath-a-binary-sky,代码行数:14,代码来源:test_add_robot.py

示例10: test_ok

# 需要导入模块: from database.memcached_database import MemcachedDatabase [as 别名]
# 或者: from database.memcached_database.MemcachedDatabase import get_robot [as 别名]
    def test_ok(self):
        '''Tests a good scenario.'''
        population_control = PopulationControl()
        database = MemcachedDatabase()

        database.add_password("iujeh87UYh6512ewQ")

        robot_info = population_control.execute_command("iujeh87UYh6512ewQ", "born", [None, "RDaniel"])
        database.commit()

        gotted_robot = database.get_robot(robot_info['robot_id'])

        self.assertEqual(gotted_robot.get_name(), "RDaniel")
开发者ID:aidin36,项目名称:beneath-a-binary-sky,代码行数:15,代码来源:test_born.py

示例11: __init__

# 需要导入模块: from database.memcached_database import MemcachedDatabase [as 别名]
# 或者: from database.memcached_database.MemcachedDatabase import get_robot [as 别名]
class AdminHandler:
    '''Handles the requests related to GUI.'''

    def __init__(self):
        self._authenticator = Authenticator()
        self._database = MemcachedDatabase()

    def execute_command(self, password, command, args):
        '''Executes the specified command.'''
        if not isinstance(password, str):
            raise InvalidArgumentsError("Expected {0} as password, found {1}.".format(type(str), type(password)))

        self._authenticator.authenticate_admin(password)

        if command == "map_data":
            return self._get_map_data(args)

    def _get_map_data(self, args):
        '''Returns the information about the world's map.

        @args: Should be a list of locations. Each location is a string
            in the form of "x,y".
        '''
        squares = self._database.get_squares(args)

        result = {}
        for location, square in squares.items():
            robot_id = square.get_robot_id()
            if robot_id is not None:
                robot = self._database.get_robot(robot_id)
                robot_info = {'name': robot.get_name(),
                              'has_water': robot.get_has_water(),
                              'energy': robot.get_energy(),
                              'life': robot.get_life(),
                              'honor': robot.get_honor()}
            else:
                robot_info = None

            plant = square.get_plant()
            if plant is not None:
                plant_info = {'water_level': plant.get_water_level(),
                              'matured': plant.is_matured(),
                              'age': plant.get_age()}
            else:
                plant_info = None

            result[location] = {'surface_type': square.get_type(),
                                'plant': plant_info,
                                'robot': robot_info}

        return result
开发者ID:aidin36,项目名称:beneath-a-binary-sky,代码行数:53,代码来源:admin_handler.py

示例12: test_locked_location

# 需要导入模块: from database.memcached_database import MemcachedDatabase [as 别名]
# 或者: from database.memcached_database.MemcachedDatabase import get_robot [as 别名]
    def test_locked_location(self):
        '''Tests adding a robot to a locked location.'''
        database = MemcachedDatabase()
        robot = Robot("test_locked_location_0023", "123")

        # Locking 8,1
        database.get_square((8, 1), for_update=True)

        self._world.add_robot(robot, (8, 1))
        database.commit()

        received_robot = database.get_robot(robot.get_id())

        self.assertNotEqual(received_robot.get_location(), (8, 1))
开发者ID:aidin36,项目名称:beneath-a-binary-sky,代码行数:16,代码来源:test_add_robot.py

示例13: test_ok

# 需要导入模块: from database.memcached_database import MemcachedDatabase [as 别名]
# 或者: from database.memcached_database.MemcachedDatabase import get_robot [as 别名]
    def test_ok(self):
        '''Adds a good robot object to the world.'''
        database = MemcachedDatabase()
        robot = Robot("world_ok_robot_38364", "123")

        self._world.add_robot(robot, (5, 0))
        database.commit()

        gotted_robot = database.get_robot(robot.get_id())

        self.assertEqual(gotted_robot.get_alive(), robot.get_alive())

        all_robots = database.get_all_robot_ids()
        self.assertIn(robot.get_id(), all_robots)
开发者ID:aidin36,项目名称:beneath-a-binary-sky,代码行数:16,代码来源:test_add_robot.py

示例14: test_not_enough_honor

# 需要导入模块: from database.memcached_database import MemcachedDatabase [as 别名]
# 或者: from database.memcached_database.MemcachedDatabase import get_robot [as 别名]
    def test_not_enough_honor(self):
        '''Tests a robot with few honors, trying to give birth.'''
        population_control = PopulationControl()
        database = MemcachedDatabase()
        configs = Configs()

        robot = database.get_robot(TestGiveBirth.ROBOT_ID, for_update=True)
        robot.set_honor(configs.get_robots_birth_required_honor() - 1)
        database.commit()

        with self.assertRaises(NotEnoughHonorError):
            population_control.execute_command("123", "give_birth", [TestGiveBirth.ROBOT_ID])

        database.rollback()
开发者ID:aidin36,项目名称:beneath-a-binary-sky,代码行数:16,代码来源:test_give_birth.py

示例15: test_simple_add

# 需要导入模块: from database.memcached_database import MemcachedDatabase [as 别名]
# 或者: from database.memcached_database.MemcachedDatabase import get_robot [as 别名]
    def test_simple_add(self):
        '''Test adding a single robot to database.'''
        database = MemcachedDatabase()

        new_robot = Robot("test_simple_add_", "123")

        # No exception should be raise.
        database.add_robot(new_robot, (0, 0))
        database.commit()

        gotted_robot = database.get_robot("test_simple_add_")

        self.assertEqual(gotted_robot.get_id(), new_robot.get_id())
        self.assertEqual(gotted_robot.get_alive(), new_robot.get_alive())
        self.assertEqual(gotted_robot.get_password(), new_robot.get_password())
开发者ID:aidin36,项目名称:beneath-a-binary-sky,代码行数:17,代码来源:test_add_robot.py


注:本文中的database.memcached_database.MemcachedDatabase.get_robot方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。