本文整理汇总了Python中the_tale.game.logic_storage.LogicStorage._test_save方法的典型用法代码示例。如果您正苦于以下问题:Python LogicStorage._test_save方法的具体用法?Python LogicStorage._test_save怎么用?Python LogicStorage._test_save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类the_tale.game.logic_storage.LogicStorage
的用法示例。
在下文中一共展示了LogicStorage._test_save方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FirstStepsActionTest
# 需要导入模块: from the_tale.game.logic_storage import LogicStorage [as 别名]
# 或者: from the_tale.game.logic_storage.LogicStorage import _test_save [as 别名]
class FirstStepsActionTest(testcase.TestCase):
def setUp(self):
super(FirstStepsActionTest, self).setUp()
create_test_map()
self.account = self.accounts_factory.create_account(is_fast=True)
self.storage = LogicStorage()
self.storage.load_account_data(self.account)
self.hero = self.storage.accounts_to_heroes[self.account.id]
self.action_idl = self.hero.actions.current_action
with self.check_calls_count("the_tale.game.heroes.logic.push_message_to_diary", 1):
self.action_first_steps = ActionFirstStepsPrototype.create(hero=self.hero)
def test_create(self):
self.assertEqual(self.action_idl.leader, False)
self.assertEqual(self.action_first_steps.leader, True)
self.assertEqual(self.action_first_steps.bundle_id, self.action_idl.bundle_id)
self.storage._test_save()
def test_processed(self):
current_time = TimePrototype.get_current_time()
self.assertEqual(self.hero.journal.messages_number(), 2)
with self.check_calls_count("the_tale.game.heroes.logic.push_message_to_diary", 0):
self.storage.process_turn()
current_time.increment_turn()
self.assertEqual(self.hero.journal.messages_number(), 3)
self.storage.process_turn()
current_time.increment_turn()
self.assertEqual(self.hero.journal.messages_number(), 4)
self.storage.process_turn(continue_steps_if_needed=False)
current_time.increment_turn()
self.assertEqual(self.hero.journal.messages_number(), 5)
self.assertTrue(self.hero.actions.current_action.TYPE.is_IDLENESS)
self.storage._test_save()
示例2: HealCompanionActionTest
# 需要导入模块: from the_tale.game.logic_storage import LogicStorage [as 别名]
# 或者: from the_tale.game.logic_storage.LogicStorage import _test_save [as 别名]
class HealCompanionActionTest(UseAbilityTaskMixin, testcase.TestCase):
PROCESSOR = Help
def setUp(self):
super(HealCompanionActionTest, self).setUp()
create_test_map()
self.account = self.accounts_factory.create_account()
self.storage = LogicStorage()
self.storage.load_account_data(self.account)
self.hero = self.storage.accounts_to_heroes[self.account.id]
self.companion_record = companions_storage.companions.enabled_companions().next()
self.hero.set_companion(companions_logic.create_companion(self.companion_record))
self.action_idl = self.hero.actions.current_action
self.hero.companion.healed_at_turn = -1
with self.check_increased(lambda: self.hero.companion.healed_at_turn):
self.action_heal_companion = prototypes.ActionHealCompanionPrototype.create(hero=self.hero)
def test_create(self):
self.assertEqual(self.action_idl.leader, False)
self.assertEqual(self.action_heal_companion.leader, True)
self.assertEqual(self.action_heal_companion.bundle_id, self.action_heal_companion.bundle_id)
self.assertEqual(self.action_heal_companion.percents, 0)
self.storage._test_save()
def test_processed__no_companion(self):
self.hero.remove_companion()
self.storage.process_turn(continue_steps_if_needed=False)
self.assertEqual(len(self.hero.actions.actions_list), 1)
self.assertEqual(self.hero.actions.current_action, self.action_idl)
self.storage._test_save()
def test_processed__max_health(self):
self.assertEqual(self.hero.companion.health, self.hero.companion.max_health)
self.storage.process_turn(continue_steps_if_needed=False)
self.assertEqual(len(self.hero.actions.actions_list), 1)
self.assertEqual(self.hero.actions.current_action, self.action_idl)
self.storage._test_save()
def test_not_ready(self):
self.hero.companion.health = 1
self.storage.process_turn()
self.assertEqual(len(self.hero.actions.actions_list), 2)
self.assertEqual(self.hero.actions.current_action, self.action_heal_companion)
self.assertTrue(self.hero.companion.health, 1)
self.assertTrue(self.action_heal_companion.percents > 0)
self.storage._test_save()
def test_ability_heal_companion(self):
self.hero.companion.health = 1
with self.check_increased(lambda: self.action_heal_companion.percents):
with self.check_increased(lambda: self.hero.companion.health):
ability = self.PROCESSOR()
with mock.patch('the_tale.game.actions.prototypes.ActionBase.get_help_choice', lambda x: HELP_CHOICES.HEAL_COMPANION):
self.assertTrue(ability.use(**self.use_attributes(hero=self.hero, storage=self.storage)))
def test_ability_heal_companion__processed_when_healed(self):
self.hero.companion.health -= 1
with self.check_increased(lambda: self.action_heal_companion.percents):
with self.check_increased(lambda: self.hero.companion.health):
ability = self.PROCESSOR()
with mock.patch('the_tale.game.actions.prototypes.ActionBase.get_help_choice', lambda x: HELP_CHOICES.HEAL_COMPANION):
self.assertTrue(ability.use(**self.use_attributes(hero=self.hero, storage=self.storage)))
self.assertTrue(self.action_heal_companion.percents, 1)
self.assertEqual(self.action_heal_companion.state, self.action_heal_companion.STATE.PROCESSED)
@mock.patch('the_tale.game.heroes.prototypes.HeroPrototype.can_companion_exp_per_heal', lambda hero: True)
def test_ability_heal_companion__processed_when_healed__exp_per_heal(self):
self.hero.companion.health -= 1
with self.check_delta(lambda: self.hero.experience, c.COMPANIONS_EXP_PER_HEAL):
with self.check_increased(lambda: self.hero.companion.health):
ability = self.PROCESSOR()
with mock.patch('the_tale.game.actions.prototypes.ActionBase.get_help_choice', lambda x: HELP_CHOICES.HEAL_COMPANION):
self.assertTrue(ability.use(**self.use_attributes(hero=self.hero, storage=self.storage)))
#.........这里部分代码省略.........
示例3: RegenerateEnergyActionTest
# 需要导入模块: from the_tale.game.logic_storage import LogicStorage [as 别名]
# 或者: from the_tale.game.logic_storage.LogicStorage import _test_save [as 别名]
class RegenerateEnergyActionTest(testcase.TestCase):
def setUp(self):
super(RegenerateEnergyActionTest, self).setUp()
create_test_map()
result, account_id, bundle_id = register_user('test_user')
self.storage = LogicStorage()
self.storage.load_account_data(AccountPrototype.get_by_id(account_id))
self.hero = self.storage.accounts_to_heroes[account_id]
self.action_idl = self.hero.actions.current_action
self.action_regenerate = ActionRegenerateEnergyPrototype.create(hero=self.hero)
def tearDown(self):
pass
def test_create(self):
self.assertEqual(self.action_idl.leader, False)
self.assertEqual(self.action_regenerate.leader, True)
self.assertEqual(self.action_regenerate.bundle_id, self.action_idl.bundle_id)
self.storage._test_save()
def test_not_ready(self):
self.storage.process_turn()
self.assertEqual(len(self.hero.actions.actions_list), 2)
self.assertEqual(self.hero.actions.current_action, self.action_regenerate)
self.storage._test_save()
@mock.patch('the_tale.game.heroes.objects.Hero.can_regenerate_double_energy', False)
def test_full(self):
self.hero.change_energy(-self.hero.energy)
current_time = TimePrototype.get_current_time()
while len(self.hero.actions.actions_list) != 1:
self.storage.process_turn(continue_steps_if_needed=False)
current_time.increment_turn()
self.assertTrue(self.action_idl.leader)
self.assertEqual(self.hero.energy, self.hero.preferences.energy_regeneration_type.amount)
self.assertEqual(self.hero.need_regenerate_energy, False)
self.assertEqual(self.hero.last_energy_regeneration_at_turn, TimePrototype.get_current_turn_number()-1)
self.storage._test_save()
@mock.patch('the_tale.game.heroes.objects.Hero.can_regenerate_double_energy', True)
def test_full__double_energy(self):
self.hero.change_energy(-self.hero.energy)
current_time = TimePrototype.get_current_time()
while len(self.hero.actions.actions_list) != 1:
self.storage.process_turn(continue_steps_if_needed=False)
current_time.increment_turn()
self.assertTrue(self.action_idl.leader)
self.assertEqual(self.hero.energy, self.hero.preferences.energy_regeneration_type.amount * 2)
self.assertEqual(self.hero.need_regenerate_energy, False)
self.assertEqual(self.hero.last_energy_regeneration_at_turn, TimePrototype.get_current_turn_number()-1)
self.storage._test_save()
示例4: InPlaceActionSpendMoneyTest
# 需要导入模块: from the_tale.game.logic_storage import LogicStorage [as 别名]
# 或者: from the_tale.game.logic_storage.LogicStorage import _test_save [as 别名]
class InPlaceActionSpendMoneyTest(testcase.TestCase):
def setUp(self):
super(InPlaceActionSpendMoneyTest, self).setUp()
create_test_map()
result, account_id, bundle_id = register_user('test_user')
self.storage = LogicStorage()
self.storage.load_account_data(AccountPrototype.get_by_id(account_id))
self.hero = self.storage.accounts_to_heroes[account_id]
self.action_idl = self.hero.actions.current_action
self.action_inplace = prototypes.ActionInPlacePrototype.create(hero=self.hero)
def test_no_money(self):
self.hero.money = 1
self.storage.process_turn()
self.assertEqual(self.hero.money, 1)
self.assertEqual(self.hero.statistics.money_spend, 0)
self.storage._test_save()
@mock.patch('the_tale.game.heroes.objects.Hero.buy_price', lambda hero: -100)
def test_buy_price_less_than_zero(self):
money = self.hero.spend_amount
self.hero.money = money
self.assertEqual(self.action_inplace.try_to_spend_money(), 1)
self.assertEqual(self.hero.statistics.money_spend, 1)
def test_instant_heal(self):
while not self.hero.next_spending.is_INSTANT_HEAL:
self.hero.switch_spending()
money = self.hero.spend_amount
self.hero.money = money + 666
self.hero.health = 1
self.storage.process_turn()
self.assertEqual(self.hero.money, 666)
self.assertEqual(self.hero.health, self.hero.max_health)
self.assertEqual(self.hero.statistics.money_spend, money)
self.assertEqual(self.hero.statistics.money_spend_for_heal, money)
self.storage._test_save()
def test_instant_heal__switch_on_full_health(self):
while not self.hero.next_spending.is_INSTANT_HEAL:
self.hero.switch_spending()
money = self.hero.spend_amount
self.hero.money = money + 666
self.hero.health = self.hero.max_health
with mock.patch('the_tale.game.heroes.objects.Hero.switch_spending') as switch_spending:
self.storage.process_turn()
self.assertEqual(switch_spending.call_count, 1)
self.assertEqual(self.hero.money, money + 666)
self.assertEqual(self.hero.health, self.hero.max_health)
self.assertEqual(self.hero.statistics.money_spend, 0)
self.assertEqual(self.hero.statistics.money_spend_for_heal, 0)
self.storage._test_save()
def test_instant_heal__too_much_health(self):
while not self.hero.next_spending.is_INSTANT_HEAL:
self.hero.switch_spending()
money = self.hero.spend_amount
health = (self.hero.max_health * c.SPEND_MONEY_FOR_HEAL_HEALTH_FRACTION) + 1
self.hero.money = money + 666
self.hero.health = health
self.storage.process_turn()
self.assertTrue(self.hero.money, money + 666)
self.assertEqual(self.hero.health, health)
self.assertEqual(self.hero.statistics.money_spend, 0)
self.assertEqual(self.hero.statistics.money_spend_for_heal, 0)
self.storage._test_save()
def test_instant_heal__low_health(self):
while not self.hero.next_spending.is_INSTANT_HEAL:
self.hero.switch_spending()
money = self.hero.spend_amount
health = (self.hero.max_health * c.SPEND_MONEY_FOR_HEAL_HEALTH_FRACTION) - 1
self.hero.money = money
self.hero.health = health
self.storage.process_turn()
self.assertEqual(self.hero.money, 0)
self.assertEqual(self.hero.health, self.hero.max_health)
self.assertEqual(self.hero.statistics.money_spend, money)
self.assertEqual(self.hero.statistics.money_spend_for_heal, money)
#.........这里部分代码省略.........
示例5: InPlaceActionTest
# 需要导入模块: from the_tale.game.logic_storage import LogicStorage [as 别名]
# 或者: from the_tale.game.logic_storage.LogicStorage import _test_save [as 别名]
class InPlaceActionTest(testcase.TestCase, ActionEventsTestsMixin):
def setUp(self):
super(InPlaceActionTest, self).setUp()
create_test_map()
self.account = self.accounts_factory.create_account()
self.storage = LogicStorage()
self.storage.load_account_data(self.account)
self.hero = self.storage.accounts_to_heroes[self.account.id]
self.action_idl = self.hero.actions.current_action
self.hero.position.previous_place_id = None # test setting prevouse place in action constructor
self.action_inplace = prototypes.ActionInPlacePrototype.create(hero=self.hero)
self.action_event = self.action_inplace
def test_create(self):
self.assertEqual(self.hero.position.previous_place, None)
self.assertEqual(self.action_idl.leader, False)
self.assertEqual(self.action_inplace.leader, True)
self.assertEqual(self.action_inplace.bundle_id, self.action_idl.bundle_id)
self.storage._test_save()
@mock.patch('the_tale.game.places.objects.Place.is_modifier_active', lambda self: True)
def test_instant_heal_in_resort(self):
self.hero.health = 1
self.hero.position.place.set_modifier(places_modifiers.CITY_MODIFIERS.RESORT)
old_messages_len = len (self.hero.journal.messages)
prototypes.ActionInPlacePrototype.create(hero=self.hero)
self.assertEqual(self.hero.health, self.hero.max_health)
self.storage._test_save()
@mock.patch('the_tale.game.places.objects.Place.is_modifier_active', lambda self: True)
def test_no_instant_heal_in_resort(self):
self.hero.health = self.hero.max_health
self.hero.position.place.set_modifier(places_modifiers.CITY_MODIFIERS.RESORT)
old_messages_len = len (self.hero.journal.messages)
prototypes.ActionInPlacePrototype.create(hero=self.hero)
self.assertEqual(self.hero.health, self.hero.max_health)
self.storage._test_save()
@mock.patch('the_tale.game.places.objects.Place.is_modifier_active', lambda self: True)
def test_companion_heal_in_resort__no_companion(self):
self.assertEqual(self.hero.companion, None)
self.hero.position.place.set_modifier(places_modifiers.CITY_MODIFIERS.RESORT)
prototypes.ActionInPlacePrototype.create(hero=self.hero)
self.storage._test_save()
@mock.patch('the_tale.game.places.objects.Place.is_modifier_active', lambda self: True)
def test_companion_heal_in_resort__healed_companion(self):
companion_record = companions_storage.companions.enabled_companions().next()
self.hero.set_companion(companions_logic.create_companion(companion_record))
self.assertEqual(self.hero.companion.health, self.hero.companion.max_health)
self.hero.position.place.set_modifier(places_modifiers.CITY_MODIFIERS.RESORT)
prototypes.ActionInPlacePrototype.create(hero=self.hero)
self.assertFalse(self.hero.journal.messages[-1].key.is_ACTION_INPLACE_COMPANION_HEAL)
self.storage._test_save()
@mock.patch('the_tale.game.places.objects.Place.is_modifier_active', lambda self: True)
def test_companion_heal_in_resort__damaged_companion(self):
companion_record = companions_storage.companions.enabled_companions().next()
self.hero.set_companion(companions_logic.create_companion(companion_record))
self.hero.companion.health = 1
self.hero.position.place.set_modifier(places_modifiers.CITY_MODIFIERS.RESORT)
with self.check_increased(lambda: self.hero.companion.health):
prototypes.ActionInPlacePrototype.create(hero=self.hero)
self.assertTrue(self.hero.journal.messages[-1].key.is_ACTION_INPLACE_COMPANION_HEAL)
self.storage._test_save()
@mock.patch('the_tale.game.places.objects.Place.is_modifier_active', lambda self: True)
def test_instant_energy_regen_in_holy_city(self):
self.hero.energy = 0
self.hero.position.previous_place_id = None
self.hero.position.place.set_modifier(places_modifiers.CITY_MODIFIERS.HOLY_CITY)
self.assertNotEqual(self.hero.position.place, self.hero.position.previous_place)
prototypes.ActionInPlacePrototype.create(hero=self.hero)
#.........这里部分代码省略.........
示例6: IdlenessActionTest
# 需要导入模块: from the_tale.game.logic_storage import LogicStorage [as 别名]
# 或者: from the_tale.game.logic_storage.LogicStorage import _test_save [as 别名]
class IdlenessActionTest(testcase.TestCase):
def setUp(self):
super(IdlenessActionTest, self).setUp()
create_test_map()
result, account_id, bundle_id = register_user('test_user')
self.account = AccountPrototype.get_by_id(account_id)
self.storage = LogicStorage()
self.storage.load_account_data(self.account)
self.hero = self.storage.accounts_to_heroes[self.account.id]
self.action_idl = self.hero.actions.current_action
def tearDown(self):
pass
def test_create(self):
self.assertEqual(self.action_idl.leader, True)
self.assertEqual(self.action_idl.percents, 1.0)
self.storage._test_save()
def test_first_quest(self):
self.storage.process_turn()
self.assertEqual(len(self.hero.actions.actions_list), 2)
self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionQuestPrototype.TYPE)
self.assertEqual(self.action_idl.state, prototypes.ActionIdlenessPrototype.STATE.QUEST)
self.assertEqual(self.action_idl.bundle_id, self.hero.account_id)
self.storage._test_save()
def test_reset_percents_on_quest_end(self):
self.action_idl.percents = 1.0
self.action_idl.state = prototypes.ActionIdlenessPrototype.STATE.QUEST
self.storage.process_turn(continue_steps_if_needed=False)
self.assertEqual(self.action_idl.percents, 0.0)
def test_inplace(self):
self.action_idl.percents = 1.0
self.action_idl.state = prototypes.ActionIdlenessPrototype.STATE.QUEST
self.storage.process_turn(continue_steps_if_needed=False)
self.assertEqual(len(self.hero.actions.actions_list), 2)
self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionInPlacePrototype.TYPE)
self.assertEqual(self.action_idl.state, prototypes.ActionIdlenessPrototype.STATE.IN_PLACE)
self.storage._test_save()
def test_waiting(self):
self.action_idl.percents = 0.0
self.action_idl.state = prototypes.ActionIdlenessPrototype.STATE.IN_PLACE
self.storage.process_turn()
self.assertEqual(len(self.hero.actions.actions_list), 1)
self.assertEqual(self.hero.actions.current_action, self.action_idl)
self.assertEqual(self.action_idl.state, prototypes.ActionIdlenessPrototype.STATE.WAITING)
self.storage._test_save()
def test_regenerate_energy_action_create(self):
self.hero.preferences.set_energy_regeneration_type(heroes_relations.ENERGY_REGENERATION.PRAY)
self.hero.last_energy_regeneration_at_turn -= max(zip(*heroes_relations.ENERGY_REGENERATION.select('period'))[0])
self.action_idl.percents = 0.0
self.storage.process_turn()
self.assertEqual(len(self.hero.actions.actions_list), 2)
self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionRegenerateEnergyPrototype.TYPE)
self.storage._test_save()
def test_regenerate_energy_action_not_create_for_sacrifice(self):
self.action_idl.percents = 0
self.hero.preferences.set_energy_regeneration_type(heroes_relations.ENERGY_REGENERATION.SACRIFICE)
self.hero.last_energy_regeneration_at_turn -= max(zip(*heroes_relations.ENERGY_REGENERATION.select('period'))[0])
self.storage.process_turn()
self.assertEqual(len(self.hero.actions.actions_list), 1)
self.assertEqual(self.hero.actions.current_action, self.action_idl)
self.storage._test_save()
def test_full_waiting(self):
self.action_idl.state = prototypes.ActionIdlenessPrototype.STATE.WAITING
self.action_idl.percents = 0
current_time = TimePrototype.get_current_time()
for i in xrange(c.TURNS_TO_IDLE*self.hero.level):
self.storage.process_turn()
current_time.increment_turn()
self.assertEqual(len(self.hero.actions.actions_list), 1)
self.assertEqual(self.hero.actions.current_action, self.action_idl)
self.storage.process_turn()
self.assertEqual(len(self.hero.actions.actions_list), 2)
self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionQuestPrototype.TYPE)
self.assertEqual(self.action_idl.state, prototypes.ActionIdlenessPrototype.STATE.QUEST)
self.storage._test_save()
#.........这里部分代码省略.........
示例7: QuestActionTests
# 需要导入模块: from the_tale.game.logic_storage import LogicStorage [as 别名]
# 或者: from the_tale.game.logic_storage.LogicStorage import _test_save [as 别名]
class QuestActionTests(testcase.TestCase):
def setUp(self):
super(QuestActionTests, self).setUp()
create_test_map()
result, account_id, bundle_id = register_user('test_user')
self.storage = LogicStorage()
self.storage.load_account_data(AccountPrototype.get_by_id(account_id))
self.hero = self.storage.accounts_to_heroes[account_id]
self.action_idl = self.hero.actions.current_action
self.action_quest = prototypes.ActionQuestPrototype.create(hero=self.hero)
def test_create(self):
self.assertEqual(self.action_idl.leader, False)
self.assertEqual(self.action_quest.leader, True)
self.assertEqual(self.action_quest.state, self.action_quest.STATE.SEARCHING)
self.assertEqual(self.action_quest.bundle_id, self.action_idl.bundle_id)
self.assertFalse(self.hero.quests.has_quests)
self.storage._test_save()
def test_setup_quest(self):
quests_helpers.setup_quest(self.hero)
self.assertEqual(self.action_quest.state, self.action_quest.STATE.PROCESSING)
self.assertTrue(self.hero.quests.has_quests)
self.storage._test_save()
def test_one_step(self):
self.storage.process_turn()
# quest can create new action on first step
self.assertTrue(2 <= len(self.hero.actions.actions_list) <= 3)
self.storage._test_save()
def test_step_with_no_quest(self):
quests_helpers.setup_quest(self.hero)
self.hero.quests.pop_quest()
self.storage.process_turn()
self.assertEqual(self.action_idl.leader, True)
def test_need_equipping(self):
with mock.patch('the_tale.game.heroes.objects.Hero.need_equipping', lambda hero: True):
self.storage.process_turn()
self.assertEqual(self.action_quest.state, self.action_quest.STATE.EQUIPPING)
self.assertTrue(self.hero.actions.current_action.TYPE.is_EQUIPPING)
self.storage.process_turn()
self.assertEqual(self.action_quest.state, self.action_quest.STATE.EQUIPPING)
self.assertTrue(self.hero.actions.current_action.TYPE.is_QUEST)
self.storage.process_turn()
self.assertEqual(self.action_quest.state, self.action_quest.STATE.PROCESSING)
def test_full_quest(self):
current_time = TimePrototype.get_current_time()
# just test that quest will be ended
while not self.action_idl.leader:
self.storage.process_turn()
current_time.increment_turn()
self.storage._test_save()
self.assertFalse(self.hero.quests.has_quests)