Mercurial > genshi > mirror
annotate genshi/template/tests/text.py @ 1030:c5c5cbadde37 stable-0.7.x
Merge r1255 from trunk (fix slash escaping of CRLF newlines).
author | hodgestar |
---|---|
date | Wed, 19 Mar 2014 13:41:53 +0000 |
parents | 59a4949b4a39 |
children |
rev | line source |
---|---|
336
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
2 # |
854
4d9bef447df9
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
714
diff
changeset
|
3 # Copyright (C) 2006-2009 Edgewall Software |
336
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
4 # All rights reserved. |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
5 # |
7763f7aec949
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 |
7763f7aec949
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 |
7763f7aec949
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. |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
9 # |
7763f7aec949
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 |
7763f7aec949
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 |
7763f7aec949
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/. |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
13 |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
14 import doctest |
475
b373f80f7763
Added include directive for text templates (#115). Thanks to Alastair for the original patch.
cmlenz
parents:
418
diff
changeset
|
15 import os |
b373f80f7763
Added include directive for text templates (#115). Thanks to Alastair for the original patch.
cmlenz
parents:
418
diff
changeset
|
16 import shutil |
b373f80f7763
Added include directive for text templates (#115). Thanks to Alastair for the original patch.
cmlenz
parents:
418
diff
changeset
|
17 import tempfile |
336
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
18 import unittest |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
19 |
610
5e358de79e4c
* XInclude elements in markup templates now support the `parse` attribute; when set to "xml" (the default), the include is processed as before, but when set to "text", the included template is parsed as a text template using the new syntax (ticket #101).
cmlenz
parents:
609
diff
changeset
|
20 from genshi.template.base import TemplateSyntaxError |
475
b373f80f7763
Added include directive for text templates (#115). Thanks to Alastair for the original patch.
cmlenz
parents:
418
diff
changeset
|
21 from genshi.template.loader import TemplateLoader |
592
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
22 from genshi.template.text import OldTextTemplate, NewTextTemplate |
336
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
23 |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
24 |
592
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
25 class OldTextTemplateTestCase(unittest.TestCase): |
336
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
26 """Tests for text template processing.""" |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
27 |
475
b373f80f7763
Added include directive for text templates (#115). Thanks to Alastair for the original patch.
cmlenz
parents:
418
diff
changeset
|
28 def setUp(self): |
b373f80f7763
Added include directive for text templates (#115). Thanks to Alastair for the original patch.
cmlenz
parents:
418
diff
changeset
|
29 self.dirname = tempfile.mkdtemp(suffix='markup_test') |
b373f80f7763
Added include directive for text templates (#115). Thanks to Alastair for the original patch.
cmlenz
parents:
418
diff
changeset
|
30 |
b373f80f7763
Added include directive for text templates (#115). Thanks to Alastair for the original patch.
cmlenz
parents:
418
diff
changeset
|
31 def tearDown(self): |
b373f80f7763
Added include directive for text templates (#115). Thanks to Alastair for the original patch.
cmlenz
parents:
418
diff
changeset
|
32 shutil.rmtree(self.dirname) |
b373f80f7763
Added include directive for text templates (#115). Thanks to Alastair for the original patch.
cmlenz
parents:
418
diff
changeset
|
33 |
336
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
34 def test_escaping(self): |
592
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
35 tmpl = OldTextTemplate('\\#escaped') |
865 | 36 self.assertEqual('#escaped', tmpl.generate().render(encoding=None)) |
336
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
37 |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
38 def test_comment(self): |
592
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
39 tmpl = OldTextTemplate('## a comment') |
865 | 40 self.assertEqual('', tmpl.generate().render(encoding=None)) |
336
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
41 |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
42 def test_comment_escaping(self): |
592
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
43 tmpl = OldTextTemplate('\\## escaped comment') |
865 | 44 self.assertEqual('## escaped comment', |
45 tmpl.generate().render(encoding=None)) | |
336
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
46 |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
47 def test_end_with_args(self): |
592
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
48 tmpl = OldTextTemplate(""" |
336
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
49 #if foo |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
50 bar |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
51 #end 'if foo'""") |
865 | 52 self.assertEqual('\n', tmpl.generate(foo=False).render(encoding=None)) |
336
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
53 |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
54 def test_latin1_encoded(self): |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
55 text = u'$foo\xf6$bar'.encode('iso-8859-1') |
592
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
56 tmpl = OldTextTemplate(text, encoding='iso-8859-1') |
854
4d9bef447df9
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
714
diff
changeset
|
57 self.assertEqual(u'x\xf6y', |
4d9bef447df9
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
714
diff
changeset
|
58 tmpl.generate(foo='x', bar='y').render(encoding=None)) |
336
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
59 |
512
ed9f1300f3bf
Fix for #125 (text template handling unicode source). Thanks to Christian Boos for the patch.
cmlenz
parents:
475
diff
changeset
|
60 def test_unicode_input(self): |
ed9f1300f3bf
Fix for #125 (text template handling unicode source). Thanks to Christian Boos for the patch.
cmlenz
parents:
475
diff
changeset
|
61 text = u'$foo\xf6$bar' |
592
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
62 tmpl = OldTextTemplate(text) |
854
4d9bef447df9
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
714
diff
changeset
|
63 self.assertEqual(u'x\xf6y', |
4d9bef447df9
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
714
diff
changeset
|
64 tmpl.generate(foo='x', bar='y').render(encoding=None)) |
512
ed9f1300f3bf
Fix for #125 (text template handling unicode source). Thanks to Christian Boos for the patch.
cmlenz
parents:
475
diff
changeset
|
65 |
365
4f431931d64e
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
66 def test_empty_lines1(self): |
592
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
67 tmpl = OldTextTemplate("""Your items: |
365
4f431931d64e
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
68 |
4f431931d64e
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
69 #for item in items |
4f431931d64e
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
70 * ${item} |
4f431931d64e
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
71 #end""") |
4f431931d64e
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
72 self.assertEqual("""Your items: |
4f431931d64e
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
73 |
4f431931d64e
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
74 * 0 |
4f431931d64e
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
75 * 1 |
4f431931d64e
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
76 * 2 |
865 | 77 """, tmpl.generate(items=range(3)).render(encoding=None)) |
365
4f431931d64e
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
78 |
4f431931d64e
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
79 def test_empty_lines2(self): |
592
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
80 tmpl = OldTextTemplate("""Your items: |
365
4f431931d64e
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
81 |
4f431931d64e
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
82 #for item in items |
4f431931d64e
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
83 * ${item} |
4f431931d64e
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
84 |
4f431931d64e
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
85 #end""") |
4f431931d64e
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
86 self.assertEqual("""Your items: |
4f431931d64e
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
87 |
4f431931d64e
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
88 * 0 |
4f431931d64e
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
89 |
4f431931d64e
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
90 * 1 |
4f431931d64e
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
91 |
4f431931d64e
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
92 * 2 |
4f431931d64e
Fix for #62: preserve whitespace in front of directives.
cmlenz
parents:
336
diff
changeset
|
93 |
865 | 94 """, tmpl.generate(items=range(3)).render(encoding=None)) |
336
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
95 |
475
b373f80f7763
Added include directive for text templates (#115). Thanks to Alastair for the original patch.
cmlenz
parents:
418
diff
changeset
|
96 def test_include(self): |
995
59a4949b4a39
Merge r1217 from trunk (fix text template tests that were failing on Windows).
hodgestar
parents:
865
diff
changeset
|
97 file1 = open(os.path.join(self.dirname, 'tmpl1.txt'), 'wb') |
475
b373f80f7763
Added include directive for text templates (#115). Thanks to Alastair for the original patch.
cmlenz
parents:
418
diff
changeset
|
98 try: |
995
59a4949b4a39
Merge r1217 from trunk (fix text template tests that were failing on Windows).
hodgestar
parents:
865
diff
changeset
|
99 file1.write(u"Included\n".encode("utf-8")) |
475
b373f80f7763
Added include directive for text templates (#115). Thanks to Alastair for the original patch.
cmlenz
parents:
418
diff
changeset
|
100 finally: |
b373f80f7763
Added include directive for text templates (#115). Thanks to Alastair for the original patch.
cmlenz
parents:
418
diff
changeset
|
101 file1.close() |
336
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
102 |
995
59a4949b4a39
Merge r1217 from trunk (fix text template tests that were failing on Windows).
hodgestar
parents:
865
diff
changeset
|
103 file2 = open(os.path.join(self.dirname, 'tmpl2.txt'), 'wb') |
475
b373f80f7763
Added include directive for text templates (#115). Thanks to Alastair for the original patch.
cmlenz
parents:
418
diff
changeset
|
104 try: |
995
59a4949b4a39
Merge r1217 from trunk (fix text template tests that were failing on Windows).
hodgestar
parents:
865
diff
changeset
|
105 file2.write(u"""----- Included data below this line ----- |
475
b373f80f7763
Added include directive for text templates (#115). Thanks to Alastair for the original patch.
cmlenz
parents:
418
diff
changeset
|
106 #include tmpl1.txt |
995
59a4949b4a39
Merge r1217 from trunk (fix text template tests that were failing on Windows).
hodgestar
parents:
865
diff
changeset
|
107 ----- Included data above this line -----""".encode("utf-8")) |
475
b373f80f7763
Added include directive for text templates (#115). Thanks to Alastair for the original patch.
cmlenz
parents:
418
diff
changeset
|
108 finally: |
b373f80f7763
Added include directive for text templates (#115). Thanks to Alastair for the original patch.
cmlenz
parents:
418
diff
changeset
|
109 file2.close() |
b373f80f7763
Added include directive for text templates (#115). Thanks to Alastair for the original patch.
cmlenz
parents:
418
diff
changeset
|
110 |
b373f80f7763
Added include directive for text templates (#115). Thanks to Alastair for the original patch.
cmlenz
parents:
418
diff
changeset
|
111 loader = TemplateLoader([self.dirname]) |
592
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
112 tmpl = loader.load('tmpl2.txt', cls=OldTextTemplate) |
475
b373f80f7763
Added include directive for text templates (#115). Thanks to Alastair for the original patch.
cmlenz
parents:
418
diff
changeset
|
113 self.assertEqual("""----- Included data below this line ----- |
b373f80f7763
Added include directive for text templates (#115). Thanks to Alastair for the original patch.
cmlenz
parents:
418
diff
changeset
|
114 Included |
b373f80f7763
Added include directive for text templates (#115). Thanks to Alastair for the original patch.
cmlenz
parents:
418
diff
changeset
|
115 ----- Included data above this line -----""", |
865 | 116 tmpl.generate().render(encoding=None)) |
592
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
117 |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
118 |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
119 class NewTextTemplateTestCase(unittest.TestCase): |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
120 """Tests for text template processing.""" |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
121 |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
122 def setUp(self): |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
123 self.dirname = tempfile.mkdtemp(suffix='markup_test') |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
124 |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
125 def tearDown(self): |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
126 shutil.rmtree(self.dirname) |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
127 |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
128 def test_escaping(self): |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
129 tmpl = NewTextTemplate('\\{% escaped %}') |
865 | 130 self.assertEqual('{% escaped %}', |
131 tmpl.generate().render(encoding=None)) | |
592
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
132 |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
133 def test_comment(self): |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
134 tmpl = NewTextTemplate('{# a comment #}') |
865 | 135 self.assertEqual('', tmpl.generate().render(encoding=None)) |
592
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
136 |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
137 def test_comment_escaping(self): |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
138 tmpl = NewTextTemplate('\\{# escaped comment #}') |
865 | 139 self.assertEqual('{# escaped comment #}', |
140 tmpl.generate().render(encoding=None)) | |
592
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
141 |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
142 def test_end_with_args(self): |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
143 tmpl = NewTextTemplate(""" |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
144 {% if foo %} |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
145 bar |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
146 {% end 'if foo' %}""") |
865 | 147 self.assertEqual('\n', tmpl.generate(foo=False).render(encoding=None)) |
592
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
148 |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
149 def test_latin1_encoded(self): |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
150 text = u'$foo\xf6$bar'.encode('iso-8859-1') |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
151 tmpl = NewTextTemplate(text, encoding='iso-8859-1') |
854
4d9bef447df9
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
714
diff
changeset
|
152 self.assertEqual(u'x\xf6y', |
4d9bef447df9
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
714
diff
changeset
|
153 tmpl.generate(foo='x', bar='y').render(encoding=None)) |
592
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
154 |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
155 def test_unicode_input(self): |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
156 text = u'$foo\xf6$bar' |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
157 tmpl = NewTextTemplate(text) |
854
4d9bef447df9
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
714
diff
changeset
|
158 self.assertEqual(u'x\xf6y', |
4d9bef447df9
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
714
diff
changeset
|
159 tmpl.generate(foo='x', bar='y').render(encoding=None)) |
592
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
160 |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
161 def test_empty_lines1(self): |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
162 tmpl = NewTextTemplate("""Your items: |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
163 |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
164 {% for item in items %}\ |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
165 * ${item} |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
166 {% end %}""") |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
167 self.assertEqual("""Your items: |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
168 |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
169 * 0 |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
170 * 1 |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
171 * 2 |
865 | 172 """, tmpl.generate(items=range(3)).render(encoding=None)) |
592
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
173 |
1030
c5c5cbadde37
Merge r1255 from trunk (fix slash escaping of CRLF newlines).
hodgestar
parents:
995
diff
changeset
|
174 def test_empty_lines1_with_crlf(self): |
c5c5cbadde37
Merge r1255 from trunk (fix slash escaping of CRLF newlines).
hodgestar
parents:
995
diff
changeset
|
175 tmpl = NewTextTemplate('Your items:\r\n' |
c5c5cbadde37
Merge r1255 from trunk (fix slash escaping of CRLF newlines).
hodgestar
parents:
995
diff
changeset
|
176 '\r\n' |
c5c5cbadde37
Merge r1255 from trunk (fix slash escaping of CRLF newlines).
hodgestar
parents:
995
diff
changeset
|
177 '{% for item in items %}\\\r\n' |
c5c5cbadde37
Merge r1255 from trunk (fix slash escaping of CRLF newlines).
hodgestar
parents:
995
diff
changeset
|
178 ' * ${item}\r\n' |
c5c5cbadde37
Merge r1255 from trunk (fix slash escaping of CRLF newlines).
hodgestar
parents:
995
diff
changeset
|
179 '{% end %}') |
c5c5cbadde37
Merge r1255 from trunk (fix slash escaping of CRLF newlines).
hodgestar
parents:
995
diff
changeset
|
180 |
c5c5cbadde37
Merge r1255 from trunk (fix slash escaping of CRLF newlines).
hodgestar
parents:
995
diff
changeset
|
181 self.assertEqual('Your items:\r\n' |
c5c5cbadde37
Merge r1255 from trunk (fix slash escaping of CRLF newlines).
hodgestar
parents:
995
diff
changeset
|
182 '\r\n' |
c5c5cbadde37
Merge r1255 from trunk (fix slash escaping of CRLF newlines).
hodgestar
parents:
995
diff
changeset
|
183 ' * 0\r\n' |
c5c5cbadde37
Merge r1255 from trunk (fix slash escaping of CRLF newlines).
hodgestar
parents:
995
diff
changeset
|
184 ' * 1\r\n' |
c5c5cbadde37
Merge r1255 from trunk (fix slash escaping of CRLF newlines).
hodgestar
parents:
995
diff
changeset
|
185 ' * 2\r\n', tmpl.generate(items=range(3)).render(encoding=None)) |
c5c5cbadde37
Merge r1255 from trunk (fix slash escaping of CRLF newlines).
hodgestar
parents:
995
diff
changeset
|
186 |
592
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
187 def test_empty_lines2(self): |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
188 tmpl = NewTextTemplate("""Your items: |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
189 |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
190 {% for item in items %}\ |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
191 * ${item} |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
192 |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
193 {% end %}""") |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
194 self.assertEqual("""Your items: |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
195 |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
196 * 0 |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
197 |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
198 * 1 |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
199 |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
200 * 2 |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
201 |
865 | 202 """, tmpl.generate(items=range(3)).render(encoding=None)) |
592
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
203 |
1030
c5c5cbadde37
Merge r1255 from trunk (fix slash escaping of CRLF newlines).
hodgestar
parents:
995
diff
changeset
|
204 def test_empty_lines2_with_crlf(self): |
c5c5cbadde37
Merge r1255 from trunk (fix slash escaping of CRLF newlines).
hodgestar
parents:
995
diff
changeset
|
205 tmpl = NewTextTemplate('Your items:\r\n' |
c5c5cbadde37
Merge r1255 from trunk (fix slash escaping of CRLF newlines).
hodgestar
parents:
995
diff
changeset
|
206 '\r\n' |
c5c5cbadde37
Merge r1255 from trunk (fix slash escaping of CRLF newlines).
hodgestar
parents:
995
diff
changeset
|
207 '{% for item in items %}\\\r\n' |
c5c5cbadde37
Merge r1255 from trunk (fix slash escaping of CRLF newlines).
hodgestar
parents:
995
diff
changeset
|
208 ' * ${item}\r\n' |
c5c5cbadde37
Merge r1255 from trunk (fix slash escaping of CRLF newlines).
hodgestar
parents:
995
diff
changeset
|
209 '\r\n' |
c5c5cbadde37
Merge r1255 from trunk (fix slash escaping of CRLF newlines).
hodgestar
parents:
995
diff
changeset
|
210 '{% end %}') |
c5c5cbadde37
Merge r1255 from trunk (fix slash escaping of CRLF newlines).
hodgestar
parents:
995
diff
changeset
|
211 self.assertEqual('Your items:\r\n' |
c5c5cbadde37
Merge r1255 from trunk (fix slash escaping of CRLF newlines).
hodgestar
parents:
995
diff
changeset
|
212 '\r\n' |
c5c5cbadde37
Merge r1255 from trunk (fix slash escaping of CRLF newlines).
hodgestar
parents:
995
diff
changeset
|
213 ' * 0\r\n' |
c5c5cbadde37
Merge r1255 from trunk (fix slash escaping of CRLF newlines).
hodgestar
parents:
995
diff
changeset
|
214 '\r\n' |
c5c5cbadde37
Merge r1255 from trunk (fix slash escaping of CRLF newlines).
hodgestar
parents:
995
diff
changeset
|
215 ' * 1\r\n' |
c5c5cbadde37
Merge r1255 from trunk (fix slash escaping of CRLF newlines).
hodgestar
parents:
995
diff
changeset
|
216 '\r\n' |
c5c5cbadde37
Merge r1255 from trunk (fix slash escaping of CRLF newlines).
hodgestar
parents:
995
diff
changeset
|
217 ' * 2\r\n' |
c5c5cbadde37
Merge r1255 from trunk (fix slash escaping of CRLF newlines).
hodgestar
parents:
995
diff
changeset
|
218 '\r\n', tmpl.generate(items=range(3)).render(encoding=None)) |
c5c5cbadde37
Merge r1255 from trunk (fix slash escaping of CRLF newlines).
hodgestar
parents:
995
diff
changeset
|
219 |
609
6d4877844e28
Add support for Python code blocks in text templates using the new syntax.
cmlenz
parents:
605
diff
changeset
|
220 def test_exec_with_trailing_space(self): |
6d4877844e28
Add support for Python code blocks in text templates using the new syntax.
cmlenz
parents:
605
diff
changeset
|
221 """ |
6d4877844e28
Add support for Python code blocks in text templates using the new syntax.
cmlenz
parents:
605
diff
changeset
|
222 Verify that a code block with trailing space does not cause a syntax |
6d4877844e28
Add support for Python code blocks in text templates using the new syntax.
cmlenz
parents:
605
diff
changeset
|
223 error (see ticket #127). |
6d4877844e28
Add support for Python code blocks in text templates using the new syntax.
cmlenz
parents:
605
diff
changeset
|
224 """ |
858 | 225 NewTextTemplate(""" |
609
6d4877844e28
Add support for Python code blocks in text templates using the new syntax.
cmlenz
parents:
605
diff
changeset
|
226 {% python |
6d4877844e28
Add support for Python code blocks in text templates using the new syntax.
cmlenz
parents:
605
diff
changeset
|
227 bar = 42 |
6d4877844e28
Add support for Python code blocks in text templates using the new syntax.
cmlenz
parents:
605
diff
changeset
|
228 $} |
6d4877844e28
Add support for Python code blocks in text templates using the new syntax.
cmlenz
parents:
605
diff
changeset
|
229 """) |
6d4877844e28
Add support for Python code blocks in text templates using the new syntax.
cmlenz
parents:
605
diff
changeset
|
230 |
6d4877844e28
Add support for Python code blocks in text templates using the new syntax.
cmlenz
parents:
605
diff
changeset
|
231 def test_exec_import(self): |
858 | 232 tmpl = NewTextTemplate("""{% python from datetime import timedelta %} |
609
6d4877844e28
Add support for Python code blocks in text templates using the new syntax.
cmlenz
parents:
605
diff
changeset
|
233 ${timedelta(days=2)} |
6d4877844e28
Add support for Python code blocks in text templates using the new syntax.
cmlenz
parents:
605
diff
changeset
|
234 """) |
6d4877844e28
Add support for Python code blocks in text templates using the new syntax.
cmlenz
parents:
605
diff
changeset
|
235 self.assertEqual(""" |
6d4877844e28
Add support for Python code blocks in text templates using the new syntax.
cmlenz
parents:
605
diff
changeset
|
236 2 days, 0:00:00 |
865 | 237 """, tmpl.generate().render(encoding=None)) |
609
6d4877844e28
Add support for Python code blocks in text templates using the new syntax.
cmlenz
parents:
605
diff
changeset
|
238 |
6d4877844e28
Add support for Python code blocks in text templates using the new syntax.
cmlenz
parents:
605
diff
changeset
|
239 def test_exec_def(self): |
858 | 240 tmpl = NewTextTemplate("""{% python |
609
6d4877844e28
Add support for Python code blocks in text templates using the new syntax.
cmlenz
parents:
605
diff
changeset
|
241 def foo(): |
6d4877844e28
Add support for Python code blocks in text templates using the new syntax.
cmlenz
parents:
605
diff
changeset
|
242 return 42 |
6d4877844e28
Add support for Python code blocks in text templates using the new syntax.
cmlenz
parents:
605
diff
changeset
|
243 %} |
6d4877844e28
Add support for Python code blocks in text templates using the new syntax.
cmlenz
parents:
605
diff
changeset
|
244 ${foo()} |
6d4877844e28
Add support for Python code blocks in text templates using the new syntax.
cmlenz
parents:
605
diff
changeset
|
245 """) |
858 | 246 self.assertEqual(""" |
609
6d4877844e28
Add support for Python code blocks in text templates using the new syntax.
cmlenz
parents:
605
diff
changeset
|
247 42 |
865 | 248 """, tmpl.generate().render(encoding=None)) |
609
6d4877844e28
Add support for Python code blocks in text templates using the new syntax.
cmlenz
parents:
605
diff
changeset
|
249 |
592
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
250 def test_include(self): |
995
59a4949b4a39
Merge r1217 from trunk (fix text template tests that were failing on Windows).
hodgestar
parents:
865
diff
changeset
|
251 file1 = open(os.path.join(self.dirname, 'tmpl1.txt'), 'wb') |
592
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
252 try: |
995
59a4949b4a39
Merge r1217 from trunk (fix text template tests that were failing on Windows).
hodgestar
parents:
865
diff
changeset
|
253 file1.write(u"Included".encode("utf-8")) |
592
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
254 finally: |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
255 file1.close() |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
256 |
995
59a4949b4a39
Merge r1217 from trunk (fix text template tests that were failing on Windows).
hodgestar
parents:
865
diff
changeset
|
257 file2 = open(os.path.join(self.dirname, 'tmpl2.txt'), 'wb') |
592
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
258 try: |
995
59a4949b4a39
Merge r1217 from trunk (fix text template tests that were failing on Windows).
hodgestar
parents:
865
diff
changeset
|
259 file2.write(u"""----- Included data below this line ----- |
592
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
260 {% include tmpl1.txt %} |
995
59a4949b4a39
Merge r1217 from trunk (fix text template tests that were failing on Windows).
hodgestar
parents:
865
diff
changeset
|
261 ----- Included data above this line -----""".encode("utf-8")) |
592
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
262 finally: |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
263 file2.close() |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
264 |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
265 loader = TemplateLoader([self.dirname]) |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
266 tmpl = loader.load('tmpl2.txt', cls=NewTextTemplate) |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
267 self.assertEqual("""----- Included data below this line ----- |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
268 Included |
865 | 269 ----- Included data above this line -----""", |
270 tmpl.generate().render(encoding=None)) | |
592
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
271 |
693
35e143388705
Enable use of expressions in include directives of text templates. Closes #194. Thanks to Oliver Cope for reporting the issue.
cmlenz
parents:
629
diff
changeset
|
272 def test_include_expr(self): |
995
59a4949b4a39
Merge r1217 from trunk (fix text template tests that were failing on Windows).
hodgestar
parents:
865
diff
changeset
|
273 file1 = open(os.path.join(self.dirname, 'tmpl1.txt'), 'wb') |
693
35e143388705
Enable use of expressions in include directives of text templates. Closes #194. Thanks to Oliver Cope for reporting the issue.
cmlenz
parents:
629
diff
changeset
|
274 try: |
995
59a4949b4a39
Merge r1217 from trunk (fix text template tests that were failing on Windows).
hodgestar
parents:
865
diff
changeset
|
275 file1.write(u"Included".encode("utf-8")) |
693
35e143388705
Enable use of expressions in include directives of text templates. Closes #194. Thanks to Oliver Cope for reporting the issue.
cmlenz
parents:
629
diff
changeset
|
276 finally: |
35e143388705
Enable use of expressions in include directives of text templates. Closes #194. Thanks to Oliver Cope for reporting the issue.
cmlenz
parents:
629
diff
changeset
|
277 file1.close() |
35e143388705
Enable use of expressions in include directives of text templates. Closes #194. Thanks to Oliver Cope for reporting the issue.
cmlenz
parents:
629
diff
changeset
|
278 |
995
59a4949b4a39
Merge r1217 from trunk (fix text template tests that were failing on Windows).
hodgestar
parents:
865
diff
changeset
|
279 file2 = open(os.path.join(self.dirname, 'tmpl2.txt'), 'wb') |
693
35e143388705
Enable use of expressions in include directives of text templates. Closes #194. Thanks to Oliver Cope for reporting the issue.
cmlenz
parents:
629
diff
changeset
|
280 try: |
995
59a4949b4a39
Merge r1217 from trunk (fix text template tests that were failing on Windows).
hodgestar
parents:
865
diff
changeset
|
281 file2.write(u"""----- Included data below this line ----- |
693
35e143388705
Enable use of expressions in include directives of text templates. Closes #194. Thanks to Oliver Cope for reporting the issue.
cmlenz
parents:
629
diff
changeset
|
282 {% include ${'%s.txt' % ('tmpl1',)} %} |
995
59a4949b4a39
Merge r1217 from trunk (fix text template tests that were failing on Windows).
hodgestar
parents:
865
diff
changeset
|
283 ----- Included data above this line -----""".encode("utf-8")) |
693
35e143388705
Enable use of expressions in include directives of text templates. Closes #194. Thanks to Oliver Cope for reporting the issue.
cmlenz
parents:
629
diff
changeset
|
284 finally: |
35e143388705
Enable use of expressions in include directives of text templates. Closes #194. Thanks to Oliver Cope for reporting the issue.
cmlenz
parents:
629
diff
changeset
|
285 file2.close() |
35e143388705
Enable use of expressions in include directives of text templates. Closes #194. Thanks to Oliver Cope for reporting the issue.
cmlenz
parents:
629
diff
changeset
|
286 |
35e143388705
Enable use of expressions in include directives of text templates. Closes #194. Thanks to Oliver Cope for reporting the issue.
cmlenz
parents:
629
diff
changeset
|
287 loader = TemplateLoader([self.dirname]) |
35e143388705
Enable use of expressions in include directives of text templates. Closes #194. Thanks to Oliver Cope for reporting the issue.
cmlenz
parents:
629
diff
changeset
|
288 tmpl = loader.load('tmpl2.txt', cls=NewTextTemplate) |
35e143388705
Enable use of expressions in include directives of text templates. Closes #194. Thanks to Oliver Cope for reporting the issue.
cmlenz
parents:
629
diff
changeset
|
289 self.assertEqual("""----- Included data below this line ----- |
35e143388705
Enable use of expressions in include directives of text templates. Closes #194. Thanks to Oliver Cope for reporting the issue.
cmlenz
parents:
629
diff
changeset
|
290 Included |
865 | 291 ----- Included data above this line -----""", |
292 tmpl.generate().render(encoding=None)) | |
693
35e143388705
Enable use of expressions in include directives of text templates. Closes #194. Thanks to Oliver Cope for reporting the issue.
cmlenz
parents:
629
diff
changeset
|
293 |
592
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
294 |
336
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
295 def suite(): |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
296 suite = unittest.TestSuite() |
592
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
297 suite.addTest(doctest.DocTestSuite(NewTextTemplate.__module__)) |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
298 suite.addTest(unittest.makeSuite(OldTextTemplateTestCase, 'test')) |
1da8de3e5e51
Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents:
512
diff
changeset
|
299 suite.addTest(unittest.makeSuite(NewTextTemplateTestCase, 'test')) |
336
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
300 return suite |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
301 |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
302 if __name__ == '__main__': |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
303 unittest.main(defaultTest='suite') |