Mercurial > genshi > genshi-test
annotate genshi/template/tests/text.py @ 418:878ffab274a6
Make expression error handling more strict. Closes #88.
author | cmlenz |
---|---|
date | Fri, 16 Mar 2007 08:58:54 +0000 |
parents | 85d910b8f9e5 |
children | bb939ed3058c 1c9250cc4365 |
rev | line source |
---|---|
336
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
2 # |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
3 # Copyright (C) 2006 Edgewall Software |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
4 # All rights reserved. |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
5 # |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
6 # This software is licensed as described in the file COPYING, which |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
7 # you should have received as part of this distribution. The terms |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
8 # are also available at http://genshi.edgewall.org/wiki/License. |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
9 # |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
10 # This software consists of voluntary contributions made by many |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
11 # individuals. For the exact contribution history, see the revision |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
12 # history and logs, available at http://genshi.edgewall.org/log/. |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
13 |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
14 import doctest |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
15 import unittest |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
16 |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
17 from genshi.template.text import TextTemplate |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
18 |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
19 |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
20 class TextTemplateTestCase(unittest.TestCase): |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
21 """Tests for text template processing.""" |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
22 |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
23 def test_escaping(self): |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
24 tmpl = TextTemplate('\\#escaped') |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
25 self.assertEqual('#escaped', str(tmpl.generate())) |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
26 |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
27 def test_comment(self): |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
28 tmpl = TextTemplate('## a comment') |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
29 self.assertEqual('', str(tmpl.generate())) |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
30 |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
31 def test_comment_escaping(self): |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
32 tmpl = TextTemplate('\\## escaped comment') |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
33 self.assertEqual('## escaped comment', str(tmpl.generate())) |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
34 |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
35 def test_end_with_args(self): |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
36 tmpl = TextTemplate(""" |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
37 #if foo |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
38 bar |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
39 #end 'if foo'""") |
418
878ffab274a6
Make expression error handling more strict. Closes #88.
cmlenz
parents:
365
diff
changeset
|
40 self.assertEqual('\n', str(tmpl.generate(foo=False))) |
336
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
41 |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
42 def test_latin1_encoded(self): |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
43 text = u'$foo\xf6$bar'.encode('iso-8859-1') |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
44 tmpl = TextTemplate(text, encoding='iso-8859-1') |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
45 self.assertEqual(u'x\xf6y', unicode(tmpl.generate(foo='x', bar='y'))) |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
46 |
365
85d910b8f9e5
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
47 def test_empty_lines1(self): |
85d910b8f9e5
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
48 tmpl = TextTemplate("""Your items: |
85d910b8f9e5
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
49 |
85d910b8f9e5
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
50 #for item in items |
85d910b8f9e5
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
51 * ${item} |
85d910b8f9e5
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
52 #end""") |
85d910b8f9e5
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
53 self.assertEqual("""Your items: |
85d910b8f9e5
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
54 |
85d910b8f9e5
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
55 * 0 |
85d910b8f9e5
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
56 * 1 |
85d910b8f9e5
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
57 * 2 |
85d910b8f9e5
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
58 """, tmpl.generate(items=range(3)).render('text')) |
85d910b8f9e5
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
59 |
85d910b8f9e5
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
60 def test_empty_lines2(self): |
85d910b8f9e5
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
61 tmpl = TextTemplate("""Your items: |
85d910b8f9e5
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
62 |
85d910b8f9e5
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
63 #for item in items |
85d910b8f9e5
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
64 * ${item} |
85d910b8f9e5
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
65 |
85d910b8f9e5
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
66 #end""") |
85d910b8f9e5
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
67 self.assertEqual("""Your items: |
85d910b8f9e5
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
68 |
85d910b8f9e5
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
69 * 0 |
85d910b8f9e5
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
70 |
85d910b8f9e5
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
71 * 1 |
85d910b8f9e5
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
72 |
85d910b8f9e5
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
73 * 2 |
85d910b8f9e5
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
74 |
85d910b8f9e5
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
75 """, tmpl.generate(items=range(3)).render('text')) |
336
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
76 |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
77 |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
78 def suite(): |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
79 suite = unittest.TestSuite() |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
80 suite.addTest(doctest.DocTestSuite(TextTemplate.__module__)) |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
81 suite.addTest(unittest.makeSuite(TextTemplateTestCase, 'test')) |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
82 return suite |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
83 |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
84 if __name__ == '__main__': |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
85 unittest.main(defaultTest='suite') |