本文整理汇总了Python中database.memcached_database.MemcachedDatabase类的典型用法代码示例。如果您正苦于以下问题:Python MemcachedDatabase类的具体用法?Python MemcachedDatabase怎么用?Python MemcachedDatabase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MemcachedDatabase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_water_level
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())
示例2: Communicator
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
示例3: setUpClass
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()
示例4: setUpClass
def setUpClass(cls):
row = [MapSquare(MapSquareTypes.WATER, (0, 18)),
MapSquare(MapSquareTypes.SOIL, (1, 18)),
MapSquare(MapSquareTypes.SAND, (2, 18))]
database = MemcachedDatabase()
database.add_square_row(row)
示例5: test_add_and_pop
def test_add_and_pop(self):
'''Adds a password and pops it again.'''
database = MemcachedDatabase()
database.add_password("test_add_and_pop_8341")
database.pop_password("test_add_and_pop_8341")
示例6: test_specific_point
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})
示例7: test_no_plant
def test_no_plant(self):
'''Tests when there's no plant to eat.'''
action_manager = ActionManager()
database = MemcachedDatabase()
with self.assertRaises(NoPlantToEat):
action_manager.do_action("123", "eat", [TestEatAction.ROBOT_ID])
database.rollback()
示例8: test_duplicate_password
def test_duplicate_password(self):
'''Adds a password twice. Should raise an exception.'''
database = MemcachedDatabase()
database.add_password("test_duplicate_8172")
with self.assertRaises(DuplicatedPasswordError):
database.add_password("test_duplicate_8172")
示例9: test_invalid_location
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()
示例10: setUpClass
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()
示例11: test_locked
def test_locked(self):
'''Tests with a locked square.'''
action_manager = ActionManager()
database = MemcachedDatabase()
database.get_square(TestEatAction.LOCATION, for_update=True)
with self.assertRaises(LockAlreadyAquiredError):
action_manager.do_action("123", "eat", [TestEatAction.ROBOT_ID])
database.rollback()
示例12: test_locked_robot
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()
示例13: test_ok
def test_ok(self):
'''Tests a good scenario.'''
row = [MapSquare(MapSquareTypes.SOIL, (0, 17))]
database = MemcachedDatabase()
database.add_square_row(row)
plant_action = PlantAction()
robot = Robot("18873.182873.1123", "123")
robot.set_location((0, 17))
plant_action.do_action(robot, ["18873.182873.1123"])
示例14: test_blocked_location
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))
示例15: test_bad_argument
def test_bad_argument(self):
'''Tests when sending bad arguments to the action.'''
action_manager = ActionManager()
database = MemcachedDatabase()
with self.assertRaises(InvalidArgumentsError):
action_manager.do_action("123", "eat", [TestEatAction.ROBOT_ID, None])
database.rollback()
with self.assertRaises(InvalidArgumentsError):
action_manager.do_action("123", "eat", [TestEatAction.ROBOT_ID, "", 9])
database.rollback()