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


Python util.result_lines函数代码示例

本文整理汇总了Python中test.util.result_lines函数的典型用法代码示例。如果您正苦于以下问题:Python result_lines函数的具体用法?Python result_lines怎么用?Python result_lines使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: test_utf8_format_exceptions_pygments

    def test_utf8_format_exceptions_pygments(self):
        """test that htmlentityreplace formatting is applied to
           exceptions reported with format_exceptions=True"""

        l = TemplateLookup(format_exceptions=True)
        if compat.py3k:
            l.put_string("foo.html", """# -*- coding: utf-8 -*-\n${'привет' + foobar}""")
        else:
            l.put_string("foo.html", """# -*- coding: utf-8 -*-\n${u'привет' + foobar}""")

        if compat.py3k:
            assert '<table class="error syntax-highlightedtable"><tr><td '\
                    'class="linenos"><div class="linenodiv"><pre>2</pre>'\
                    '</div></td><td class="code"><div class="error '\
                    'syntax-highlighted"><pre><span class="cp">${</span>'\
                    '<span class="s">&#39;привет&#39;</span> <span class="o">+</span> '\
                    '<span class="n">foobar</span><span class="cp">}</span>'\
                    '<span class="x"></span>' in \
                result_lines(l.get_template("foo.html").render().decode('utf-8'))
        else:
            assert '<table class="error syntax-highlightedtable"><tr><td '\
                    'class="linenos"><div class="linenodiv"><pre>2</pre>'\
                    '</div></td><td class="code"><div class="error '\
                    'syntax-highlighted"><pre><span class="cp">${</span>'\
                    '<span class="s">u&#39;&#x43F;&#x440;&#x438;&#x432;'\
                    '&#x435;&#x442;&#39;</span> <span class="o">+</span> '\
                    '<span class="n">foobar</span><span class="cp">}</span>'\
                    '<span class="x"></span>' in \
                result_lines(l.get_template("foo.html").render().decode('utf-8'))
开发者ID:Distrotech,项目名称:mako,代码行数:29,代码来源:test_exceptions.py

示例2: test_strict

    def test_strict(self):
        t = Template("""
            % if x is UNDEFINED:
                undefined
            % else:
                x: ${x}
            % endif
        """, strict_undefined=True)

        assert result_lines(t.render(x=12)) == ['x: 12']

        assert_raises(
            NameError,
            t.render, y=12
        )

        l = TemplateLookup(strict_undefined=True)
        l.put_string("a", "some template")
        l.put_string("b", """
            <%namespace name='a' file='a' import='*'/>
            % if x is UNDEFINED:
                undefined
            % else:
                x: ${x}
            % endif
        """)

        assert result_lines(t.render(x=12)) == ['x: 12']

        assert_raises(
            NameError,
            t.render, y=12
        )
开发者ID:SvenDowideit,项目名称:clearlinux,代码行数:33,代码来源:test_template.py

示例3: test_dynamic_key_with_funcargs

    def test_dynamic_key_with_funcargs(self):
        t = Template("""
            <%def name="foo(num=5)" cached="True" cache_key="foo_${str(num)}">
             hi
            </%def>

            ${foo()}
        """)
        m = self._install_mock_cache(t)
        t.render()
        t.render()
        assert result_lines(t.render()) == ['hi']
        assert m.key == "foo_5"

        t = Template("""
            <%def name="foo(*args, **kwargs)" cached="True"
             cache_key="foo_${kwargs['bar']}">
             hi
            </%def>

            ${foo(1, 2, bar='lala')}
        """)
        m = self._install_mock_cache(t)
        t.render()
        assert result_lines(t.render()) == ['hi']
        assert m.key == "foo_lala"

        t = Template('''
        <%page args="bar='hi'" cache_key="foo_${bar}" cached="True"/>
         hi
        ''')
        m = self._install_mock_cache(t)
        t.render()
        assert result_lines(t.render()) == ['hi']
        assert m.key == "foo_hi"
开发者ID:whiteclover,项目名称:Choco,代码行数:35,代码来源:test_cache.py

