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


Python ContextStack.pop方法代码示例

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


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

示例1: test_dot_notation__missing_part_terminates_search

# 需要导入模块: from pystache.context import ContextStack [as 别名]
# 或者: from pystache.context.ContextStack import pop [as 别名]
    def test_dot_notation__missing_part_terminates_search(self):
        """
        Test that dotted name resolution terminates on a later part not found.

        Check that if a later dotted name part is not found in the result from
        the former resolution, then name resolution terminates rather than
        starting the search over with the next element of the context stack.
        From the spec (interpolation section)--

          5) If any name parts were retained in step 1, each should be resolved
          against a context stack containing only the result from the former
          resolution.  If any part fails resolution, the result should be considered
          falsey, and should interpolate as the empty string.

        This test case is equivalent to the test case in the following pull
        request:

          https://github.com/mustache/spec/pull/48

        """
        stack = ContextStack({'a': {'b': 'A.B'}}, {'a': 'A'})
        self.assertEqual(stack.get('a'), 'A')
        self.assertException(KeyNotFoundError, "Key 'a.b' not found: missing 'b'", stack.get, "a.b")
        stack.pop()
        self.assertEqual(stack.get('a.b'), 'A.B')
开发者ID:foursquare,项目名称:pystache,代码行数:27,代码来源:test_context.py

示例2: test_pop

# 需要导入模块: from pystache.context import ContextStack [as 别名]
# 或者: from pystache.context.ContextStack import pop [as 别名]
    def test_pop(self):
        """
        Test pop().

        """
        key = "foo"
        context = ContextStack({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:foursquare,项目名称:pystache,代码行数:14,代码来源:test_context.py


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