From 2761023988c16498f726e2368f5381772390f54d Mon Sep 17 00:00:00 2001 From: Mike Bayer <mike_mp@zzzcomputing.com> Date: Fri, 18 May 2007 18:27:37 +0000 Subject: [PATCH] added exceptions unit test, changed myghtyutils to beaker in docs --- doc/build/content/caching.txt | 2 +- test/exceptions_.py | 62 +++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 test/exceptions_.py diff --git a/doc/build/content/caching.txt b/doc/build/content/caching.txt index e6dee41..113afd4 100644 --- a/doc/build/content/caching.txt +++ b/doc/build/content/caching.txt @@ -9,7 +9,7 @@ Any template or component can be cached using the `cache` argument to the `<%pag The above template, after being executed the first time, will store its content within a cache that by default is scoped within memory. Subsequent calls to the template's `render()` method will return content directly from the cache. When the `Template` object itself falls out of scope, its corresponding cache is garbage collected along with the template. -Caching requires that the `myghtyutils` package be installed on the system. +Caching requires that the `beaker` package be installed on the system. The caching flag and all its options can be used with the `<%def>` tag. diff --git a/test/exceptions_.py b/test/exceptions_.py new file mode 100644 index 0000000..0e5b83e --- /dev/null +++ b/test/exceptions_.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- +import sys +import unittest + +from mako import exceptions +from mako.template import Template + +class ExceptionsTest(unittest.TestCase): + def test_html_error_template(self): + """test the html_error_template""" + code = """ +% i = 0 +""" + try: + template = Template(code) + template.render() + except exceptions.CompileException, ce: + html_error = exceptions.html_error_template().render() + assert ("CompileException: Fragment 'i = 0' is not a partial " + "control statement") in html_error + assert '<style>' 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 = exceptions.html_error_template().render(full=False) + assert '<html>' not in not_full + assert '</html>' not in not_full + assert '<style>' in not_full + assert '</style>' in not_full + + no_css = exceptions.html_error_template().render(css=False) + assert '<style>' not in no_css + assert '</style>' not in no_css + else: + assert False, ("This function should trigger a CompileException, " + "but didn't") + + def test_utf8_html_error_template(self): + """test the html_error_template with a Template containing utf8 chars""" + code = """# -*- coding: utf-8 -*- +% if 2 == 2: # an innocently-looking comment +${u'привет'} +% endif +""" + try: + template = Template(code) + template.render() + except exceptions.CompileException, ce: + html_error = exceptions.html_error_template().render() + assert ("CompileException: Fragment 'if 2 == 2: # an " + "innocently-looking comment' is not a partial control " + "statement at line: 2 char: 1") in html_error + assert u"3 ${u'привет'}".encode(sys.getdefaultencoding(), + 'htmlentityreplace') in html_error + else: + assert False, ("This function should trigger a CompileException, " + "but didn't") + +if __name__ == '__main__': + unittest.main() -- GitLab