本文整理汇总了Python中pystache.context.ContextStack类的典型用法代码示例。如果您正苦于以下问题:Python ContextStack类的具体用法?Python ContextStack怎么用?Python ContextStack使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ContextStack类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_get__precedence
def test_get__precedence(self):
"""
Test that get() respects the order of precedence (later items first).
"""
context = ContextStack({"foo": "bar"}, {"foo": "buzz"})
self.assertEqual(context.get("foo"), "buzz")
开发者ID:foursquare,项目名称:pystache,代码行数:7,代码来源:test_context.py
示例2: test_get__key_present
def test_get__key_present(self):
"""
Test getting a key.
"""
context = ContextStack({"foo": "bar"})
self.assertEqual(context.get("foo"), "bar")
开发者ID:foursquare,项目名称:pystache,代码行数:7,代码来源:test_context.py
示例3: test_dot_notation__missing_attr_or_key
def test_dot_notation__missing_attr_or_key(self):
name = "foo.bar.baz.bak"
stack = ContextStack({"foo": {"bar": {}}})
self.assertString(stack.get(name), "")
stack = ContextStack({"foo": Attachable(bar=Attachable())})
self.assertString(stack.get(name), "")
开发者ID:phihag,项目名称:py3stache,代码行数:7,代码来源:test_context.py
示例4: test_get__fallback
def test_get__fallback(self):
"""
Check that first-added stack items are queried on context misses.
"""
context = ContextStack({"fuzz": "buzz"}, {"foo": "bar"})
self.assertEqual(context.get("fuzz"), "buzz")
开发者ID:foursquare,项目名称:pystache,代码行数:7,代码来源:test_context.py
示例5: test_get__key_missing
def test_get__key_missing(self):
"""
Test getting a missing key.
"""
context = ContextStack()
self.assertString(context.get("foo"), "")
开发者ID:phihag,项目名称:py3stache,代码行数:7,代码来源:test_context.py
示例6: test_get__default
def test_get__default(self):
"""
Test that get() respects the default value.
"""
context = ContextStack()
self.assertEqual(context.get("foo", "bar"), "bar")
开发者ID:phihag,项目名称:py3stache,代码行数:7,代码来源:test_context.py
示例7: test_dot_notation__missing_part_terminates_search
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,代码行数:25,代码来源:test_context.py
示例8: test_get__single_dot
def test_get__single_dot(self):
"""
Test getting a single dot (".").
"""
context = ContextStack("a", "b")
self.assertEqual(context.get("."), "b")
开发者ID:foursquare,项目名称:pystache,代码行数:7,代码来源:test_context.py
示例9: test_dot_notation__list
def test_dot_notation__list(self):
""" Test that an index interger after a dot correctly grabs the item
if the parent is a list.
"""
name = "foo.1"
stack = ContextStack({"foo": ['Ignore me.', 'Choose me!']})
self.assertEqual(stack.get(name), "Choose me!")
开发者ID:mintchaos,项目名称:pystache,代码行数:8,代码来源:test_context.py
示例10: test_top
def test_top(self):
key = "foo"
context = ContextStack({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:foursquare,项目名称:pystache,代码行数:9,代码来源:test_context.py
示例11: test_dot_notation__dict
def test_dot_notation__dict(self):
name = "foo.bar"
stack = ContextStack({"foo": {"bar": "baz"}})
self.assertEqual(stack.get(name), "baz")
# Works all the way down
name = "a.b.c.d.e.f.g"
stack = ContextStack({"a": {"b": {"c": {"d": {"e": {"f": {"g": "w00t!"}}}}}}})
self.assertEqual(stack.get(name), "w00t!")
开发者ID:foursquare,项目名称:pystache,代码行数:9,代码来源:test_context.py
示例12: test_dot_notation_escaped
def test_dot_notation_escaped(self):
name = "foo\.bar"
stack = ContextStack({"foo.bar": "baz"})
self.assertEqual(stack.get(name), "baz")
# Works at any component depth.
name = "zoo.foo\.bar"
stack = ContextStack({"zoo": {"foo.bar": "baz"}})
self.assertEqual(stack.get(name), "baz")
开发者ID:foursquare,项目名称:pystache,代码行数:9,代码来源:test_context.py
示例13: test_dot_notation__user_object
def test_dot_notation__user_object(self):
name = "foo.bar"
stack = ContextStack({"foo": Attachable(bar="baz")})
self.assertEqual(stack.get(name), "baz")
# Works on multiple levels, too
name = "a.b.c.d.e.f.g"
A = Attachable
stack = ContextStack({"a": A(b=A(c=A(d=A(e=A(f=A(g="w00t!"))))))})
self.assertEqual(stack.get(name), "w00t!")
开发者ID:foursquare,项目名称:pystache,代码行数:10,代码来源:test_context.py
示例14: test_push
def test_push(self):
"""
Test push().
"""
key = "foo"
context = ContextStack({key: "bar"})
self.assertEqual(context.get(key), "bar")
context.push({key: "buzz"})
self.assertEqual(context.get(key), "buzz")
开发者ID:foursquare,项目名称:pystache,代码行数:11,代码来源:test_context.py
示例15: test_pop
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,代码行数:12,代码来源:test_context.py
示例16: test_dot_notation__autocall
def test_dot_notation__autocall(self):
name = "foo.bar.baz"
# When any element in the path is callable, it should be automatically invoked
stack = ContextStack({"foo": Attachable(bar=Attachable(baz=lambda: "Called!"))})
self.assertEqual(stack.get(name), "Called!")
class Foo(object):
def bar(self):
return Attachable(baz='Baz')
stack = ContextStack({"foo": Foo()})
self.assertEqual(stack.get(name), "Baz")
开发者ID:foursquare,项目名称:pystache,代码行数:13,代码来源:test_context.py
示例17: test_copy
def test_copy(self):
key = "foo"
original = ContextStack({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:foursquare,项目名称:pystache,代码行数:13,代码来源:test_context.py
示例18: test_create__precedence_positional
def test_create__precedence_positional(self):
"""
Test precedence of positional arguments.
"""
context = ContextStack.create({'foo': 'bar'}, {'foo': 'buzz'})
self.assertEqual(context.get('foo'), 'buzz')
开发者ID:foursquare,项目名称:pystache,代码行数:7,代码来源:test_context.py
示例19: test_create__none
def test_create__none(self):
"""
Test passing None.
"""
context = ContextStack.create({"foo": "bar"}, None)
self.assertEqual(context.get("foo"), "bar")
开发者ID:phihag,项目名称:py3stache,代码行数:7,代码来源:test_context.py
示例20: test_create__kwarg
def test_create__kwarg(self):
"""
Test passing a keyword argument.
"""
context = ContextStack.create(foo="bar")
self.assertEqual(context.get("foo"), "bar")
开发者ID:phihag,项目名称:py3stache,代码行数:7,代码来源:test_context.py
注:本文中的pystache.context.ContextStack类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论