當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。