예제 #1
0
 def _do_test_traceback(self, utf8, memory, syntax):
     if memory:
         if syntax:
             source = u('## coding: utf-8\n<% print "m’a réveillé. '\
                     'Elle disait: « S’il vous plaît… dessine-moi un mouton! » %>')
         else:
             source = u('## coding: utf-8\n<% print u"m’a réveillé. '\
                     'Elle disait: « S’il vous plaît… dessine-moi un mouton! »" + str(5/0) %>')
         if utf8:
             source = source.encode('utf-8')
         else:
             source = source
         templateargs = {'text': source}
     else:
         if syntax:
             filename = 'unicode_syntax_error.html'
         else:
             filename = 'unicode_runtime_error.html'
         source = util.read_file(self._file_path(filename), 'rb')
         if not utf8:
             source = source.decode('utf-8')
         templateargs = {'filename': self._file_path(filename)}
     try:
         template = Template(**templateargs)
         if not syntax:
             template.render_unicode()
         assert False
     except Exception:
         tback = errors.RichTraceback()
         if utf8:
             assert tback.source == source.decode('utf-8')
         else:
             assert tback.source == source
예제 #2
0
 def _do_test_traceback(self, utf8, memory, syntax):
     if memory:
         if syntax:
             source = u('## coding: utf-8\n<% print "m’a réveillé. '\
                     'Elle disait: « S’il vous plaît… dessine-moi un mouton! » %>')
         else:
             source = u('## coding: utf-8\n<% print u"m’a réveillé. '\
                     'Elle disait: « S’il vous plaît… dessine-moi un mouton! »" + str(5/0) %>')
         if utf8:
             source = source.encode('utf-8')
         else:
             source = source
         templateargs = {'text': source}
     else:
         if syntax:
             filename = 'unicode_syntax_error.html'
         else:
             filename = 'unicode_runtime_error.html'
         source = util.read_file(self._file_path(filename), 'rb')
         if not utf8:
             source = source.decode('utf-8')
         templateargs = {'filename': self._file_path(filename)}
     try:
         template = Template(**templateargs)
         if not syntax:
             template.render_unicode()
         assert False
     except Exception:
         tback = errors.RichTraceback()
         if utf8:
             assert tback.source == source.decode('utf-8')
         else:
             assert tback.source == source
예제 #3
0
    def test_html_error_template(self):
        """test the html_error_template"""
        code = """
% i = 0
"""
        try:
            template = Template(code)
            template.render_unicode()
            assert False
        except errors.CompileException:
            html_error = errors.html_error_template().render_unicode()
            assert ("CompileException: Fragment &#39;i = 0&#39; is not "
                    "a partial control statement at line: 2 char: 1") in html_error
            assert '<style>' in html_error
            html_error_stripped = html_error.strip()
            assert html_error_stripped.startswith('<html>')
            assert html_error_stripped.endswith('</html>')

            not_full = errors.html_error_template().\
                                    render_unicode(full=False)
            assert '<html>' not in not_full
            assert '<style>' in not_full

            no_css = errors.html_error_template().\
                                    render_unicode(css=False)
            assert '<style>' not in no_css
        else:
            assert False, ("This function should trigger a CompileException, "
                           "but didn't")
예제 #4
0
    def test_text_error_template(self):
        code = """
% i = 0
"""
        try:
            template = Template(code)
            template.render_unicode()
            assert False
        except errors.CompileException:
            text_error = errors.text_error_template().render_unicode()
            assert 'Traceback (most recent call last):' in text_error
            assert ("CompileException: Fragment 'i = 0' is not a partial "
                    "control statement") in text_error
예제 #5
0
 def test_encode_filter_non_str(self):
     t = Template("""# coding: utf-8
         some stuff.... ${x}
     """, default_filters=['decode.utf8'])
     eq_(
         t.render_unicode(x=3).strip(),
         u("some stuff.... 3")
     )
예제 #6
0
 def test_encode_filter(self):
     t = Template("""# coding: utf-8
         some stuff.... ${x}
     """, default_filters=['decode.utf8'])
     eq_(
         t.render_unicode(x=u("voix m’a réveillé")).strip(),
         u("some stuff.... voix m’a réveillé")
     )
예제 #7
0
 def test_encode_filter(self):
     t = Template("""# coding: utf-8
         some stuff.... ${x}
     """,
                  default_filters=['decode.utf8'])
     eq_(
         t.render_unicode(x=u("voix m’a réveillé")).strip(),
         u("some stuff.... voix m’a réveillé"))
예제 #8
0
 def test_encode_filter_non_str(self):
     t = Template("""# coding: utf-8
         some stuff.... ${x}
     """, default_filters=['decode.utf8'])
     eq_(
         t.render_unicode(x=3).strip(),
         u("some stuff.... 3")
     )
예제 #9
0
    def test_utf8_html_error_template_pygments(self):
        """test the html_error_template with a Template containing UTF-8
        chars"""

        if compat.py3k:
            code = """# -*- coding: utf-8 -*-
% if 2 == 2: /an error
${'привет'}
% endif
"""
        else:
            code = """# -*- coding: utf-8 -*-
% if 2 == 2: /an error
${u'привет'}
% endif
"""
        try:
            template = Template(code)
            template.render_unicode()
        except errors.CompileException:
            html_error = errors.html_error_template().render()
            if compat.py3k:
                assert ("CompileException: Fragment &#39;if 2 == 2: /an "
                    "error&#39; is not a partial control statement "
                    "at line: 2 char: 1").encode(sys.getdefaultencoding(), 'htmlentityreplace') in \
                    html_error
            else:
                assert ("CompileException: Fragment &#39;if 2 == 2: /an "
                        "error&#39; is not a partial control statement "
                        "at line: 2 char: 1") in \
                        html_error

            if compat.py3k:
                assert "".encode(sys.getdefaultencoding(),
                                        'htmlentityreplace') in html_error
            else:
                assert 'u&#39;'\
                        '&#x43F;&#x440;&#x438;&#x432;&#x435;&#x442;'\
                        '&#39;</span><span class="cp">}</span>'.encode(
                                sys.getdefaultencoding(),
                                'htmlentityreplace') in html_error
        else:
            assert False, ("This function should trigger a CompileException, "
                           "but didn't")
예제 #10
0
    def test_encode_filter_non_str_we_return_bytes(self):
        class Foo(object):
            def __str__(self):
                return compat.b("å")

        t = Template("""# coding: utf-8
            some stuff.... ${x}
        """,
                     default_filters=['decode.utf8'])
        eq_(t.render_unicode(x=Foo()).strip(), u("some stuff.... å"))
예제 #11
0
 def test_encode_filter_non_str_we_return_bytes(self):
     class Foo(object):
         def __str__(self):
             return compat.b("å")
     t = Template("""# coding: utf-8
         some stuff.... ${x}
     """, default_filters=['decode.utf8'])
     eq_(
         t.render_unicode(x=Foo()).strip(),
         u("some stuff.... å")
     )