本文整理汇总了Python中pystache.renderer.Renderer.partials方法的典型用法代码示例。如果您正苦于以下问题:Python Renderer.partials方法的具体用法?Python Renderer.partials怎么用?Python Renderer.partials使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pystache.renderer.Renderer
的用法示例。
在下文中一共展示了Renderer.partials方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_make_load_partial__unicode
# 需要导入模块: from pystache.renderer import Renderer [as 别名]
# 或者: from pystache.renderer.Renderer import partials [as 别名]
def test_make_load_partial__unicode(self):
"""
Test _make_load_partial(): that load_partial doesn't "double-decode" Unicode.
"""
renderer = Renderer()
renderer.partials = {'partial': 'foo'}
load_partial = renderer._make_load_partial()
self.assertEquals(load_partial("partial"), "foo")
# Now with a value that is already unicode.
renderer.partials = {'partial': u'foo'}
load_partial = renderer._make_load_partial()
# If the next line failed, we would get the following error:
# TypeError: decoding Unicode is not supported
self.assertEquals(load_partial("partial"), "foo")
示例2: test_make_load_partial
# 需要导入模块: from pystache.renderer import Renderer [as 别名]
# 或者: from pystache.renderer.Renderer import partials [as 别名]
def test_make_load_partial(self):
"""
Test the _make_load_partial() method.
"""
renderer = Renderer()
renderer.partials = {'foo': 'bar'}
load_partial = renderer._make_load_partial()
actual = load_partial('foo')
self.assertEquals(actual, 'bar')
self.assertEquals(type(actual), unicode, "RenderEngine requires that "
"load_partial return unicode strings.")
示例3: test__load_partial__not_found
# 需要导入模块: from pystache.renderer import Renderer [as 别名]
# 或者: from pystache.renderer.Renderer import partials [as 别名]
def test__load_partial__not_found(self):
"""
Check that load_partial provides a nice message when a template is not found.
"""
renderer = Renderer()
renderer.partials = {}
engine = renderer._make_render_engine()
load_partial = engine.load_partial
try:
load_partial("foo")
raise Exception("Shouldn't get here")
except Exception, err:
self.assertEquals(str(err), "Partial not found with name: 'foo'")
示例4: test__load_partial__returns_unicode
# 需要导入模块: from pystache.renderer import Renderer [as 别名]
# 或者: from pystache.renderer.Renderer import partials [as 别名]
def test__load_partial__returns_unicode(self):
"""
Check that load_partial returns unicode (and not a subclass).
"""
class MyUnicode(unicode):
pass
renderer = Renderer()
renderer.default_encoding = 'ascii'
renderer.partials = {'str': 'foo', 'subclass': MyUnicode('abc')}
engine = renderer._make_render_engine()
actual = engine.load_partial('str')
self.assertEquals(actual, "foo")
self.assertEquals(type(actual), unicode)
# Check that unicode subclasses are not preserved.
actual = engine.load_partial('subclass')
self.assertEquals(actual, "abc")
self.assertEquals(type(actual), unicode)