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


Python context.Context类代码示例

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


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

示例1: test_to_dict_with_callbacks

    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())
开发者ID:dustinhiatt-wf,项目名称:furious,代码行数:35,代码来源:test_context.py

示例2: test_store_context

 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)
开发者ID:johnlockwood-wf,项目名称:furious,代码行数:13,代码来源:test_ndb_persistence.py

示例3: test_persist_persists

    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:Workiva,项目名称:furious,代码行数:13,代码来源:test_context.py

示例4: test_load_context

    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,代码行数:13,代码来源:test_context.py

示例5: test_load_context

    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,代码行数:14,代码来源:test_context.py

示例6: test_save_context

    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())
开发者ID:brentarndorfer-wf,项目名称:furious,代码行数:15,代码来源:test_ndb_persistence.py

示例7: test_has_errors_with_marker_cached

    def test_has_errors_with_marker_cached(self):
        """Ensure returns the value from the marker when cached."""
        context_id = 1

        marker = FuriousCompletionMarker(id=context_id, has_errors=True)
        marker.put()

        context = Context(id=context_id)
        context._marker = marker
        context_result = ContextResult(context)

        self.assertIsNone(context_result._marker)
        self.assertTrue(context_result.has_errors())

        marker.key.delete()
开发者ID:brentarndorfer-wf,项目名称:furious,代码行数:15,代码来源:test_ndb_persistence.py

示例8: test_from_dict_with_callbacks

    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,代码行数:32,代码来源:test_context.py

示例9: test_from_dict_with_callbacks

    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,代码行数:28,代码来源:test_context.py

示例10: test_from_dict

    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,代码行数:25,代码来源:test_context.py

示例11: test_from_dict

    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,代码行数:25,代码来源:test_context.py

示例12: test_to_dict

    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())
开发者ID:ericolson-wf,项目名称:furious,代码行数:17,代码来源:test_context.py

示例13: test_to_dict_with_callbacks

    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())
开发者ID:thianpengter-wf,项目名称:furious,代码行数:45,代码来源:test_context.py

示例14: from_id

    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,代码行数:11,代码来源:ndb_persistence.py

示例15: test_to_dict

    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())
开发者ID:dustinhiatt-wf,项目名称:furious,代码行数:22,代码来源:test_context.py


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