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


Python Context.get方法代码示例

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


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

示例1: test_top

# 需要导入模块: from pystache.context import Context [as 别名]
# 或者: from pystache.context.Context import get [as 别名]
    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,代码行数:11,代码来源:test_context.py

示例2: test_push

# 需要导入模块: from pystache.context import Context [as 别名]
# 或者: from pystache.context.Context import get [as 别名]
    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,代码行数:13,代码来源:test_context.py

示例3: test_pop

# 需要导入模块: from pystache.context import Context [as 别名]
# 或者: from pystache.context.Context import get [as 别名]
    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,代码行数:14,代码来源:test_context.py

示例4: test_copy

# 需要导入模块: from pystache.context import Context [as 别名]
# 或者: from pystache.context.Context import get [as 别名]
    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,代码行数:15,代码来源:test_context.py

示例5: test_get__fallback

# 需要导入模块: from pystache.context import Context [as 别名]
# 或者: from pystache.context.Context import get [as 别名]
    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,代码行数:9,代码来源:test_context.py

示例6: test_get__precedence

# 需要导入模块: from pystache.context import Context [as 别名]
# 或者: from pystache.context.Context import get [as 别名]
    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,代码行数:9,代码来源:test_context.py

示例7: test_get__default

# 需要导入模块: from pystache.context import Context [as 别名]
# 或者: from pystache.context.Context import get [as 别名]
    def test_get__default(self):
        """
        Test that get() respects the default value.

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

示例8: test_get__key_missing

# 需要导入模块: from pystache.context import Context [as 别名]
# 或者: from pystache.context.Context import get [as 别名]
    def test_get__key_missing(self):
        """
        Test getting a missing key.

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

示例9: test_get__key_present

# 需要导入模块: from pystache.context import Context [as 别名]
# 或者: from pystache.context.Context import get [as 别名]
    def test_get__key_present(self):
        """
        Test getting a key.

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


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