本文整理汇总了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")
示例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")
示例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")
示例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)
示例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")
示例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")
示例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")
示例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")
示例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")
示例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')
示例11: test_create__none
def test_create__none(self):
"""
Test passing None.
"""
context = Context.create({'foo': 'bar'}, None)
self.assertEqual(context.get('foo'), 'bar')
示例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')
示例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')
示例14: test_create__dictionary
def test_create__dictionary(self):
"""
Test passing a dictionary.
"""
context = Context.create({'foo': 'bar'})
self.assertEqual(context.get('foo'), 'bar')
示例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')