1
# -*- coding: utf-8 -*-
5
from mako import exceptions
6
from mako.template import Template
8
class ExceptionsTest(unittest.TestCase):
9
def test_html_error_template(self):
10
"""test the html_error_template"""
15
template = Template(code)
17
except exceptions.CompileException, ce:
18
html_error = exceptions.html_error_template().render()
19
assert ("CompileException: Fragment 'i = 0' is not a partial "
20
"control statement") in html_error
21
assert '<style>' in html_error
22
assert '</style>' in html_error
23
html_error_stripped = html_error.strip()
24
assert html_error_stripped.startswith('<html>')
25
assert html_error_stripped.endswith('</html>')
27
not_full = exceptions.html_error_template().render(full=False)
28
assert '<html>' not in not_full
29
assert '</html>' not in not_full
30
assert '<style>' in not_full
31
assert '</style>' in not_full
33
no_css = exceptions.html_error_template().render(css=False)
34
assert '<style>' not in no_css
35
assert '</style>' not in no_css
37
assert False, ("This function should trigger a CompileException, "
40
def test_utf8_html_error_template(self):
41
"""test the html_error_template with a Template containing utf8 chars"""
42
code = """# -*- coding: utf-8 -*-
43
% if 2 == 2: /an error
48
template = Template(code)
50
except exceptions.CompileException, ce:
51
html_error = exceptions.html_error_template().render()
52
assert ("CompileException: Fragment 'if 2 == 2: /an "
53
"error' is not a partial control "
54
"statement at line: 2 char: 1") in html_error
55
assert u"3 ${u'привет'}".encode(sys.getdefaultencoding(),
56
'htmlentityreplace') in html_error
58
assert False, ("This function should trigger a CompileException, "
61
if __name__ == '__main__':