diff options
Diffstat (limited to 'test/test_exceptions.py')
-rw-r--r-- | test/test_exceptions.py | 178 |
1 files changed, 47 insertions, 131 deletions
diff --git a/test/test_exceptions.py b/test/test_exceptions.py index 2ec46cf..b0e2bb1 100644 --- a/test/test_exceptions.py +++ b/test/test_exceptions.py @@ -1,9 +1,7 @@ # -*- coding: utf-8 -*- import sys -from mako import compat from mako import exceptions -from mako.compat import u from mako.lookup import TemplateLookup from mako.template import Template from test import requires_no_pygments_exceptions @@ -68,53 +66,29 @@ class ExceptionsTest(TemplateTest): """test the html_error_template with a Template containing UTF-8 chars""" - if compat.py3k: - code = """# -*- coding: utf-8 -*- + 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 exceptions.CompileException: html_error = exceptions.html_error_template().render() - if compat.py3k: - assert ( - ( - "CompileException: Fragment 'if 2 == 2: /an " - "error' is not a partial control statement " - "at line: 2 char: 1" - ).encode(sys.getdefaultencoding(), "htmlentityreplace") - in html_error - ) - else: - assert ( + assert ( + ( "CompileException: Fragment 'if 2 == 2: /an " "error' is not a partial control statement " "at line: 2 char: 1" - ) in html_error + ).encode(sys.getdefaultencoding(), "htmlentityreplace") + in html_error + ) - if compat.py3k: - assert ( - "".encode(sys.getdefaultencoding(), "htmlentityreplace") - in html_error - ) - else: - assert ( - "'" - "привет" - ''</span><span class="cp">}</span>'.encode( - sys.getdefaultencoding(), "htmlentityreplace" - ) - in html_error - ) + assert ( + "".encode(sys.getdefaultencoding(), "htmlentityreplace") + in html_error + ) else: assert False, ( "This function should trigger a CompileException, " @@ -126,53 +100,30 @@ ${u'привет'} """test the html_error_template with a Template containing UTF-8 chars""" - if compat.py3k: - code = """# -*- coding: utf-8 -*- + 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 exceptions.CompileException: html_error = exceptions.html_error_template().render() - if compat.py3k: - assert ( - ( - "CompileException: Fragment 'if 2 == 2: /an " - "error' is not a partial control statement " - "at line: 2 char: 1" - ).encode(sys.getdefaultencoding(), "htmlentityreplace") - in html_error - ) - else: - assert ( + assert ( + ( "CompileException: Fragment 'if 2 == 2: /an " "error' 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("${u'привет'}").encode( - sys.getdefaultencoding(), "htmlentityreplace" - ) - in html_error + ).encode(sys.getdefaultencoding(), "htmlentityreplace") + in html_error + ) + assert ( + "${'привет'}".encode( + sys.getdefaultencoding(), "htmlentityreplace" ) + in html_error + ) else: assert False, ( "This function should trigger a CompileException, " @@ -189,29 +140,22 @@ ${u'привет'} def test_py_utf8_html_error_template(self): try: - foo = u("日本") # noqa + foo = "日本" # noqa raise RuntimeError("test") except: html_error = exceptions.html_error_template().render() - if compat.py3k: - assert "RuntimeError: test" in html_error.decode("utf-8") - assert "foo = u("日本")" in html_error.decode( - "utf-8" - ) or "foo = u("日本")" in html_error.decode("utf-8") - else: - assert "RuntimeError: test" in html_error - assert ( - "foo = u("日本")" in html_error - or "foo = u("日本")" in html_error - ) + assert "RuntimeError: test" in html_error.decode("utf-8") + assert "foo = "日本"" in html_error.decode( + "utf-8" + ) or "foo = "日本"" in html_error.decode("utf-8") def test_py_unicode_error_html_error_template(self): try: - raise RuntimeError(u("日本")) + raise RuntimeError("日本") except: html_error = exceptions.html_error_template().render() assert ( - u("RuntimeError: 日本").encode("ascii", "ignore") in html_error + "RuntimeError: 日本".encode("ascii", "ignore") in html_error ) @requires_pygments_14 @@ -267,25 +211,13 @@ ${foobar} 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}""", - ) + l.put_string( + "foo.html", """# -*- coding: utf-8 -*-\n${'привет' + foobar}""" + ) - if compat.py3k: - assert "'привет'</span>" in l.get_template( - "foo.html" - ).render().decode("utf-8") - else: - assert ( - "'прив" - "ет'</span>" - ) in l.get_template("foo.html").render().decode("utf-8") + assert "'привет'</span>" in l.get_template( + "foo.html" + ).render().decode("utf-8") @requires_no_pygments_exceptions def test_utf8_format_exceptions_no_pygments(self): @@ -293,31 +225,16 @@ ${foobar} 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}""", - ) + l.put_string( + "foo.html", """# -*- coding: utf-8 -*-\n${'привет' + foobar}""" + ) - if compat.py3k: - assert ( - '<div class="sourceline">${'привет' + foobar}</div>' - in result_lines( - l.get_template("foo.html").render().decode("utf-8") - ) - ) - else: - assert ( - "${u'приве" - "т' + foobar}" - in result_lines( - l.get_template("foo.html").render().decode("utf-8") - ) + assert ( + '<div class="sourceline">${'привет' + foobar}</div>' + in result_lines( + l.get_template("foo.html").render().decode("utf-8") ) + ) def test_mod_no_encoding(self): @@ -358,10 +275,6 @@ ${foobar} except: t, v, tback = sys.exc_info() - if not compat.py3k: - # blow away tracebaack info - sys.exc_clear() - # and don't even send what we have. html_error = exceptions.html_error_template().render_unicode( error=v, traceback=None @@ -457,7 +370,8 @@ def broken(): t.render() except: text_error = exceptions.text_error_template().render_unicode() - assert """ + assert ( + """ File "base.html", line 5, in render_body %> body starts here File "foo.html", line 4, in render_foo @@ -466,6 +380,8 @@ def broken(): ${broken()} File "base.html", line 4, in broken raise RuntimeError("Something went wrong.") -""" in text_error +""" + in text_error + ) else: assert False |