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


Python LogicStorage._get_bundles_to_save方法代码示例

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


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

示例1: LogicStorageTests

# 需要导入模块: from the_tale.game.logic_storage import LogicStorage [as 别名]
# 或者: from the_tale.game.logic_storage.LogicStorage import _get_bundles_to_save [as 别名]

#.........这里部分代码省略.........
        with mock.patch('the_tale.game.heroes.prototypes.HeroPrototype.ui_info', ui_info):
            self.storage.save_changed_data()
            self.storage.process_turn()
            self.storage.save_changed_data()

        self.assertEqual(calls, [{'actual_guaranteed': True, 'old_info': None},
                                 {'actual_guaranteed': True, 'old_info': None},
                                 {'actual_guaranteed': True, 'old_info': {'hero': self.hero_1.id}},
                                 {'actual_guaranteed': True, 'old_info': {'hero': self.hero_2.id}}])


    def test_save_changed_data__old_info(self):
        self.storage.process_turn()
        self.storage.save_changed_data()

        self.storage.process_turn()

        with mock.patch('dext.common.utils.cache.set_many') as set_many:
            with mock.patch('the_tale.game.heroes.prototypes.HeroPrototype.ui_info') as ui_info:
                self.storage.save_changed_data()

        self.assertEqual(set_many.call_count, 1)
        self.assertEqual(ui_info.call_count, 2)
        self.assertNotEqual(ui_info.call_args_list[0][1]['old_info'], None)
        self.assertNotEqual(ui_info.call_args_list[1][1]['old_info'], None)


    @mock.patch('the_tale.game.heroes.conf.heroes_settings.DUMP_CACHED_HEROES', True)
    def test_save_changed_data__with_unsaved_bundles(self):
        self.storage.process_turn()

        self.assertEqual(len(self.storage.heroes), 2)

        with mock.patch('the_tale.game.logic_storage.LogicStorage._get_bundles_to_save', lambda x: [self.bundle_2_id]):
            with mock.patch('the_tale.game.logic_storage.LogicStorage._save_hero_data') as save_hero_data:
                with mock.patch('the_tale.game.heroes.prototypes.HeroPrototype.ui_info') as ui_info:
                    self.storage.save_changed_data()

        self.assertEqual(ui_info.call_count, 2) # cache all heroes, since they are new
        self.assertEqual(ui_info.call_args_list, [mock.call(actual_guaranteed=True, old_info=None), mock.call(actual_guaranteed=True, old_info=None)])
        self.assertEqual(save_hero_data.call_args, mock.call(self.hero_2.id))

    def test_save_changed_data__with_unsaved_bundles__without_dump(self):
        self.storage.process_turn()

        self.assertEqual(len(self.storage.heroes), 2)

        self.hero_2.ui_caching_started_at = datetime.datetime.fromtimestamp(0)

        with mock.patch('the_tale.game.logic_storage.LogicStorage._get_bundles_to_save', lambda x: [self.bundle_2_id]):
            with mock.patch('the_tale.game.logic_storage.LogicStorage._save_hero_data') as save_hero_data:
                with mock.patch('the_tale.game.heroes.prototypes.HeroPrototype.ui_info') as ui_info:
                    self.storage.save_changed_data()

        self.assertEqual(ui_info.call_count, 1) # cache only first hero
        self.assertEqual(ui_info.call_args, mock.call(actual_guaranteed=True, old_info=None))
        self.assertEqual(save_hero_data.call_args, mock.call(self.hero_2.id))

    def test_remove_action__from_middle(self):
        actions_prototypes.ActionRegenerateEnergyPrototype.create(hero=self.hero_1)
        self.assertRaises(exceptions.RemoveActionFromMiddleError, self.storage.remove_action, self.action_idl_1)

    def test_remove_action__metaaction(self):
        bundle_id = 666

        meta_action_battle = meta_actions.ArenaPvP1x1.create(self.storage, self.hero_1, self.hero_2)
开发者ID:alexudracul,项目名称:the-tale,代码行数:70,代码来源:test_logic_storage.py


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