annotate genshi/template/tests/markup.py @ 656:3a3562e40a7e

Add unit test for #157, which seems to be working okay in trunk.
author cmlenz
date Thu, 22 Nov 2007 20:04:23 +0000
parents 0413c8817a3c
children 8d079cee6822
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 #
408
49a3bae5a8bb Update copyright year for files modified this year.
cmlenz
parents: 405
diff changeset
3 # Copyright (C) 2006-2007 Edgewall Software
336
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
363
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
15 import os
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
16 import shutil
374
ca46dc9c7761 `MarkupTemplate`s can now be instantiated from markup streams, in addition to strings and file-like objects. Thanks to David Fraser for the patch. Closes #69.
cmlenz
parents: 363
diff changeset
17 from StringIO import StringIO
336
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
18 import sys
363
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
19 import tempfile
336
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
20 import unittest
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
21
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
22 from genshi.core import Markup
374
ca46dc9c7761 `MarkupTemplate`s can now be instantiated from markup streams, in addition to strings and file-like objects. Thanks to David Fraser for the patch. Closes #69.
cmlenz
parents: 363
diff changeset
23 from genshi.input import XML
400
8dd0d34a9fb7 Renamed `genshi.template.core` to `genshi.template.base`, mainly to avoid confusion with `genshi.core`.
cmlenz
parents: 381
diff changeset
24 from genshi.template.base import BadDirectiveError, TemplateSyntaxError
590
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
25 from genshi.template.loader import TemplateLoader, TemplateNotFound
336
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
26 from genshi.template.markup import MarkupTemplate
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
27
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
28
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
29 class MarkupTemplateTestCase(unittest.TestCase):
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
30 """Tests for markup template processing."""
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
31
374
ca46dc9c7761 `MarkupTemplate`s can now be instantiated from markup streams, in addition to strings and file-like objects. Thanks to David Fraser for the patch. Closes #69.
cmlenz
parents: 363
diff changeset
32 def test_parse_fileobj(self):
ca46dc9c7761 `MarkupTemplate`s can now be instantiated from markup streams, in addition to strings and file-like objects. Thanks to David Fraser for the patch. Closes #69.
cmlenz
parents: 363
diff changeset
33 fileobj = StringIO('<root> ${var} $var</root>')
ca46dc9c7761 `MarkupTemplate`s can now be instantiated from markup streams, in addition to strings and file-like objects. Thanks to David Fraser for the patch. Closes #69.
cmlenz
parents: 363
diff changeset
34 tmpl = MarkupTemplate(fileobj)
ca46dc9c7761 `MarkupTemplate`s can now be instantiated from markup streams, in addition to strings and file-like objects. Thanks to David Fraser for the patch. Closes #69.
cmlenz
parents: 363
diff changeset
35 self.assertEqual('<root> 42 42</root>', str(tmpl.generate(var=42)))
ca46dc9c7761 `MarkupTemplate`s can now be instantiated from markup streams, in addition to strings and file-like objects. Thanks to David Fraser for the patch. Closes #69.
cmlenz
parents: 363
diff changeset
36
ca46dc9c7761 `MarkupTemplate`s can now be instantiated from markup streams, in addition to strings and file-like objects. Thanks to David Fraser for the patch. Closes #69.
cmlenz
parents: 363
diff changeset
37 def test_parse_stream(self):
ca46dc9c7761 `MarkupTemplate`s can now be instantiated from markup streams, in addition to strings and file-like objects. Thanks to David Fraser for the patch. Closes #69.
cmlenz
parents: 363
diff changeset
38 stream = XML('<root> ${var} $var</root>')
ca46dc9c7761 `MarkupTemplate`s can now be instantiated from markup streams, in addition to strings and file-like objects. Thanks to David Fraser for the patch. Closes #69.
cmlenz
parents: 363
diff changeset
39 tmpl = MarkupTemplate(stream)
ca46dc9c7761 `MarkupTemplate`s can now be instantiated from markup streams, in addition to strings and file-like objects. Thanks to David Fraser for the patch. Closes #69.
cmlenz
parents: 363
diff changeset
40 self.assertEqual('<root> 42 42</root>', str(tmpl.generate(var=42)))
ca46dc9c7761 `MarkupTemplate`s can now be instantiated from markup streams, in addition to strings and file-like objects. Thanks to David Fraser for the patch. Closes #69.
cmlenz
parents: 363
diff changeset
41
336
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
42 def test_interpolate_mixed3(self):
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
43 tmpl = MarkupTemplate('<root> ${var} $var</root>')
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
44 self.assertEqual('<root> 42 42</root>', str(tmpl.generate(var=42)))
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
45
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
46 def test_interpolate_leading_trailing_space(self):
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
47 tmpl = MarkupTemplate('<root>${ foo }</root>')
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
48 self.assertEqual('<root>bar</root>', str(tmpl.generate(foo='bar')))
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
49
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
50 def test_interpolate_multiline(self):
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
51 tmpl = MarkupTemplate("""<root>${dict(
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
52 bar = 'baz'
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
53 )[foo]}</root>""")
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
54 self.assertEqual('<root>baz</root>', str(tmpl.generate(foo='bar')))
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
55
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
56 def test_interpolate_non_string_attrs(self):
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
57 tmpl = MarkupTemplate('<root attr="${1}"/>')
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
58 self.assertEqual('<root attr="1"/>', str(tmpl.generate()))
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
59
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
60 def test_interpolate_list_result(self):
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
61 tmpl = MarkupTemplate('<root>$foo</root>')
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
62 self.assertEqual('<root>buzz</root>', str(tmpl.generate(foo=('buzz',))))
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
63
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
64 def test_empty_attr(self):
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
65 tmpl = MarkupTemplate('<root attr=""/>')
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
66 self.assertEqual('<root attr=""/>', str(tmpl.generate()))
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
67
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
68 def test_bad_directive_error(self):
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
69 xml = '<p xmlns:py="http://genshi.edgewall.org/" py:do="nothing" />'
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
70 try:
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
71 tmpl = MarkupTemplate(xml, filename='test.html')
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
72 except BadDirectiveError, e:
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
73 self.assertEqual('test.html', e.filename)
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
74 if sys.version_info[:2] >= (2, 4):
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
75 self.assertEqual(1, e.lineno)
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 def test_directive_value_syntax_error(self):
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
78 xml = """<p xmlns:py="http://genshi.edgewall.org/" py:if="bar'" />"""
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
79 try:
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
80 tmpl = MarkupTemplate(xml, filename='test.html')
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
81 self.fail('Expected SyntaxError')
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
82 except TemplateSyntaxError, e:
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
83 self.assertEqual('test.html', e.filename)
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
84 if sys.version_info[:2] >= (2, 4):
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
85 self.assertEqual(1, e.lineno)
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
86
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
87 def test_expression_syntax_error(self):
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
88 xml = """<p>
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
89 Foo <em>${bar"}</em>
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
90 </p>"""
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
91 try:
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
92 tmpl = MarkupTemplate(xml, filename='test.html')
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
93 self.fail('Expected SyntaxError')
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
94 except TemplateSyntaxError, e:
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
95 self.assertEqual('test.html', e.filename)
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
96 if sys.version_info[:2] >= (2, 4):
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
97 self.assertEqual(2, e.lineno)
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
98
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
99 def test_expression_syntax_error_multi_line(self):
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
100 xml = """<p><em></em>
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
101
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
102 ${bar"}
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
103
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
104 </p>"""
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
105 try:
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
106 tmpl = MarkupTemplate(xml, filename='test.html')
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
107 self.fail('Expected SyntaxError')
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
108 except TemplateSyntaxError, e:
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
109 self.assertEqual('test.html', e.filename)
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
110 if sys.version_info[:2] >= (2, 4):
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
111 self.assertEqual(3, e.lineno)
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
112
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
113 def test_markup_noescape(self):
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
114 """
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
115 Verify that outputting context data that is a `Markup` instance is not
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
116 escaped.
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
117 """
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
118 tmpl = MarkupTemplate("""<div xmlns:py="http://genshi.edgewall.org/">
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
119 $myvar
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
120 </div>""")
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
121 self.assertEqual("""<div>
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
122 <b>foo</b>
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
123 </div>""", str(tmpl.generate(myvar=Markup('<b>foo</b>'))))
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
124
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
125 def test_text_noescape_quotes(self):
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
126 """
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
127 Verify that outputting context data in text nodes doesn't escape quotes.
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
128 """
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
129 tmpl = MarkupTemplate("""<div xmlns:py="http://genshi.edgewall.org/">
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
130 $myvar
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
131 </div>""")
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
132 self.assertEqual("""<div>
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
133 "foo"
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
134 </div>""", str(tmpl.generate(myvar='"foo"')))
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
135
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
136 def test_attr_escape_quotes(self):
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
137 """
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
138 Verify that outputting context data in attribtes escapes quotes.
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
139 """
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
140 tmpl = MarkupTemplate("""<div xmlns:py="http://genshi.edgewall.org/">
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
141 <elem class="$myvar"/>
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
142 </div>""")
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
143 self.assertEqual("""<div>
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
144 <elem class="&#34;foo&#34;"/>
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
145 </div>""", str(tmpl.generate(myvar='"foo"')))
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
146
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
147 def test_directive_element(self):
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
148 tmpl = MarkupTemplate("""<div xmlns:py="http://genshi.edgewall.org/">
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
149 <py:if test="myvar">bar</py:if>
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
150 </div>""")
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
151 self.assertEqual("""<div>
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
152 bar
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
153 </div>""", str(tmpl.generate(myvar='"foo"')))
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
154
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
155 def test_normal_comment(self):
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
156 tmpl = MarkupTemplate("""<div xmlns:py="http://genshi.edgewall.org/">
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
157 <!-- foo bar -->
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
158 </div>""")
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
159 self.assertEqual("""<div>
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
160 <!-- foo bar -->
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
161 </div>""", str(tmpl.generate()))
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
162
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
163 def test_template_comment(self):
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
164 tmpl = MarkupTemplate("""<div xmlns:py="http://genshi.edgewall.org/">
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
165 <!-- !foo -->
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
166 <!--!bar-->
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
167 </div>""")
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
168 self.assertEqual("""<div>
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
169 </div>""", str(tmpl.generate()))
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
170
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
171 def test_parse_with_same_namespace_nested(self):
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
172 tmpl = MarkupTemplate("""<div xmlns:py="http://genshi.edgewall.org/">
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
173 <span xmlns:py="http://genshi.edgewall.org/">
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
174 </span>
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
175 </div>""")
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
176 self.assertEqual("""<div>
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
177 <span>
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
178 </span>
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
179 </div>""", str(tmpl.generate()))
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
180
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
181 def test_latin1_encoded_with_xmldecl(self):
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
182 tmpl = MarkupTemplate(u"""<?xml version="1.0" 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
183 <div xmlns:py="http://genshi.edgewall.org/">
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
184 \xf6
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
185 </div>""".encode('iso-8859-1'), encoding='iso-8859-1')
460
6b5544bb5a99 Apply patch by Alec Thomas for processing XML declarations (#111). Thanks!
cmlenz
parents: 437
diff changeset
186 self.assertEqual(u"""<?xml version="1.0" encoding="iso-8859-1"?>\n<div>
336
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
187 \xf6
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
188 </div>""", unicode(tmpl.generate()))
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
189
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
190 def test_latin1_encoded_explicit_encoding(self):
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
191 tmpl = MarkupTemplate(u"""<div xmlns:py="http://genshi.edgewall.org/">
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
192 \xf6
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
193 </div>""".encode('iso-8859-1'), 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
194 self.assertEqual(u"""<div>
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
195 \xf6
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
196 </div>""", unicode(tmpl.generate()))
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
197
520
ced12be33858 Applied patch by Dale Sedivec to fix #127. Many thanks!
cmlenz
parents: 460
diff changeset
198 def test_exec_with_trailing_space(self):
ced12be33858 Applied patch by Dale Sedivec to fix #127. Many thanks!
cmlenz
parents: 460
diff changeset
199 """
ced12be33858 Applied patch by Dale Sedivec to fix #127. Many thanks!
cmlenz
parents: 460
diff changeset
200 Verify that a code block processing instruction with trailing space
ced12be33858 Applied patch by Dale Sedivec to fix #127. Many thanks!
cmlenz
parents: 460
diff changeset
201 does not cause a syntax error (see ticket #127).
ced12be33858 Applied patch by Dale Sedivec to fix #127. Many thanks!
cmlenz
parents: 460
diff changeset
202 """
ced12be33858 Applied patch by Dale Sedivec to fix #127. Many thanks!
cmlenz
parents: 460
diff changeset
203 MarkupTemplate(u"""<foo>
ced12be33858 Applied patch by Dale Sedivec to fix #127. Many thanks!
cmlenz
parents: 460
diff changeset
204 <?python
ced12be33858 Applied patch by Dale Sedivec to fix #127. Many thanks!
cmlenz
parents: 460
diff changeset
205 bar = 42
ced12be33858 Applied patch by Dale Sedivec to fix #127. Many thanks!
cmlenz
parents: 460
diff changeset
206 ?>
ced12be33858 Applied patch by Dale Sedivec to fix #127. Many thanks!
cmlenz
parents: 460
diff changeset
207 </foo>""")
ced12be33858 Applied patch by Dale Sedivec to fix #127. Many thanks!
cmlenz
parents: 460
diff changeset
208
405
bd5da099c113 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
209 def test_exec_import(self):
bd5da099c113 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
210 tmpl = MarkupTemplate(u"""<?python from datetime import timedelta ?>
bd5da099c113 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
211 <div xmlns:py="http://genshi.edgewall.org/">
bd5da099c113 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
212 ${timedelta(days=2)}
bd5da099c113 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
213 </div>""")
bd5da099c113 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
214 self.assertEqual(u"""<div>
bd5da099c113 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
215 2 days, 0:00:00
bd5da099c113 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
216 </div>""", str(tmpl.generate()))
bd5da099c113 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
217
bd5da099c113 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
218 def test_exec_def(self):
bd5da099c113 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
219 tmpl = MarkupTemplate(u"""
bd5da099c113 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
220 <?python
bd5da099c113 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
221 def foo():
bd5da099c113 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
222 return 42
bd5da099c113 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
223 ?>
bd5da099c113 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
224 <div xmlns:py="http://genshi.edgewall.org/">
bd5da099c113 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
225 ${foo()}
bd5da099c113 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
226 </div>""")
bd5da099c113 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
227 self.assertEqual(u"""<div>
bd5da099c113 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
228 42
bd5da099c113 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
229 </div>""", str(tmpl.generate()))
bd5da099c113 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
230
437
3d82c5bdbf46 Fix for #107.
cmlenz
parents: 408
diff changeset
231 def test_namespace_on_removed_elem(self):
3d82c5bdbf46 Fix for #107.
cmlenz
parents: 408
diff changeset
232 """
3d82c5bdbf46 Fix for #107.
cmlenz
parents: 408
diff changeset
233 Verify that a namespace declaration on an element that is removed from
3d82c5bdbf46 Fix for #107.
cmlenz
parents: 408
diff changeset
234 the generated stream does not get pushed up to the next non-stripped
3d82c5bdbf46 Fix for #107.
cmlenz
parents: 408
diff changeset
235 element (see ticket #107).
3d82c5bdbf46 Fix for #107.
cmlenz
parents: 408
diff changeset
236 """
3d82c5bdbf46 Fix for #107.
cmlenz
parents: 408
diff changeset
237 tmpl = MarkupTemplate("""<?xml version="1.0"?>
3d82c5bdbf46 Fix for #107.
cmlenz
parents: 408
diff changeset
238 <Test xmlns:py="http://genshi.edgewall.org/">
3d82c5bdbf46 Fix for #107.
cmlenz
parents: 408
diff changeset
239 <Size py:if="0" xmlns:t="test">Size</Size>
3d82c5bdbf46 Fix for #107.
cmlenz
parents: 408
diff changeset
240 <Item/>
3d82c5bdbf46 Fix for #107.
cmlenz
parents: 408
diff changeset
241 </Test>""")
460
6b5544bb5a99 Apply patch by Alec Thomas for processing XML declarations (#111). Thanks!
cmlenz
parents: 437
diff changeset
242 self.assertEqual("""<?xml version="1.0"?>\n<Test>
437
3d82c5bdbf46 Fix for #107.
cmlenz
parents: 408
diff changeset
243
3d82c5bdbf46 Fix for #107.
cmlenz
parents: 408
diff changeset
244 <Item/>
3d82c5bdbf46 Fix for #107.
cmlenz
parents: 408
diff changeset
245 </Test>""", str(tmpl.generate()))
3d82c5bdbf46 Fix for #107.
cmlenz
parents: 408
diff changeset
246
363
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
247 def test_include_in_loop(self):
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
248 dirname = tempfile.mkdtemp(suffix='genshi_test')
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
249 try:
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
250 file1 = open(os.path.join(dirname, 'tmpl1.html'), 'w')
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
251 try:
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
252 file1.write("""<div>Included $idx</div>""")
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
253 finally:
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
254 file1.close()
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
255
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
256 file2 = open(os.path.join(dirname, 'tmpl2.html'), 'w')
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
257 try:
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
258 file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude"
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
259 xmlns:py="http://genshi.edgewall.org/">
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
260 <xi:include href="${name}.html" py:for="idx in range(3)" />
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
261 </html>""")
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
262 finally:
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
263 file2.close()
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
264
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
265 loader = TemplateLoader([dirname])
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
266 tmpl = loader.load('tmpl2.html')
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
267 self.assertEqual("""<html>
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
268 <div>Included 0</div><div>Included 1</div><div>Included 2</div>
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
269 </html>""", tmpl.generate(name='tmpl1').render())
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
270 finally:
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
271 shutil.rmtree(dirname)
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
272
656
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
273 def test_dynamic_include_href(self):
363
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
274 dirname = tempfile.mkdtemp(suffix='genshi_test')
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
275 try:
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
276 file1 = open(os.path.join(dirname, 'tmpl1.html'), 'w')
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
277 try:
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
278 file1.write("""<div>Included</div>""")
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
279 finally:
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
280 file1.close()
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
281
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
282 file2 = open(os.path.join(dirname, 'tmpl2.html'), 'w')
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
283 try:
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
284 file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude"
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
285 xmlns:py="http://genshi.edgewall.org/">
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
286 <xi:include href="${name}.html" />
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
287 </html>""")
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
288 finally:
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
289 file2.close()
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
290
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
291 loader = TemplateLoader([dirname])
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
292 tmpl = loader.load('tmpl2.html')
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
293 self.assertEqual("""<html>
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
294 <div>Included</div>
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
295 </html>""", tmpl.generate(name='tmpl1').render())
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
296 finally:
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
297 shutil.rmtree(dirname)
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
298
656
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
299 def test_select_included_elements(self):
363
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
300 dirname = tempfile.mkdtemp(suffix='genshi_test')
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
301 try:
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
302 file1 = open(os.path.join(dirname, 'tmpl1.html'), 'w')
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
303 try:
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
304 file1.write("""<li>$item</li>""")
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
305 finally:
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
306 file1.close()
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
307
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
308 file2 = open(os.path.join(dirname, 'tmpl2.html'), 'w')
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
309 try:
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
310 file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude"
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
311 xmlns:py="http://genshi.edgewall.org/">
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
312 <ul py:match="ul">${select('li')}</ul>
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
313 <ul py:with="items=(1, 2, 3)">
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
314 <xi:include href="tmpl1.html" py:for="item in items" />
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
315 </ul>
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
316 </html>""")
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
317 finally:
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
318 file2.close()
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
319
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
320 loader = TemplateLoader([dirname])
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
321 tmpl = loader.load('tmpl2.html')
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
322 self.assertEqual("""<html>
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
323 <ul><li>1</li><li>2</li><li>3</li></ul>
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
324 </html>""", tmpl.generate().render())
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
325 finally:
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
326 shutil.rmtree(dirname)
caf7b68ab5dc Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
327
381
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
328 def test_fallback_when_include_found(self):
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
329 dirname = tempfile.mkdtemp(suffix='genshi_test')
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
330 try:
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
331 file1 = open(os.path.join(dirname, 'tmpl1.html'), 'w')
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
332 try:
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
333 file1.write("""<div>Included</div>""")
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
334 finally:
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
335 file1.close()
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
336
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
337 file2 = open(os.path.join(dirname, 'tmpl2.html'), 'w')
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
338 try:
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
339 file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude">
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
340 <xi:include href="tmpl1.html"><xi:fallback>
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
341 Missing</xi:fallback></xi:include>
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
342 </html>""")
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
343 finally:
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
344 file2.close()
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
345
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
346 loader = TemplateLoader([dirname])
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
347 tmpl = loader.load('tmpl2.html')
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
348 self.assertEqual("""<html>
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
349 <div>Included</div>
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
350 </html>""", tmpl.generate().render())
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
351 finally:
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
352 shutil.rmtree(dirname)
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
353
590
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
354 def test_error_when_include_not_found(self):
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
355 dirname = tempfile.mkdtemp(suffix='genshi_test')
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
356 try:
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
357 file2 = open(os.path.join(dirname, 'tmpl2.html'), 'w')
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
358 try:
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
359 file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude">
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
360 <xi:include href="tmpl1.html"/>
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
361 </html>""")
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
362 finally:
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
363 file2.close()
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
364
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
365 loader = TemplateLoader([dirname], auto_reload=True)
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
366 tmpl = loader.load('tmpl2.html')
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
367 self.assertRaises(TemplateNotFound, tmpl.generate().render)
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
368 finally:
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
369 shutil.rmtree(dirname)
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
370
381
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
371 def test_fallback_when_include_not_found(self):
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
372 dirname = tempfile.mkdtemp(suffix='genshi_test')
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
373 try:
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
374 file2 = open(os.path.join(dirname, 'tmpl2.html'), 'w')
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
375 try:
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
376 file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude">
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
377 <xi:include href="tmpl1.html"><xi:fallback>
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
378 Missing</xi:fallback></xi:include>
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
379 </html>""")
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
380 finally:
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
381 file2.close()
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
382
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
383 loader = TemplateLoader([dirname])
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
384 tmpl = loader.load('tmpl2.html')
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
385 self.assertEqual("""<html>
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
386 Missing
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
387 </html>""", tmpl.generate().render())
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
388 finally:
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
389 shutil.rmtree(dirname)
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
390
639
b0cdc457dde9 Fix for XInclude fallbacks when auto-reloading is enabled. Closes #147. Thanks to rintaro@cpan.org for reporting the issue and providing a patch and test case!
cmlenz
parents: 629
diff changeset
391 def test_fallback_when_auto_reload_true(self):
b0cdc457dde9 Fix for XInclude fallbacks when auto-reloading is enabled. Closes #147. Thanks to rintaro@cpan.org for reporting the issue and providing a patch and test case!
cmlenz
parents: 629
diff changeset
392 dirname = tempfile.mkdtemp(suffix='genshi_test')
b0cdc457dde9 Fix for XInclude fallbacks when auto-reloading is enabled. Closes #147. Thanks to rintaro@cpan.org for reporting the issue and providing a patch and test case!
cmlenz
parents: 629
diff changeset
393 try:
b0cdc457dde9 Fix for XInclude fallbacks when auto-reloading is enabled. Closes #147. Thanks to rintaro@cpan.org for reporting the issue and providing a patch and test case!
cmlenz
parents: 629
diff changeset
394 file2 = open(os.path.join(dirname, 'tmpl2.html'), 'w')
b0cdc457dde9 Fix for XInclude fallbacks when auto-reloading is enabled. Closes #147. Thanks to rintaro@cpan.org for reporting the issue and providing a patch and test case!
cmlenz
parents: 629
diff changeset
395 try:
b0cdc457dde9 Fix for XInclude fallbacks when auto-reloading is enabled. Closes #147. Thanks to rintaro@cpan.org for reporting the issue and providing a patch and test case!
cmlenz
parents: 629
diff changeset
396 file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude">
b0cdc457dde9 Fix for XInclude fallbacks when auto-reloading is enabled. Closes #147. Thanks to rintaro@cpan.org for reporting the issue and providing a patch and test case!
cmlenz
parents: 629
diff changeset
397 <xi:include href="tmpl1.html"><xi:fallback>
b0cdc457dde9 Fix for XInclude fallbacks when auto-reloading is enabled. Closes #147. Thanks to rintaro@cpan.org for reporting the issue and providing a patch and test case!
cmlenz
parents: 629
diff changeset
398 Missing</xi:fallback></xi:include>
b0cdc457dde9 Fix for XInclude fallbacks when auto-reloading is enabled. Closes #147. Thanks to rintaro@cpan.org for reporting the issue and providing a patch and test case!
cmlenz
parents: 629
diff changeset
399 </html>""")
b0cdc457dde9 Fix for XInclude fallbacks when auto-reloading is enabled. Closes #147. Thanks to rintaro@cpan.org for reporting the issue and providing a patch and test case!
cmlenz
parents: 629
diff changeset
400 finally:
b0cdc457dde9 Fix for XInclude fallbacks when auto-reloading is enabled. Closes #147. Thanks to rintaro@cpan.org for reporting the issue and providing a patch and test case!
cmlenz
parents: 629
diff changeset
401 file2.close()
b0cdc457dde9 Fix for XInclude fallbacks when auto-reloading is enabled. Closes #147. Thanks to rintaro@cpan.org for reporting the issue and providing a patch and test case!
cmlenz
parents: 629
diff changeset
402
b0cdc457dde9 Fix for XInclude fallbacks when auto-reloading is enabled. Closes #147. Thanks to rintaro@cpan.org for reporting the issue and providing a patch and test case!
cmlenz
parents: 629
diff changeset
403 loader = TemplateLoader([dirname], auto_reload=True)
b0cdc457dde9 Fix for XInclude fallbacks when auto-reloading is enabled. Closes #147. Thanks to rintaro@cpan.org for reporting the issue and providing a patch and test case!
cmlenz
parents: 629
diff changeset
404 tmpl = loader.load('tmpl2.html')
b0cdc457dde9 Fix for XInclude fallbacks when auto-reloading is enabled. Closes #147. Thanks to rintaro@cpan.org for reporting the issue and providing a patch and test case!
cmlenz
parents: 629
diff changeset
405 self.assertEqual("""<html>
b0cdc457dde9 Fix for XInclude fallbacks when auto-reloading is enabled. Closes #147. Thanks to rintaro@cpan.org for reporting the issue and providing a patch and test case!
cmlenz
parents: 629
diff changeset
406 Missing
b0cdc457dde9 Fix for XInclude fallbacks when auto-reloading is enabled. Closes #147. Thanks to rintaro@cpan.org for reporting the issue and providing a patch and test case!
cmlenz
parents: 629
diff changeset
407 </html>""", tmpl.generate().render())
b0cdc457dde9 Fix for XInclude fallbacks when auto-reloading is enabled. Closes #147. Thanks to rintaro@cpan.org for reporting the issue and providing a patch and test case!
cmlenz
parents: 629
diff changeset
408 finally:
b0cdc457dde9 Fix for XInclude fallbacks when auto-reloading is enabled. Closes #147. Thanks to rintaro@cpan.org for reporting the issue and providing a patch and test case!
cmlenz
parents: 629
diff changeset
409 shutil.rmtree(dirname)
b0cdc457dde9 Fix for XInclude fallbacks when auto-reloading is enabled. Closes #147. Thanks to rintaro@cpan.org for reporting the issue and providing a patch and test case!
cmlenz
parents: 629
diff changeset
410
381
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
411 def test_include_in_fallback(self):
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
412 dirname = tempfile.mkdtemp(suffix='genshi_test')
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
413 try:
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
414 file1 = open(os.path.join(dirname, 'tmpl1.html'), 'w')
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
415 try:
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
416 file1.write("""<div>Included</div>""")
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
417 finally:
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
418 file1.close()
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
419
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
420 file2 = open(os.path.join(dirname, 'tmpl3.html'), 'w')
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
421 try:
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
422 file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude">
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
423 <xi:include href="tmpl2.html">
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
424 <xi:fallback>
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
425 <xi:include href="tmpl1.html">
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
426 <xi:fallback>Missing</xi:fallback>
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
427 </xi:include>
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
428 </xi:fallback>
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
429 </xi:include>
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
430 </html>""")
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
431 finally:
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
432 file2.close()
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
433
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
434 loader = TemplateLoader([dirname])
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
435 tmpl = loader.load('tmpl3.html')
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
436 self.assertEqual("""<html>
590
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
437 <div>Included</div>
381
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
438 </html>""", tmpl.generate().render())
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
439 finally:
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
440 shutil.rmtree(dirname)
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
441
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
442 def test_nested_include_fallback(self):
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
443 dirname = tempfile.mkdtemp(suffix='genshi_test')
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
444 try:
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
445 file2 = open(os.path.join(dirname, 'tmpl3.html'), 'w')
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
446 try:
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
447 file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude">
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
448 <xi:include href="tmpl2.html">
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
449 <xi:fallback>
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
450 <xi:include href="tmpl1.html">
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
451 <xi:fallback>Missing</xi:fallback>
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
452 </xi:include>
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
453 </xi:fallback>
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
454 </xi:include>
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
455 </html>""")
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
456 finally:
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
457 file2.close()
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
458
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
459 loader = TemplateLoader([dirname])
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
460 tmpl = loader.load('tmpl3.html')
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
461 self.assertEqual("""<html>
590
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
462 Missing
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
463 </html>""", tmpl.generate().render())
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
464 finally:
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
465 shutil.rmtree(dirname)
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
466
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
467 def test_nested_include_in_fallback(self):
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
468 dirname = tempfile.mkdtemp(suffix='genshi_test')
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
469 try:
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
470 file1 = open(os.path.join(dirname, 'tmpl2.html'), 'w')
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
471 try:
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
472 file1.write("""<div>Included</div>""")
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
473 finally:
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
474 file1.close()
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
475
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
476 file2 = open(os.path.join(dirname, 'tmpl3.html'), 'w')
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
477 try:
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
478 file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude">
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
479 <xi:include href="tmpl2.html">
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
480 <xi:fallback>
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
481 <xi:include href="tmpl1.html" />
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
482 </xi:fallback>
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
483 </xi:include>
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
484 </html>""")
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
485 finally:
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
486 file2.close()
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
487
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
488 loader = TemplateLoader([dirname])
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
489 tmpl = loader.load('tmpl3.html')
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
490 self.assertEqual("""<html>
880b1a75d046 Fix includes so that they again raise an exception when the included template is not found and no fallback has been provided.
cmlenz
parents: 548
diff changeset
491 <div>Included</div>
381
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
492 </html>""", tmpl.generate().render())
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
493 finally:
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
494 shutil.rmtree(dirname)
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
495
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
496 def test_include_fallback_with_directive(self):
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
497 dirname = tempfile.mkdtemp(suffix='genshi_test')
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
498 try:
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
499 file2 = open(os.path.join(dirname, 'tmpl2.html'), 'w')
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
500 try:
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
501 file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude"
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
502 xmlns:py="http://genshi.edgewall.org/">
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
503 <xi:include href="tmpl1.html"><xi:fallback>
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
504 <py:if test="True">tmpl1.html not found</py:if>
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
505 </xi:fallback></xi:include>
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
506 </html>""")
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
507 finally:
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
508 file2.close()
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
509
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
510 loader = TemplateLoader([dirname])
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
511 tmpl = loader.load('tmpl2.html')
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
512 self.assertEqual("""<html>
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
513 tmpl1.html not found
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
514 </html>""", tmpl.generate(debug=True).render())
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
515 finally:
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
516 shutil.rmtree(dirname)
a6c2a9cd2e92 Fix for #80: fallback only shown when the template to include wasn't found. In addition, the nesting of includes and fallback content should work correctly, and directives/expressions/etc inside fallback content are processed. Thanks to Christian Boos for the original patch and unit tests.
cmlenz
parents: 374
diff changeset
517
548
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
518 def test_include_inlined(self):
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
519 dirname = tempfile.mkdtemp(suffix='genshi_test')
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
520 try:
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
521 file1 = open(os.path.join(dirname, 'tmpl1.html'), 'w')
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
522 try:
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
523 file1.write("""<div>Included</div>""")
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
524 finally:
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
525 file1.close()
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
526
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
527 file2 = open(os.path.join(dirname, 'tmpl2.html'), 'w')
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
528 try:
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
529 file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude"
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
530 xmlns:py="http://genshi.edgewall.org/">
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
531 <xi:include href="tmpl1.html" />
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
532 </html>""")
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
533 finally:
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
534 file2.close()
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
535
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
536 loader = TemplateLoader([dirname], auto_reload=False)
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
537 tmpl = loader.load('tmpl2.html')
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
538 # if not inlined the following would be 5
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
539 self.assertEqual(7, len(tmpl.stream))
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
540 self.assertEqual("""<html>
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
541 <div>Included</div>
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
542 </html>""", tmpl.generate().render())
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
543 finally:
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
544 shutil.rmtree(dirname)
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
545
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
546 def test_include_inlined_in_loop(self):
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
547 dirname = tempfile.mkdtemp(suffix='genshi_test')
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
548 try:
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
549 file1 = open(os.path.join(dirname, 'tmpl1.html'), 'w')
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
550 try:
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
551 file1.write("""<div>Included $idx</div>""")
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
552 finally:
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
553 file1.close()
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
554
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
555 file2 = open(os.path.join(dirname, 'tmpl2.html'), 'w')
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
556 try:
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
557 file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude"
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
558 xmlns:py="http://genshi.edgewall.org/">
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
559 <xi:include href="tmpl1.html" py:for="idx in range(3)" />
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
560 </html>""")
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
561 finally:
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
562 file2.close()
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
563
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
564 loader = TemplateLoader([dirname], auto_reload=False)
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
565 tmpl = loader.load('tmpl2.html')
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
566 self.assertEqual("""<html>
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
567 <div>Included 0</div><div>Included 1</div><div>Included 2</div>
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
568 </html>""", tmpl.generate().render())
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
569 finally:
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
570 shutil.rmtree(dirname)
c2e039c7e439 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
571
545
6e21c89d9255 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
572 def test_allow_exec_false(self):
6e21c89d9255 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
573 xml = ("""<?python
6e21c89d9255 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
574 title = "A Genshi Template"
6e21c89d9255 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
575 ?>
6e21c89d9255 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
576 <html xmlns:py="http://genshi.edgewall.org/">
6e21c89d9255 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
577 <head>
6e21c89d9255 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
578 <title py:content="title">This is replaced.</title>
6e21c89d9255 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
579 </head>
6e21c89d9255 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
580 </html>""")
6e21c89d9255 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
581 try:
6e21c89d9255 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
582 tmpl = MarkupTemplate(xml, filename='test.html',
6e21c89d9255 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
583 allow_exec=False)
6e21c89d9255 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
584 self.fail('Expected SyntaxError')
6e21c89d9255 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
585 except TemplateSyntaxError, e:
6e21c89d9255 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
586 pass
6e21c89d9255 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
587
6e21c89d9255 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
588 def test_allow_exec_true(self):
6e21c89d9255 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
589 xml = ("""<?python
6e21c89d9255 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
590 title = "A Genshi Template"
6e21c89d9255 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
591 ?>
6e21c89d9255 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
592 <html xmlns:py="http://genshi.edgewall.org/">
6e21c89d9255 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
593 <head>
6e21c89d9255 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
594 <title py:content="title">This is replaced.</title>
6e21c89d9255 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
595 </head>
6e21c89d9255 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
596 </html>""")
6e21c89d9255 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
597 tmpl = MarkupTemplate(xml, filename='test.html', allow_exec=True)
336
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
598
650
0413c8817a3c Code blocks in match templates are now executed. Closes #155. Many thanks to Andrew Sutherland for the patch!
cmlenz
parents: 639
diff changeset
599 def test_exec_in_match(self):
0413c8817a3c Code blocks in match templates are now executed. Closes #155. Many thanks to Andrew Sutherland for the patch!
cmlenz
parents: 639
diff changeset
600 xml = ("""<html xmlns:py="http://genshi.edgewall.org/">
0413c8817a3c Code blocks in match templates are now executed. Closes #155. Many thanks to Andrew Sutherland for the patch!
cmlenz
parents: 639
diff changeset
601 <py:match path="body/p">
0413c8817a3c Code blocks in match templates are now executed. Closes #155. Many thanks to Andrew Sutherland for the patch!
cmlenz
parents: 639
diff changeset
602 <?python title="wakka wakka wakka" ?>
0413c8817a3c Code blocks in match templates are now executed. Closes #155. Many thanks to Andrew Sutherland for the patch!
cmlenz
parents: 639
diff changeset
603 ${title}
0413c8817a3c Code blocks in match templates are now executed. Closes #155. Many thanks to Andrew Sutherland for the patch!
cmlenz
parents: 639
diff changeset
604 </py:match>
0413c8817a3c Code blocks in match templates are now executed. Closes #155. Many thanks to Andrew Sutherland for the patch!
cmlenz
parents: 639
diff changeset
605 <body><p>moot text</p></body>
0413c8817a3c Code blocks in match templates are now executed. Closes #155. Many thanks to Andrew Sutherland for the patch!
cmlenz
parents: 639
diff changeset
606 </html>""")
0413c8817a3c Code blocks in match templates are now executed. Closes #155. Many thanks to Andrew Sutherland for the patch!
cmlenz
parents: 639
diff changeset
607 tmpl = MarkupTemplate(xml, filename='test.html', allow_exec=True)
0413c8817a3c Code blocks in match templates are now executed. Closes #155. Many thanks to Andrew Sutherland for the patch!
cmlenz
parents: 639
diff changeset
608 self.assertEqual("""<html>
0413c8817a3c Code blocks in match templates are now executed. Closes #155. Many thanks to Andrew Sutherland for the patch!
cmlenz
parents: 639
diff changeset
609 <body>
0413c8817a3c Code blocks in match templates are now executed. Closes #155. Many thanks to Andrew Sutherland for the patch!
cmlenz
parents: 639
diff changeset
610 wakka wakka wakka
0413c8817a3c Code blocks in match templates are now executed. Closes #155. Many thanks to Andrew Sutherland for the patch!
cmlenz
parents: 639
diff changeset
611 </body>
0413c8817a3c Code blocks in match templates are now executed. Closes #155. Many thanks to Andrew Sutherland for the patch!
cmlenz
parents: 639
diff changeset
612 </html>""", tmpl.generate().render())
0413c8817a3c Code blocks in match templates are now executed. Closes #155. Many thanks to Andrew Sutherland for the patch!
cmlenz
parents: 639
diff changeset
613
656
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
614 def test_nested_include_matches(self):
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
615 # See ticket #157
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
616 dirname = tempfile.mkdtemp(suffix='genshi_test')
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
617 try:
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
618 file1 = open(os.path.join(dirname, 'tmpl1.html'), 'w')
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
619 try:
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
620 file1.write("""<html xmlns:py="http://genshi.edgewall.org/" py:strip="">
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
621 <div class="target">Some content.</div>
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
622 </html>""")
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
623 finally:
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
624 file1.close()
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
625
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
626 file2 = open(os.path.join(dirname, 'tmpl2.html'), 'w')
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
627 try:
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
628 file2.write("""<html xmlns:py="http://genshi.edgewall.org/"
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
629 xmlns:xi="http://www.w3.org/2001/XInclude">
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
630 <body>
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
631 <h1>Some full html document that includes file1.html</h1>
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
632 <xi:include href="tmpl1.html" />
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
633 </body>
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
634 </html>""")
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
635 finally:
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
636 file2.close()
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
637
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
638 file3 = open(os.path.join(dirname, 'tmpl3.html'), 'w')
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
639 try:
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
640 file3.write("""<html xmlns:py="http://genshi.edgewall.org/"
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
641 xmlns:xi="http://www.w3.org/2001/XInclude" py:strip="">
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
642 <div py:match="div[@class='target']" py:attrs="select('@*')">
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
643 Some added stuff.
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
644 ${select('*|text()')}
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
645 </div>
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
646 <xi:include href="tmpl2.html" />
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
647 </html>
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
648 """)
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
649 finally:
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
650 file3.close()
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
651
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
652 loader = TemplateLoader([dirname])
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
653 tmpl = loader.load('tmpl3.html')
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
654 self.assertEqual("""
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
655 <html>
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
656 <body>
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
657 <h1>Some full html document that includes file1.html</h1>
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
658 <div class="target">
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
659 Some added stuff.
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
660 Some content.
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
661 </div>
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
662 </body>
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
663 </html>
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
664 """, tmpl.generate().render())
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
665 finally:
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
666 shutil.rmtree(dirname)
3a3562e40a7e Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
667
546
f58b52a9fa6e White space.
cmlenz
parents: 545
diff changeset
668
336
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
669 def suite():
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
670 suite = unittest.TestSuite()
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
671 suite.addTest(doctest.DocTestSuite(MarkupTemplate.__module__))
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
672 suite.addTest(unittest.makeSuite(MarkupTemplateTestCase, 'test'))
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
673 return suite
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
674
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
675 if __name__ == '__main__':
5f2c7782cd8a Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
676 unittest.main(defaultTest='suite')
Copyright (C) 2012-2017 Edgewall Software