示例4: test_interpret_expression_from_arg_two

    def test_interpret_expression_from_arg_two(self):
        """test that cache_key=${foo} gets its value from
        the 'foo' argument regardless of it being passed
        from the context.

        This is here testing that there's no change
        to existing behavior before and after #191.

        """
        t = Template("""
        <%def name="layout(foo)" cached="True" cache_key="${foo}">
        foo: ${value}
        </%def>

        ${layout(3)}
        """, cache_impl="plain")

        eq_(
            result_lines(t.render(foo='foo', value=1)),
            ["foo: 1"]
        )
        eq_(
            result_lines(t.render(foo='bar', value=2)),
            ["foo: 1"]
        )
开发者ID:whiteclover,项目名称:Choco,代码行数:25,代码来源:test_def.py

示例5: test_pageargs

    def test_pageargs(self):
        collection = lookup.TemplateLookup()
        collection.put_string("base", """
            this is the base.

            <%
            sorted_ = pageargs.items()
            sorted_ = sorted(sorted_)
            %>
            pageargs: (type: ${type(pageargs)}) ${sorted_}
            <%def name="foo()">
                ${next.body(**context.kwargs)}
            </%def>

            ${foo()}
        """)
        collection.put_string("index", """
            <%inherit file="base"/>
            <%page args="x, y, z=7"/>
            print ${x}, ${y}, ${z}
        """)

        if compat.py3k:
            assert result_lines(collection.get_template('index').render_unicode(x=5,y=10)) == [
                "this is the base.",
                "pageargs: (type: <class 'dict'>) [('x', 5), ('y', 10)]",
                "print 5, 10, 7"
            ]
        else:
            assert result_lines(collection.get_template('index').render_unicode(x=5,y=10)) == [
                "this is the base.",
                "pageargs: (type: <type 'dict'>) [('x', 5), ('y', 10)]",
                "print 5, 10, 7"
            ]
开发者ID:whiteclover,项目名称:Choco,代码行数:34,代码来源:test_inheritance.py

示例6: test_module_roundtrip

    def test_module_roundtrip(self):
        lookup = TemplateLookup()

        template = Template("""
        <%inherit file="base.html"/>

        % for x in range(5):
            ${x}
        % endfor
""", lookup=lookup)

        base = Template("""
        This is base.
        ${self.body()}
""", lookup=lookup)

        lookup.put_template("base.html", base)
        lookup.put_template("template.html", template)

        assert result_lines(template.render()) == [
            "This is base.", "0", "1", "2", "3", "4"
        ]

        lookup = TemplateLookup()
        template = ModuleTemplate(template.module, lookup=lookup)
        base = ModuleTemplate(base.module, lookup=lookup)

        lookup.put_template("base.html", base)
        lookup.put_template("template.html", template)

        assert result_lines(template.render()) == [
            "This is base.", "0", "1", "2", "3", "4"
        ]
开发者ID:SvenDowideit,项目名称:clearlinux,代码行数:33,代码来源:test_template.py

示例7: test_dynamic_key_with_context

    def test_dynamic_key_with_context(self):
        t = Template(
            """
            <%block name="foo" cached="True" cache_key="${mykey}">
                some block
            </%block>
        """
        )
        m = self._install_mock_cache(t)
        t.render(mykey="thekey")
        t.render(mykey="thekey")
        eq_(result_lines(t.render(mykey="thekey")), ["some block"])
        eq_(m.key, "thekey")

        t = Template(
            """
            <%def name="foo()" cached="True" cache_key="${mykey}">
                some def
            </%def>
            ${foo()}
        """
        )
        m = self._install_mock_cache(t)
        t.render(mykey="thekey")
        t.render(mykey="thekey")
        eq_(result_lines(t.render(mykey="thekey")), ["some def"])
        eq_(m.key, "thekey")
开发者ID:margarethagan,项目名称:docassemble,代码行数:27,代码来源:test_cache.py

示例8: test_render

 def test_render(self):
     assert result_lines(tl.render({}, template='/index.html')) == [
         "this is index"
     ]
     assert result_lines(tl.render({}, template=compat.u('/index.html'))) == [
         "this is index"
     ]
开发者ID:Distrotech,项目名称:mako,代码行数:7,代码来源:test_tgplugin.py

示例9: test_undefined

    def test_undefined(self):
        t = Template("""
            % if x is UNDEFINED:
                undefined
            % else:
                x: ${x}
            % endif
        """)

        assert result_lines(t.render(x=12)) == ["x: 12"]
        assert result_lines(t.render(y=12)) == ["undefined"]
