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


Python Context.from_dict方法代码示例

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


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

示例1: test_from_dict_with_callbacks

# 需要导入模块: from furious.context import Context [as 别名]
# 或者: from furious.context.Context import from_dict [as 别名]
    def test_from_dict_with_callbacks(self):
        """Ensure from_dict reconstructs the Context callbacks correctly."""
        from furious.context import Context

        callbacks = {
            'success': ("furious.tests.context.test_context."
                        "TestContext.test_to_dict_with_callbacks"),
            'failure': "dir",
            'exec': {'job': ('id', None, None), 'id': 'myid',
                     'context_id': 'contextid',
                     'parent_id': 'parentid'}
        }

        context = Context.from_dict({'callbacks': callbacks})

        check_callbacks = {
            'success': TestContext.test_to_dict_with_callbacks,
            'failure': dir
        }

        callbacks = context._options.get('callbacks')
        exec_callback = callbacks.pop('exec')

        correct_dict = {'job': ('id', None, None),
                        'parent_id': 'parentid',
                        'id': 'myid',
                        'context_id': 'contextid',
                        '_recursion': {'current': 0, 'max': 100},
                        '_type': 'furious.async.Async'}

        self.assertEqual(check_callbacks, callbacks)
        self.assertEqual(correct_dict, exec_callback.to_dict())
开发者ID:Workiva,项目名称:furious,代码行数:34,代码来源:test_context.py

示例2: test_from_dict_with_callbacks

# 需要导入模块: from furious.context import Context [as 别名]
# 或者: from furious.context.Context import from_dict [as 别名]
    def test_from_dict_with_callbacks(self):
        """Ensure from_dict reconstructs the Context callbacks correctly."""
        from furious.context import Context

        callbacks = {
            "success": ("furious.tests.context.test_context." "TestContext.test_to_dict_with_callbacks"),
            "failure": "dir",
            "exec": {"job": ("id", None, None), "id": "myid", "context_id": "contextid", "parent_id": "parentid"},
        }

        context = Context.from_dict({"callbacks": callbacks})

        check_callbacks = {"success": TestContext.test_to_dict_with_callbacks, "failure": dir}

        callbacks = context._options.get("callbacks")
        exec_callback = callbacks.pop("exec")

        correct_dict = {
            "job": ("id", None, None),
            "parent_id": "parentid",
            "id": "myid",
            "context_id": "contextid",
            "_recursion": {"current": 0, "max": 100},
            "_type": "furious.async.Async",
        }

        self.assertEqual(check_callbacks, callbacks)
        self.assertEqual(correct_dict, exec_callback.to_dict())
开发者ID:thianpengter-wf,项目名称:furious,代码行数:30,代码来源:test_context.py

示例3: test_from_dict

# 需要导入模块: from furious.context import Context [as 别名]
# 或者: from furious.context.Context import from_dict [as 别名]
    def test_from_dict(self):
        """Ensure from_dict returns the correct Context object."""
        from furious.context import Context

        from furious.context.context import _insert_tasks

        # TODO: persistence_engine needs set to a real persistence module.

        options = {
            'id': 123456,
            'insert_tasks': 'furious.context.context._insert_tasks',
            'random_option': 'avalue',
            '_tasks_inserted': True,
            '_task_ids': [1, 2, 3, 4],
            'persistence_engine': 'furious.context.context.Context'
        }

        context = Context.from_dict(options)

        self.assertEqual(123456, context.id)
        self.assertEqual([1, 2, 3, 4], context.task_ids)
        self.assertEqual(True, context._tasks_inserted)
        self.assertEqual('avalue', context._options.get('random_option'))
        self.assertEqual(_insert_tasks, context._insert_tasks)
        self.assertEqual(Context, context._persistence_engine)
开发者ID:Workiva,项目名称:furious,代码行数:27,代码来源:test_context.py

示例4: test_from_dict

