本文整理汇总了Python中furious.context.Context.to_dict方法的典型用法代码示例。如果您正苦于以下问题:Python Context.to_dict方法的具体用法?Python Context.to_dict怎么用?Python Context.to_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类furious.context.Context
的用法示例。
在下文中一共展示了Context.to_dict方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_to_dict_with_callbacks
# 需要导入模块: from furious.context import Context [as 别名]
# 或者: from furious.context.Context import to_dict [as 别名]
def test_to_dict_with_callbacks(self):
"""Ensure to_dict correctly encodes callbacks."""
import copy
from furious.async import Async
from furious.context import Context
options = {
'persistence_engine': 'persistence_engine',
'callbacks': {
'success': self.__class__.test_to_dict_with_callbacks,
'failure': "failure_function",
'exec': Async(target=dir)
}
}
context = Context(**copy.deepcopy(options))
# This stuff gets dumped out by to_dict().
options.update({
'insert_tasks': 'furious.context.context._insert_tasks',
'persistence_engine': 'persistence_engine',
'_tasks_inserted': False,
'_task_ids': [],
'callbacks': {
'success': ("furious.tests.context.test_context."
"TestContext.test_to_dict_with_callbacks"),
'failure': "failure_function",
'exec': {'job': ('dir', None, None),
'_recursion': {'current': 0, 'max': 100},
'_type': 'furious.async.Async'}
}
})
self.assertEqual(options, context.to_dict())
示例2: test_store_context
# 需要导入模块: from furious.context import Context [as 别名]
# 或者: from furious.context.Context import to_dict [as 别名]
def test_store_context(self):
from furious.extras.appengine.ndb_persistence import store_context
from furious.extras.appengine.ndb_persistence import load_context
from furious.extras.appengine.ndb_persistence import ContextPersist
from furious.context import Context
ctx = Context()
ctx.add('test', args=[1, 2])
ctx_dict = ctx.to_dict()
store_context(ctx.id, ctx_dict)
ctx_persisted = ContextPersist.get_by_id(ctx.id)
self.assertIsNotNone(ctx_persisted)
reloaded_ctx = load_context(ctx.id)
self.assertEqual(reloaded_ctx, ctx_dict)
示例3: test_persist_persists
# 需要导入模块: from furious.context import Context [as 别名]
# 或者: from furious.context.Context import to_dict [as 别名]
def test_persist_persists(self):
"""Calling persist with an engine persists the Context."""
from furious.context import Context
persistence_engine = Mock()
persistence_engine.func_name = "persistence_engine"
persistence_engine.im_class.__name__ = "engine"
context = Context(persistence_engine=persistence_engine)
context.persist()
persistence_engine.store_context.assert_called_once_with(context.id, context.to_dict())
示例4: test_save_context
# 需要导入模块: from furious.context import Context [as 别名]
# 或者: from furious.context.Context import to_dict [as 别名]
def test_save_context(self):
"""Ensure the passed in context gets serialized and set on the saved
FuriousContext entity.
"""
_id = "contextid"
context = Context(id=_id)
result = store_context(context)
self.assertEqual(result.id(), _id)
loaded_context = FuriousContext.from_id(result.id())
self.assertEqual(context.to_dict(), loaded_context.to_dict())
示例5: test_to_dict
# 需要导入模块: from furious.context import Context [as 别名]
# 或者: from furious.context.Context import to_dict [as 别名]
def test_to_dict(self):
"""Ensure to_dict returns a dictionary representation of the Context.
"""
import copy
from furious.context import Context
options = {"persistence_engine": "persistence_engine", "unkown": True}
context = Context(**copy.deepcopy(options))
# This stuff gets dumped out by to_dict().
options.update(
{"insert_tasks": "furious.context.context._insert_tasks", "_tasks_inserted": False, "_task_ids": []}
)
self.assertEqual(options, context.to_dict())
示例6: test_to_dict_with_callbacks
# 需要导入模块: from furious.context import Context [as 别名]
# 或者: from furious.context.Context import to_dict [as 别名]
def test_to_dict_with_callbacks(self):
"""Ensure to_dict correctly encodes callbacks."""
import copy
from furious.async import Async
from furious.context import Context
options = {
"id": "someid",
"context_id": "contextid",
"parent_id": "parentid",
"persistence_engine": "persistence_engine",
"callbacks": {
"success": self.__class__.test_to_dict_with_callbacks,
"failure": "failure_function",
"exec": Async(target=dir, id="blargh", context_id="contextid", parent_id="parentid"),
},
}
context = Context(**copy.deepcopy(options))
# This stuff gets dumped out by to_dict().
options.update(
{
"id": "someid",
"insert_tasks": "furious.context.context._insert_tasks",
"persistence_engine": "persistence_engine",
"_tasks_inserted": False,
"_task_ids": [],
"callbacks": {
"success": ("furious.tests.context.test_context." "TestContext.test_to_dict_with_callbacks"),
"failure": "failure_function",
"exec": {
"job": ("dir", None, None),
"id": "blargh",
"context_id": "contextid",
"parent_id": "parentid",
"_recursion": {"current": 0, "max": 100},
"_type": "furious.async.Async",
},
},
}
)
self.assertEqual(options, context.to_dict())
示例7: test_to_dict
# 需要导入模块: from furious.context import Context [as 别名]
# 或者: from furious.context.Context import to_dict [as 别名]
def test_to_dict(self):
"""Ensure to_dict returns a dictionary representation of the Context.
"""
import copy
from furious.context import Context
options = {
'persistence_engine': 'persistence_engine',
'unkown': True,
}
context = Context(**copy.deepcopy(options))
# This stuff gets dumped out by to_dict().
options.update({
'insert_tasks': 'furious.context.context._insert_tasks',
'_tasks_inserted': False,
'_task_ids': [],
})
self.assertEqual(options, context.to_dict())