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


Python context.Context类代码示例

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


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

示例1: test_get__default

    def test_get__default(self):
        """
        Test that get() respects the default value.

        """
        context = Context()
        self.assertEqual(context.get("foo", "bar"), "bar")
开发者ID:tobiasandtobias,项目名称:pystache,代码行数:7,代码来源:test_context.py

示例2: test_get__fallback

    def test_get__fallback(self):
        """
        Check that first-added stack items are queried on context misses.

        """
        context = Context({"fuzz": "buzz"}, {"foo": "bar"})
        self.assertEqual(context.get("fuzz"), "buzz")
开发者ID:tobiasandtobias,项目名称:pystache,代码行数:7,代码来源:test_context.py

示例3: test_get__precedence

    def test_get__precedence(self):
        """
        Test that get() respects the order of precedence (later items first).

        """
        context = Context({"foo": "bar"}, {"foo": "buzz"})
        self.assertEqual(context.get("foo"), "buzz")
开发者ID:tobiasandtobias,项目名称:pystache,代码行数:7,代码来源:test_context.py

示例4: test_get__key_missing

    def test_get__key_missing(self):
        """
        Test getting a missing key.

        """
        context = Context()
        self.assertTrue(context.get("foo") is None)
开发者ID:tobiasandtobias,项目名称:pystache,代码行数:7,代码来源:test_context.py

示例5: test_get__key_present

    def test_get__key_present(self):
        """
        Test getting a key.

        """
        context = Context({"foo": "bar"})
        self.assertEqual(context.get("foo"), "bar")
开发者ID:tobiasandtobias,项目名称:pystache,代码行数:7,代码来源:test_context.py

示例6: test_top

    def test_top(self):
        key = "foo"
        context = Context({key: "bar"}, {key: "buzz"})
        self.assertEqual(context.get(key), "buzz")

        top = context.top()
        self.assertEqual(top, {"foo": "buzz"})
        # Make sure calling top() didn't remove the item from the stack.
        self.assertEqual(context.get(key), "buzz")
开发者ID:tobiasandtobias,项目名称:pystache,代码行数:9,代码来源:test_context.py

示例7: test_push

    def test_push(self):
        """
        Test push().

        """
        key = "foo"
        context = Context({key: "bar"})
        self.assertEqual(context.get(key), "bar")

        context.push({key: "buzz"})
        self.assertEqual(context.get(key), "buzz")
开发者ID:tobiasandtobias,项目名称:pystache,代码行数:11,代码来源:test_context.py

示例8: test_pop

    def test_pop(self):
        """
        Test pop().

        """
        key = "foo"
        context = Context({key: "bar"}, {key: "buzz"})
        self.assertEqual(context.get(key), "buzz")

        item = context.pop()
        self.assertEqual(item, {"foo": "buzz"})
        self.assertEqual(context.get(key), "bar")
开发者ID:tobiasandtobias,项目名称:pystache,代码行数:12,代码来源:test_context.py

示例9: test_copy

    def test_copy(self):
        key = "foo"
        original = Context({key: "bar"}, {key: "buzz"})
        self.assertEqual(original.get(key), "buzz")

        new = original.copy()
        # Confirm that the copy behaves the same.
        self.assertEqual(new.get(key), "buzz")
        # Change the copy, and confirm it is changed.
        new.pop()
        self.assertEqual(new.get(key), "bar")
        # Confirm the original is unchanged.
        self.assertEqual(original.get(key), "buzz")
开发者ID:tobiasandtobias,项目名称:pystache,代码行数:13,代码来源:test_context.py

示例10: test_create__kwarg

    def test_create__kwarg(self):
        """
        Test passing a keyword argument.

        """
        context = Context.create(foo='bar')
        self.assertEqual(context.get('foo'), 'bar')
开发者ID:tobiasandtobias,项目名称:pystache,代码行数:7,代码来源:test_context.py

示例11: test_create__none

    def test_create__none(self):
        """
        Test passing None.

        """
        context = Context.create({'foo': 'bar'}, None)
        self.assertEqual(context.get('foo'), 'bar')
开发者ID:tobiasandtobias,项目名称:pystache,代码行数:7,代码来源:test_context.py

示例12: test_create__precedence_positional

    def test_create__precedence_positional(self):
        """
        Test precedence of positional arguments.

        """
        context = Context.create({'foo': 'bar'}, {'foo': 'buzz'})
        self.assertEqual(context.get('foo'), 'buzz')
开发者ID:tobiasandtobias,项目名称:pystache,代码行数:7,代码来源:test_context.py

示例13: test_create__precedence_keyword

    def test_create__precedence_keyword(self):
        """
        Test precedence of keyword arguments.

        """
        context = Context.create({'foo': 'bar'}, foo='buzz')
        self.assertEqual(context.get('foo'), 'buzz')
开发者ID:tobiasandtobias,项目名称:pystache,代码行数:7,代码来源:test_context.py

示例14: test_create__dictionary

    def test_create__dictionary(self):
        """
        Test passing a dictionary.

        """
        context = Context.create({'foo': 'bar'})
        self.assertEqual(context.get('foo'), 'bar')
开发者ID:tobiasandtobias,项目名称:pystache,代码行数:7,代码来源:test_context.py

示例15: test_create__context

    def test_create__context(self):
        """
        Test passing a Context instance.

        """
        obj = Context({'foo': 'bar'})
        context = Context.create(obj)
        self.assertEqual(context.get('foo'), 'bar')
开发者ID:tobiasandtobias,项目名称:pystache,代码行数:8,代码来源:test_context.py


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