# 需要导入模块: from furious.context import Context [as 别名]
# 或者: from furious.context.Context import from_dict [as 别名]
    def test_from_dict(self):
        """Ensure from_dict returns the correct Context object."""
        from furious.context import Context

        from furious.context.context import _insert_tasks

        # TODO: persistence_engine needs set to a real persistence module.

        options = {
            "id": 123456,
            "insert_tasks": "furious.context.context._insert_tasks",
            "random_option": "avalue",
            "_tasks_inserted": True,
            "_task_ids": [1, 2, 3, 4],
            "persistence_engine": "furious.context.context.Context",
        }

        context = Context.from_dict(options)

        self.assertEqual(123456, context.id)
        self.assertEqual([1, 2, 3, 4], context.task_ids)
        self.assertEqual(True, context._tasks_inserted)
        self.assertEqual("avalue", context._options.get("random_option"))
        self.assertEqual(_insert_tasks, context._insert_tasks)
        self.assertEqual(Context, context._persistence_engine)
开发者ID:thianpengter-wf,项目名称:furious,代码行数:27,代码来源:test_context.py

示例5: from_id

# 需要导入模块: from furious.context import Context [as 别名]
# 或者: from furious.context.Context import from_dict [as 别名]
    def from_id(cls, id):
        """Load a `cls` entity and instantiate the Context it stores."""
        from furious.context import Context

        # TODO: Handle exceptions and retries here.
        entity = cls.get_by_id(id)
        if not entity:
            raise FuriousContextNotFoundError(
                "Context entity not found for: {}".format(id))

        return Context.from_dict(entity.context)
开发者ID:Workiva,项目名称:furious,代码行数:13,代码来源:ndb_persistence.py

示例6: test_load_context

# 需要导入模块: from furious.context import Context [as 别名]
# 或者: from furious.context.Context import from_dict [as 别名]
    def test_load_context(self):
        """Calling load with an engine attempts to load the Context."""
        from furious.context import Context

        persistence_engine = Mock()
        persistence_engine.func_name = "persistence_engine"
        persistence_engine.im_class.__name__ = "engine"
        persistence_engine.load_context.return_value = Context.from_dict({"id": "ABC123"})

        context = Context.load("ABC123", persistence_engine)

        persistence_engine.load_context.assert_called_once_with("ABC123")
        self.assertEqual("ABC123", context.id)
开发者ID:thianpengter-wf,项目名称:furious,代码行数:15,代码来源:test_context.py

示例7: test_load_context

# 需要导入模块: from furious.context import Context [as 别名]
# 或者: from furious.context.Context import from_dict [as 别名]
    def test_load_context(self):
        """Calling load with an engine attempts to load the Context."""
        from furious.context import Context

        persistence_engine = Mock()
        persistence_engine.func_name = 'persistence_engine'
        persistence_engine.im_class.__name__ = 'engine'
        persistence_engine.load_context.return_value = Context.from_dict(
            {'id': 'ABC123'})

        context = Context.load('ABC123', persistence_engine)

        persistence_engine.load_context.assert_called_once_with('ABC123')
        self.assertEqual('ABC123', context.id)
开发者ID:Workiva,项目名称:furious,代码行数:16,代码来源:test_context.py

示例8: test_reconstitution

# 需要导入模块: from furious.context import Context [as 别名]
# 或者: from furious.context.Context import from_dict [as 别名]
    def test_reconstitution(self):
        """Ensure to_dict(job.from_dict()) returns the same thing."""
        from furious.context import Context

        options = {
            "id": 123098,
            "insert_tasks": "furious.context.context._insert_tasks",
            "persistence_engine": "furious.job_utils.get_function_path_and_options",
            "_tasks_inserted": True,
            "_task_ids": [],
        }

        context = Context.from_dict(options)

        self.assertEqual(options, context.to_dict())
开发者ID:ericolson-wf,项目名称:furious,代码行数:17,代码来源:test_context.py

示例9: test_reconstitution

# 需要导入模块: from furious.context import Context [as 别名]
# 或者: from furious.context.Context import from_dict [as 别名]
    def test_reconstitution(self):
        """Ensure to_dict(job.from_dict()) returns the same thing."""
        from furious.context import Context

        options = {
            'id': 123098,
            'insert_tasks': 'furious.context.context._insert_tasks',
            'persistence_engine':
            'furious.job_utils.get_function_path_and_options',
            '_tasks_inserted': True,
            '_task_ids': []
        }

        context = Context.from_dict(options)

        self.assertEqual(options, context.to_dict())
开发者ID:dustinhiatt-wf,项目名称:furious,代码行数:18,代码来源:test_context.py


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