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


Python MemcachedDatabase.commit方法代码示例

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


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

示例1: Communicator

# 需要导入模块: from database.memcached_database import MemcachedDatabase [as 别名]
# 或者: from database.memcached_database.MemcachedDatabase import commit [as 别名]
class Communicator(Singleton):
    '''Interface between listeners and the application.'''

    def _initialize(self):
        self._database = MemcachedDatabase()
        self._action_manager = ActionManager()
        self._population_control = PopulationControl()
        self._admin_handler = AdminHandler()

    def execute_command(self, password, command, args):
        '''Execute client's command.'''

        try:
            if command in ["born", "give_birth"]:
                result = self._population_control.execute_command(password, command, args)
            elif command == "map_data":
                result = self._admin_handler.execute_command(password, command, args)
            else:
                result = self._action_manager.do_action(password, command, args)

            # Committing or rollbacking all changes after the completion of execution.
            self._database.commit()
            return result

        except Exception:
            self._database.rollback()
            raise
开发者ID:aidin36,项目名称:beneath-a-binary-sky,代码行数:29,代码来源:communicator.py

示例2: test_water_level

# 需要导入模块: from database.memcached_database import MemcachedDatabase [as 别名]
# 或者: from database.memcached_database.MemcachedDatabase import commit [as 别名]
    def test_water_level(self):
        '''Tests if water level increases after watering.'''
        database = MemcachedDatabase()
        world = World()

        robot = Robot("198.1287.fkdfjei", "123")
        robot.set_location((5, 0))
        robot.set_has_water(True)

        plant = Plant()
        plant.set_water_level(30)

        world.plant(plant, (5, 0))

        database.commit()

        action = WaterAction()
        action.do_action(robot, ["198.1287.fkdfjei"])

        database.commit()

        updated_square = world.get_square((5, 0))
        plant = updated_square.get_plant()

        # Checking if honor increased.
        self.assertEqual(robot.get_honor(), 1)

        self.assertEqual(plant.get_water_level(), 100)
        self.assertFalse(robot.get_has_water())
开发者ID:aidin36,项目名称:beneath-a-binary-sky,代码行数:31,代码来源:test_water_action.py

示例3: test_specific_point

# 需要导入模块: from database.memcached_database import MemcachedDatabase [as 别名]
# 或者: from database.memcached_database.MemcachedDatabase import commit [as 别名]
    def test_specific_point(self):
        '''Gets information of a specific point, and check its result.'''
        database = MemcachedDatabase()
        new_robot = Robot("oie982736hhjf", "lo098173635")
        new_robot.set_location((9, 4))

        database.add_robot(new_robot, (9, 4))
        database.commit()

        action_manager = ActionManager()
        info = action_manager.do_action(new_robot.get_password(), "sense", [new_robot.get_id()])

        self.assertEqual(len(info), 9)
        self.assertEqual(info["9,4"], {"surface_type": MapSquareTypes.SOIL,
                                       "robot": True,
                                       "plant": None})
        self.assertEqual(info["9,3"], {"surface_type": MapSquareTypes.WATER,
                                       "robot": False,
                                       "plant": None})
        self.assertEqual(info["10,5"], {"surface_type": MapSquareTypes.SOIL,
                                        "robot": False,
                                        "plant": None})
        self.assertEqual(info["8,4"], {"surface_type": MapSquareTypes.SOIL,
                                       "robot": False,
                                       "plant": None})
开发者ID:aidin36,项目名称:beneath-a-binary-sky,代码行数:27,代码来源:test_sense_action.py

示例4: test_bad_name

# 需要导入模块: from database.memcached_database import MemcachedDatabase [as 别名]
# 或者: from database.memcached_database.MemcachedDatabase import commit [as 别名]
    def test_bad_name(self):
        '''Tries to born a robot with an invalid name. Should be fail.'''
        population_control = PopulationControl()
        database = MemcachedDatabase()

        database.add_password("OIkdj981HJDJHcnm_1")
        database.add_password("OIkdj981HJDJHcnm_2")
        database.add_password("OIkdj981HJDJHcnm_3")
        database.add_password("OIkdj981HJDJHcnm_4")
        database.commit()

        long_name = "n" * (MAX_ROBOT_NAME + 1)
        with self.assertRaises(LongRobotNameError):
            population_control.execute_command("OIkdj981HJDJHcnm_1", "born", [None, long_name])
        database.rollback()

        with self.assertRaises(LongRobotNameError):
            population_control.execute_command("OIkdj981HJDJHcnm_2", "born", [None, None])
        database.rollback()

        with self.assertRaises(LongRobotNameError):
            population_control.execute_command("OIkdj981HJDJHcnm_3", "born", [None, b"some bytes"])
        database.rollback()

        with self.assertRaises(LongRobotNameError):
            population_control.execute_command("OIkdj981HJDJHcnm_4", "born", [None, database])
        database.rollback()
开发者ID:aidin36,项目名称:beneath-a-binary-sky,代码行数:29,代码来源:test_born.py

示例5: test_bad_direction

