本文整理汇总了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")
示例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")
示例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")
示例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")
示例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")
示例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")
示例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")
示例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)
示例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")