~jonas-drange/ubuntu-start-page/1252899-mobile-friendly

« back to all changes in this revision

Viewing changes to src/Mako-0.1.9/test/exceptions_.py

  • Committer: Matthew Nuzum
  • Date: 2008-04-18 01:58:53 UTC
  • Revision ID: matthew.nuzum@canonical.com-20080418015853-2b8rf979z2c2exxl
adding files

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
import sys
 
3
import unittest
 
4
 
 
5
from mako import exceptions
 
6
from mako.template import Template
 
7
 
 
8
class ExceptionsTest(unittest.TestCase):
 
9
    def test_html_error_template(self):
 
10
        """test the html_error_template"""
 
11
        code = """
 
12
% i = 0
 
13
"""
 
14
        try:
 
15
            template = Template(code)
 
16
            template.render()
 
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>')
 
26
 
 
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
 
32
 
 
33
            no_css = exceptions.html_error_template().render(css=False)
 
34
            assert '<style>' not in no_css
 
35
            assert '</style>' not in no_css
 
36
        else:
 
37
            assert False, ("This function should trigger a CompileException, "
 
38
                           "but didn't")
 
39
 
 
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
 
44
${u'привет'}
 
45
% endif
 
46
"""
 
47
        try:
 
48
            template = Template(code)
 
49
            template.render()
 
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
 
57
        else:
 
58
            assert False, ("This function should trigger a CompileException, "
 
59
                           "but didn't")
 
60
            
 
61
if __name__ == '__main__':
 
62
    unittest.main()