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


Python Renderer.partials方法代码示例

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


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

示例1: test_make_resolve_partial__unicode

# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import partials [as 别名]
    def test_make_resolve_partial__unicode(self):
        """
        Test _make_resolve_partial(): that resolve_partial doesn't "double-decode" Unicode.

        """
        renderer = Renderer()

        renderer.partials = {'partial': 'foo'}
        resolve_partial = renderer._make_resolve_partial()
        self.assertEqual(resolve_partial("partial"), "foo")

        # Now with a value that is already unicode.
        renderer.partials = {'partial': 'foo'}
        resolve_partial = renderer._make_resolve_partial()
        # If the next line failed, we would get the following error:
        #   TypeError: decoding Unicode is not supported
        self.assertEqual(resolve_partial("partial"), "foo")
开发者ID:Abixer,项目名称:croomcroom,代码行数:19,代码来源:test_renderer.py

示例2: test__resolve_partial__not_found__partials_dict

# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import partials [as 别名]
    def test__resolve_partial__not_found__partials_dict(self):
        """
        Check that resolve_partial returns the empty string when a template is not found.

        """
        renderer = Renderer()
        renderer.partials = {}

        engine = renderer._make_render_engine()
        resolve_partial = engine.resolve_partial

        self.assertString(resolve_partial('foo'), '')
开发者ID:Abixer,项目名称:croomcroom,代码行数:14,代码来源:test_renderer.py

示例3: test_make_resolve_partial

# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import partials [as 别名]
    def test_make_resolve_partial(self):
        """
        Test the _make_resolve_partial() method.

        """
        renderer = Renderer()
        renderer.partials = {'foo': 'bar'}
        resolve_partial = renderer._make_resolve_partial()

        actual = resolve_partial('foo')
        self.assertEqual(actual, 'bar')
        self.assertEqual(type(actual), str, "RenderEngine requires that "
            "resolve_partial return unicode strings.")
开发者ID:Abixer,项目名称:croomcroom,代码行数:15,代码来源:test_renderer.py

示例4: test__load_partial__not_found__dict

# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import partials [as 别名]
    def test__load_partial__not_found__dict(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

        # Include dict directly since str(dict) is different in Python 2 and 3:
        #   <type 'dict'> versus <class 'dict'>, respectively.
        self.assertException(TemplateNotFoundError, "Name 'foo' not found in partials: %s" % dict,
                             load_partial, "foo")
开发者ID:phihag,项目名称:py3stache,代码行数:17,代码来源:test_renderer.py

示例5: test__load_partial__not_found

# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.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'")
开发者ID:chuanzhang,项目名称:pystache,代码行数:18,代码来源:test_renderer.py

示例6: test__resolve_partial__returns_subclass

# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import partials [as 别名]
    def test__resolve_partial__returns_subclass(self):
        """Check that resolve_partial returns str (preserving any subclass)."""
        class MyUnicode(str):
            pass

        renderer = Renderer()
        renderer.string_encoding = 'ascii'
        renderer.partials = {'str': 'foo', 'subclass': MyUnicode('abc')}

        engine = renderer._make_render_engine()

        actual = engine.resolve_partial('str', None)
        self.assertEqual(actual, "foo")
        self.assertEqual(type(actual), str)

        # Check that unicode subclasses are not preserved.
        actual = engine.resolve_partial('subclass', None)
        self.assertEqual(actual, "abc")
        self.assertEqual(type(actual), MyUnicode)
开发者ID:GaloisInc,项目名称:echronos,代码行数:21,代码来源:test_renderer.py

示例7: test__load_partial__returns_unicode

# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import partials [as 别名]
    def test__load_partial__returns_unicode(self):
        """
        Check that load_partial returns unicode (and not a subclass).

        """
        class MyUnicode(str):
            pass

        renderer = Renderer()
        renderer.string_encoding = 'ascii'
        renderer.partials = {'str': 'foo', 'subclass': MyUnicode('abc')}

        engine = renderer._make_render_engine()

        actual = engine.load_partial('str')
        self.assertEqual(actual, "foo")
        self.assertEqual(type(actual), str)

        # Check that unicode subclasses are not preserved.
        actual = engine.load_partial('subclass')
        self.assertEqual(actual, "abc")
        self.assertEqual(type(actual), str)
开发者ID:phihag,项目名称:py3stache,代码行数:24,代码来源:test_renderer.py


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