开发者ID:SvenDowideit,项目名称:clearlinux,代码行数:11,代码来源:test_template.py

示例10: test_lookup

 def test_lookup(self):
     l = TemplateLookup(cache_impl='mock')
     l.put_string("x", """
         <%page cached="True" />
         ${y}
     """)
     t = l.get_template("x")
     self._install_mock_cache(t)
     assert result_lines(t.render(y=5)) == ["5"]
     assert result_lines(t.render(y=7)) == ["5"]
     assert isinstance(t.cache.impl, MockCacheImpl)
开发者ID:whiteclover,项目名称:Choco,代码行数:11,代码来源:test_cache.py

示例11: test_preprocess2

 def test_preprocess2(self):
     t = """
     %call foo():
         hi
     %endcall
     """
     s = """
     <%call expr="foo()">
         hi
     </%call>
     """
     t = convert_calls(t)
     assert_equals(result_lines(t), result_lines(s))
开发者ID:marcpare,项目名称:mako-sugar,代码行数:13,代码来源:test_process.py

示例12: test_preprocess

 def test_preprocess(self):
     t = """
     % def foo():
         hi
     % enddef
     """
     s = """
     <%def name="foo()">
         hi
     </%def>
     """
     t = convert_defs(t)
     assert_equals(result_lines(t), result_lines(s))
开发者ID:marcpare,项目名称:mako-sugar,代码行数:13,代码来源:test_process.py

示例13: test_invalidate

    def test_invalidate(self):
        t = Template("""
            <%%def name="foo()" cached="True">
                foo: ${x}
            </%%def>

            <%%def name="bar()" cached="True" cache_type='dbm' cache_dir='%s'>
                bar: ${x}
            </%%def>
            ${foo()} ${bar()}
        """ % module_base)
        self._install_mock_cache(t)
        assert result_lines(t.render(x=1)) == ["foo: 1", "bar: 1"]
        assert result_lines(t.render(x=2)) == ["foo: 1", "bar: 1"]
        t.cache.invalidate_def('foo')
        assert result_lines(t.render(x=3)) == ["foo: 3", "bar: 1"]
        t.cache.invalidate_def('bar')
        assert result_lines(t.render(x=4)) == ["foo: 3", "bar: 4"]

        t = Template("""
            <%%page cached="True" cache_type="dbm" cache_dir="%s"/>

            page: ${x}
        """ % module_base)
        self._install_mock_cache(t)
        assert result_lines(t.render(x=1)) == ["page: 1"]
        assert result_lines(t.render(x=2)) == ["page: 1"]
        t.cache.invalidate_body()
        assert result_lines(t.render(x=3)) == ["page: 3"]
        assert result_lines(t.render(x=4)) == ["page: 3"]
开发者ID:whiteclover,项目名称:Choco,代码行数:30,代码来源:test_cache.py

示例14: test_ccall_caller

    def test_ccall_caller(self):
        t = Template("""
        <%def name="outer_func()">
        OUTER BEGIN
            <%call expr="caller.inner_func()">
                INNER CALL
            </%call>
        OUTER END
        </%def>

        <%call expr="outer_func()">
            <%def name="inner_func()">
                INNER BEGIN
                ${caller.body()}
                INNER END
            </%def>
        </%call>

        """)
        #print t.code
        assert result_lines(t.render()) == [
            "OUTER BEGIN",
            "INNER BEGIN",
            "INNER CALL",
            "INNER END",
            "OUTER END",
        ]
开发者ID:whiteclover,项目名称:Choco,代码行数:27,代码来源:test_call.py

示例15: test_basic

    def test_basic(self):
        t = Template("""
        <%!
            cached = None
        %>
        <%def name="foo()">
            <%
                global cached
                if cached:
                    return "cached: " + cached
                __M_writer = context._push_writer()
            %>
            this is foo
            <%
                buf, __M_writer = context._pop_buffer_and_writer()
                cached = buf.getvalue()
                return cached
            %>
        </%def>

        ${foo()}
        ${foo()}
""")
        assert result_lines(t.render()) == [
            "this is foo",
            "cached:",
            "this is foo"
        ]
开发者ID:whiteclover,项目名称:Choco,代码行数:28,代码来源:test_call.py


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