# 需要导入模块: from database.memcached_database import MemcachedDatabase [as 别名]
# 或者: from database.memcached_database.MemcachedDatabase import commit [as 别名]
    def test_bad_direction(self):
        '''Sends an invalid direction as arguments.'''
        robot_id = "test_bad_direction_18445"
        robot = Robot(robot_id, "123")
        world = World()
        action_manager = ActionManager()
        database = MemcachedDatabase()

        world.add_robot(robot, (12, 6))
        database.commit()

        with self.assertRaises(InvalidArgumentsError):
            action_manager.do_action("123", "move", [robot_id, "U"])

        database.rollback()

        with self.assertRaises(InvalidArgumentsError):
            action_manager.do_action("123", "move", [robot_id, 988])

        database.rollback()

        with self.assertRaises(InvalidArgumentsError):
            action_manager.do_action("123", "move", [robot_id, None])

        database.rollback()

        with self.assertRaises(InvalidArgumentsError):
            action_manager.do_action("123", "move", [robot_id])

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

示例6: setUpClass

# 需要导入模块: from database.memcached_database import MemcachedDatabase [as 别名]
# 或者: from database.memcached_database.MemcachedDatabase import commit [as 别名]
 def setUpClass(cls):
     # Creating a robot that all the tests will use.
     database = MemcachedDatabase()
     world = World()
     robot = Robot(TestGiveBirth.ROBOT_ID, "123")
     world.add_robot(robot, (0, 14))
     database.commit()
开发者ID:aidin36,项目名称:beneath-a-binary-sky,代码行数:9,代码来源:test_give_birth.py

示例7: test_for_update

# 需要导入模块: from database.memcached_database import MemcachedDatabase [as 别名]
# 或者: from database.memcached_database.MemcachedDatabase import commit [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

示例8: test_invalid_location

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

        with self.assertRaises(InvalidLocationError):
            self._world.add_robot(robot, (19872, 1190))
            database.commit()
开发者ID:aidin36,项目名称:beneath-a-binary-sky,代码行数:10,代码来源:test_add_robot.py

示例9: setUpClass

# 需要导入模块: from database.memcached_database import MemcachedDatabase [as 别名]
# 或者: from database.memcached_database.MemcachedDatabase import commit [as 别名]
    def setUpClass(cls):
        # Addin a robot to the world. All the tests would use this robot.
        robot = Robot(cls.ROBOT_ID, "123")
        world = World()

        world.add_robot(robot, cls.LOCATION)

        database = MemcachedDatabase()
        database.commit()
开发者ID:aidin36,项目名称:beneath-a-binary-sky,代码行数:11,代码来源:test_eat_action.py

示例10: test_rollback

# 需要导入模块: from database.memcached_database import MemcachedDatabase [as 别名]
# 或者: from database.memcached_database.MemcachedDatabase import commit [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

示例11: test_duplicate_add

# 需要导入模块: from database.memcached_database import MemcachedDatabase [as 别名]
# 或者: from database.memcached_database.MemcachedDatabase import commit [as 别名]
    def test_duplicate_add(self):
        '''Adding two robots with same ID. Should be failed.'''
        database = MemcachedDatabase()

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

        robot2 = Robot("test_duplicate_add_", "123")
        with self.assertRaises(CannotAddObjectError):
            database.add_robot(robot2, (1, 2))
            database.commit()
开发者ID:aidin36,项目名称:beneath-a-binary-sky,代码行数:14,代码来源:test_add_robot.py

示例12: test_blocked_location

# 需要导入模块: from database.memcached_database import MemcachedDatabase [as 别名]
# 或者: from database.memcached_database.MemcachedDatabase import commit [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

示例13: test_blocking_object

# 需要导入模块: from database.memcached_database import MemcachedDatabase [as 别名]
# 或者: from database.memcached_database.MemcachedDatabase import commit [as 别名]
    def test_blocking_object(self):
        '''Tests moving toward a blocking object.'''
        robot_id = "test_invalid_location_8765112"
        robot = Robot(robot_id, "123")
        world = World()
        action_manager = ActionManager()
        database = MemcachedDatabase()

        world.add_robot(robot, (11, 6))
        database.commit()

        with self.assertRaises(LocationIsBlockedError):
            action_manager.do_action("123", "move", [robot_id, "W"])
开发者ID:aidin36,项目名称:beneath-a-binary-sky,代码行数:15,代码来源:test_move_action.py

示例14: test_with_parent

# 需要导入模块: from database.memcached_database import MemcachedDatabase [as 别名]
# 或者: from database.memcached_database.MemcachedDatabase import commit [as 别名]
    def test_with_parent(self):
        '''Tests borning a robot with a parent.'''
        population_control = PopulationControl()
        database = MemcachedDatabase()

        database.add_password("oijdnnh76153WEd")
        robot = Robot("test_with_parent_18873", "123")
        database.add_robot(robot, (14, 1))
        database.commit()

        population_control.execute_command("oijdnnh76153WEd", "born", ["test_with_parent_18873", "My Child"])

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

示例15: test_ok

# 需要导入模块: from database.memcached_database import MemcachedDatabase [as 别名]
# 或者: from database.memcached_database.MemcachedDatabase import commit [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


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