annotate genshi/template/tests/markup.py @ 790:da90cee22560 trunk

Merged the custom-directives branch back into trunk.
author cmlenz
date Wed, 10 Sep 2008 20:53:09 +0000
parents 2c2e9e685424
children 728f25c1d1a3
rev   line source
336
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
1 # -*- coding: utf-8 -*-
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
2 #
714
fc6d9d2a3527 The `Template` class and its subclasses, as well as the interpolation API, now take an `filepath` parameter instead of `basedir`. Closes #207. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents: 700
diff changeset
3 # Copyright (C) 2006-2008 Edgewall Software
336
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
4 # All rights reserved.
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
5 #
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
6 # This software is licensed as described in the file COPYING, which
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
7 # you should have received as part of this distribution. The terms
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
8 # are also available at http://genshi.edgewall.org/wiki/License.
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
9 #
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
10 # This software consists of voluntary contributions made by many
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
11 # individuals. For the exact contribution history, see the revision
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
12 # history and logs, available at http://genshi.edgewall.org/log/.
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
13
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
14 import doctest
363
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
15 import os
715
b5bd8c109209 Enable pickling of `Template` and `Code` objects.
cmlenz
parents: 714
diff changeset
16 import pickle
363
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
17 import shutil
374
b146277eb54a `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
18 from StringIO import StringIO
336
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
19 import sys
363
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
20 import tempfile
336
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
21 import unittest
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
22
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
23 from genshi.core import Markup
374
b146277eb54a `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
24 from genshi.input import XML
400
e29a94b3ba0c Renamed `genshi.template.core` to `genshi.template.base`, mainly to avoid confusion with `genshi.core`.
cmlenz
parents: 381
diff changeset
25 from genshi.template.base import BadDirectiveError, TemplateSyntaxError
590
36b5a03534a0 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
26 from genshi.template.loader import TemplateLoader, TemplateNotFound
336
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
27 from genshi.template.markup import MarkupTemplate
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
28
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
29
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
30 class MarkupTemplateTestCase(unittest.TestCase):
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
31 """Tests for markup template processing."""
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
32
374
b146277eb54a `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 def test_parse_fileobj(self):
b146277eb54a `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 fileobj = StringIO('<root> ${var} $var</root>')
b146277eb54a `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 tmpl = MarkupTemplate(fileobj)
b146277eb54a `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 self.assertEqual('<root> 42 42</root>', str(tmpl.generate(var=42)))
b146277eb54a `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
b146277eb54a `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 def test_parse_stream(self):
b146277eb54a `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 stream = XML('<root> ${var} $var</root>')
b146277eb54a `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 tmpl = MarkupTemplate(stream)
b146277eb54a `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 self.assertEqual('<root> 42 42</root>', str(tmpl.generate(var=42)))
b146277eb54a `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
42
715
b5bd8c109209 Enable pickling of `Template` and `Code` objects.
cmlenz
parents: 714
diff changeset
43 def test_pickle(self):
b5bd8c109209 Enable pickling of `Template` and `Code` objects.
cmlenz
parents: 714
diff changeset
44 stream = XML('<root>$var</root>')
b5bd8c109209 Enable pickling of `Template` and `Code` objects.
cmlenz
parents: 714
diff changeset
45 tmpl = MarkupTemplate(stream)
b5bd8c109209 Enable pickling of `Template` and `Code` objects.
cmlenz
parents: 714
diff changeset
46 buf = StringIO()
b5bd8c109209 Enable pickling of `Template` and `Code` objects.
cmlenz
parents: 714
diff changeset
47 pickle.dump(tmpl, buf, 2)
b5bd8c109209 Enable pickling of `Template` and `Code` objects.
cmlenz
parents: 714
diff changeset
48 buf.seek(0)
b5bd8c109209 Enable pickling of `Template` and `Code` objects.
cmlenz
parents: 714
diff changeset
49 unpickled = pickle.load(buf)
b5bd8c109209 Enable pickling of `Template` and `Code` objects.
cmlenz
parents: 714
diff changeset
50 self.assertEqual('<root>42</root>', str(unpickled.generate(var=42)))
b5bd8c109209 Enable pickling of `Template` and `Code` objects.
cmlenz
parents: 714
diff changeset
51
336
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
52 def test_interpolate_mixed3(self):
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
53 tmpl = MarkupTemplate('<root> ${var} $var</root>')
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
54 self.assertEqual('<root> 42 42</root>', str(tmpl.generate(var=42)))
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
55
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
56 def test_interpolate_leading_trailing_space(self):
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
57 tmpl = MarkupTemplate('<root>${ foo }</root>')
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
58 self.assertEqual('<root>bar</root>', str(tmpl.generate(foo='bar')))
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
59
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
60 def test_interpolate_multiline(self):
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
61 tmpl = MarkupTemplate("""<root>${dict(
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
62 bar = 'baz'
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
63 )[foo]}</root>""")
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
64 self.assertEqual('<root>baz</root>', str(tmpl.generate(foo='bar')))
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
65
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
66 def test_interpolate_non_string_attrs(self):
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
67 tmpl = MarkupTemplate('<root attr="${1}"/>')
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
68 self.assertEqual('<root attr="1"/>', str(tmpl.generate()))
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
69
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
70 def test_interpolate_list_result(self):
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
71 tmpl = MarkupTemplate('<root>$foo</root>')
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
72 self.assertEqual('<root>buzz</root>', str(tmpl.generate(foo=('buzz',))))
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
73
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
74 def test_empty_attr(self):
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
75 tmpl = MarkupTemplate('<root attr=""/>')
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
76 self.assertEqual('<root attr=""/>', str(tmpl.generate()))
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
77
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
78 def test_bad_directive_error(self):
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
79 xml = '<p xmlns:py="http://genshi.edgewall.org/" py:do="nothing" />'
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
80 try:
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
81 tmpl = MarkupTemplate(xml, filename='test.html')
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
82 except BadDirectiveError, e:
7763f7aec949 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)
750
52219748e5c1 Remove some cruft for supporting Python 2.3.
cmlenz
parents: 715
diff changeset
84 self.assertEqual(1, e.lineno)
336
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
85
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
86 def test_directive_value_syntax_error(self):
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
87 xml = """<p xmlns:py="http://genshi.edgewall.org/" py:if="bar'" />"""
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
88 try:
790
da90cee22560 Merged the custom-directives branch back into trunk.
cmlenz
parents: 771
diff changeset
89 tmpl = MarkupTemplate(xml, filename='test.html').generate()
da90cee22560 Merged the custom-directives branch back into trunk.
cmlenz
parents: 771
diff changeset
90 self.fail('Expected TemplateSyntaxError')
336
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
91 except TemplateSyntaxError, e:
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
92 self.assertEqual('test.html', e.filename)
750
52219748e5c1 Remove some cruft for supporting Python 2.3.
cmlenz
parents: 715
diff changeset
93 self.assertEqual(1, e.lineno)
336
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
94
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
95 def test_expression_syntax_error(self):
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
96 xml = """<p>
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
97 Foo <em>${bar"}</em>
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
98 </p>"""
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
99 try:
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
100 tmpl = MarkupTemplate(xml, filename='test.html')
790
da90cee22560 Merged the custom-directives branch back into trunk.
cmlenz
parents: 771
diff changeset
101 self.fail('Expected TemplateSyntaxError')
336
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
102 except TemplateSyntaxError, e:
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
103 self.assertEqual('test.html', e.filename)
750
52219748e5c1 Remove some cruft for supporting Python 2.3.
cmlenz
parents: 715
diff changeset
104 self.assertEqual(2, e.lineno)
336
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
105
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
106 def test_expression_syntax_error_multi_line(self):
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
107 xml = """<p><em></em>
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
108
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
109 ${bar"}
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
110
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
111 </p>"""
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
112 try:
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
113 tmpl = MarkupTemplate(xml, filename='test.html')
790
da90cee22560 Merged the custom-directives branch back into trunk.
cmlenz
parents: 771
diff changeset
114 self.fail('Expected TemplateSyntaxError')
336
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
115 except TemplateSyntaxError, e:
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
116 self.assertEqual('test.html', e.filename)
750
52219748e5c1 Remove some cruft for supporting Python 2.3.
cmlenz
parents: 715
diff changeset
117 self.assertEqual(3, e.lineno)
336
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
118
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
119 def test_markup_noescape(self):
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
120 """
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
121 Verify that outputting context data that is a `Markup` instance is not
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
122 escaped.
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
123 """
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
124 tmpl = MarkupTemplate("""<div xmlns:py="http://genshi.edgewall.org/">
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
125 $myvar
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
126 </div>""")
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
127 self.assertEqual("""<div>
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
128 <b>foo</b>
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
129 </div>""", str(tmpl.generate(myvar=Markup('<b>foo</b>'))))
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
130
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
131 def test_text_noescape_quotes(self):
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
132 """
790
da90cee22560 Merged the custom-directives branch back into trunk.
cmlenz
parents: 771
diff changeset
133 Verify that outputting context data in text nodes doesn't escape
da90cee22560 Merged the custom-directives branch back into trunk.
cmlenz
parents: 771
diff changeset
134 quotes.
336
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
135 """
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
136 tmpl = MarkupTemplate("""<div xmlns:py="http://genshi.edgewall.org/">
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
137 $myvar
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
138 </div>""")
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
139 self.assertEqual("""<div>
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
140 "foo"
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
141 </div>""", str(tmpl.generate(myvar='"foo"')))
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
142
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
143 def test_attr_escape_quotes(self):
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
144 """
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
145 Verify that outputting context data in attribtes escapes quotes.
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
146 """
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
147 tmpl = MarkupTemplate("""<div xmlns:py="http://genshi.edgewall.org/">
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
148 <elem class="$myvar"/>
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
149 </div>""")
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
150 self.assertEqual("""<div>
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
151 <elem class="&#34;foo&#34;"/>
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
152 </div>""", str(tmpl.generate(myvar='"foo"')))
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
153
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
154 def test_directive_element(self):
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
155 tmpl = MarkupTemplate("""<div xmlns:py="http://genshi.edgewall.org/">
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
156 <py:if test="myvar">bar</py:if>
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
157 </div>""")
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
158 self.assertEqual("""<div>
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
159 bar
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
160 </div>""", str(tmpl.generate(myvar='"foo"')))
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
161
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
162 def test_normal_comment(self):
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
163 tmpl = MarkupTemplate("""<div xmlns:py="http://genshi.edgewall.org/">
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
164 <!-- foo bar -->
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
165 </div>""")
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
166 self.assertEqual("""<div>
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
167 <!-- foo bar -->
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
168 </div>""", str(tmpl.generate()))
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
169
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
170 def test_template_comment(self):
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
171 tmpl = MarkupTemplate("""<div xmlns:py="http://genshi.edgewall.org/">
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
172 <!-- !foo -->
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
173 <!--!bar-->
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
174 </div>""")
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
175 self.assertEqual("""<div>
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
176 </div>""", str(tmpl.generate()))
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
177
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
178 def test_parse_with_same_namespace_nested(self):
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
179 tmpl = MarkupTemplate("""<div xmlns:py="http://genshi.edgewall.org/">
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
180 <span xmlns:py="http://genshi.edgewall.org/">
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
181 </span>
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
182 </div>""")
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
183 self.assertEqual("""<div>
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
184 <span>
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
185 </span>
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
186 </div>""", str(tmpl.generate()))
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
187
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
188 def test_latin1_encoded_with_xmldecl(self):
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
189 tmpl = MarkupTemplate(u"""<?xml version="1.0" encoding="iso-8859-1" ?>
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
190 <div xmlns:py="http://genshi.edgewall.org/">
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
191 \xf6
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
192 </div>""".encode('iso-8859-1'), encoding='iso-8859-1')
460
75425671b437 Apply patch by Alec Thomas for processing XML declarations (#111). Thanks!
cmlenz
parents: 437
diff changeset
193 self.assertEqual(u"""<?xml version="1.0" encoding="iso-8859-1"?>\n<div>
336
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
194 \xf6
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
195 </div>""", unicode(tmpl.generate()))
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
196
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
197 def test_latin1_encoded_explicit_encoding(self):
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
198 tmpl = MarkupTemplate(u"""<div xmlns:py="http://genshi.edgewall.org/">
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
199 \xf6
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
200 </div>""".encode('iso-8859-1'), encoding='iso-8859-1')
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
201 self.assertEqual(u"""<div>
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
202 \xf6
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
203 </div>""", unicode(tmpl.generate()))
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
204
520
203bd6a3c93d Applied patch by Dale Sedivec to fix #127. Many thanks!
cmlenz
parents: 460
diff changeset
205 def test_exec_with_trailing_space(self):
203bd6a3c93d Applied patch by Dale Sedivec to fix #127. Many thanks!
cmlenz
parents: 460
diff changeset
206 """
203bd6a3c93d Applied patch by Dale Sedivec to fix #127. Many thanks!
cmlenz
parents: 460
diff changeset
207 Verify that a code block processing instruction with trailing space
203bd6a3c93d Applied patch by Dale Sedivec to fix #127. Many thanks!
cmlenz
parents: 460
diff changeset
208 does not cause a syntax error (see ticket #127).
203bd6a3c93d Applied patch by Dale Sedivec to fix #127. Many thanks!
cmlenz
parents: 460
diff changeset
209 """
203bd6a3c93d Applied patch by Dale Sedivec to fix #127. Many thanks!
cmlenz
parents: 460
diff changeset
210 MarkupTemplate(u"""<foo>
203bd6a3c93d Applied patch by Dale Sedivec to fix #127. Many thanks!
cmlenz
parents: 460
diff changeset
211 <?python
203bd6a3c93d Applied patch by Dale Sedivec to fix #127. Many thanks!
cmlenz
parents: 460
diff changeset
212 bar = 42
203bd6a3c93d Applied patch by Dale Sedivec to fix #127. Many thanks!
cmlenz
parents: 460
diff changeset
213 ?>
203bd6a3c93d Applied patch by Dale Sedivec to fix #127. Many thanks!
cmlenz
parents: 460
diff changeset
214 </foo>""")
203bd6a3c93d Applied patch by Dale Sedivec to fix #127. Many thanks!
cmlenz
parents: 460
diff changeset
215
405
5340931530e2 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
216 def test_exec_import(self):
5340931530e2 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
217 tmpl = MarkupTemplate(u"""<?python from datetime import timedelta ?>
5340931530e2 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
218 <div xmlns:py="http://genshi.edgewall.org/">
5340931530e2 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
219 ${timedelta(days=2)}
5340931530e2 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
220 </div>""")
5340931530e2 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
221 self.assertEqual(u"""<div>
5340931530e2 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
222 2 days, 0:00:00
5340931530e2 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
223 </div>""", str(tmpl.generate()))
5340931530e2 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
224
5340931530e2 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
225 def test_exec_def(self):
5340931530e2 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
226 tmpl = MarkupTemplate(u"""
5340931530e2 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
227 <?python
5340931530e2 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
228 def foo():
5340931530e2 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
229 return 42
5340931530e2 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
230 ?>
5340931530e2 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
231 <div xmlns:py="http://genshi.edgewall.org/">
5340931530e2 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
232 ${foo()}
5340931530e2 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
233 </div>""")
5340931530e2 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
234 self.assertEqual(u"""<div>
5340931530e2 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
235 42
5340931530e2 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
236 </div>""", str(tmpl.generate()))
5340931530e2 Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents: 400
diff changeset
237
437
821fc97d3c0a Fix for #107.
cmlenz
parents: 408
diff changeset
238 def test_namespace_on_removed_elem(self):
821fc97d3c0a Fix for #107.
cmlenz
parents: 408
diff changeset
239 """
821fc97d3c0a Fix for #107.
cmlenz
parents: 408
diff changeset
240 Verify that a namespace declaration on an element that is removed from
821fc97d3c0a Fix for #107.
cmlenz
parents: 408
diff changeset
241 the generated stream does not get pushed up to the next non-stripped
821fc97d3c0a Fix for #107.
cmlenz
parents: 408
diff changeset
242 element (see ticket #107).
821fc97d3c0a Fix for #107.
cmlenz
parents: 408
diff changeset
243 """
821fc97d3c0a Fix for #107.
cmlenz
parents: 408
diff changeset
244 tmpl = MarkupTemplate("""<?xml version="1.0"?>
821fc97d3c0a Fix for #107.
cmlenz
parents: 408
diff changeset
245 <Test xmlns:py="http://genshi.edgewall.org/">
821fc97d3c0a Fix for #107.
cmlenz
parents: 408
diff changeset
246 <Size py:if="0" xmlns:t="test">Size</Size>
821fc97d3c0a Fix for #107.
cmlenz
parents: 408
diff changeset
247 <Item/>
821fc97d3c0a Fix for #107.
cmlenz
parents: 408
diff changeset
248 </Test>""")
460
75425671b437 Apply patch by Alec Thomas for processing XML declarations (#111). Thanks!
cmlenz
parents: 437
diff changeset
249 self.assertEqual("""<?xml version="1.0"?>\n<Test>
437
821fc97d3c0a Fix for #107.
cmlenz
parents: 408
diff changeset
250
821fc97d3c0a Fix for #107.
cmlenz
parents: 408
diff changeset
251 <Item/>
821fc97d3c0a Fix for #107.
cmlenz
parents: 408
diff changeset
252 </Test>""", str(tmpl.generate()))
821fc97d3c0a Fix for #107.
cmlenz
parents: 408
diff changeset
253
363
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
254 def test_include_in_loop(self):
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
255 dirname = tempfile.mkdtemp(suffix='genshi_test')
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
256 try:
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
257 file1 = open(os.path.join(dirname, 'tmpl1.html'), 'w')
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
258 try:
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
259 file1.write("""<div>Included $idx</div>""")
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
260 finally:
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
261 file1.close()
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
262
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
263 file2 = open(os.path.join(dirname, 'tmpl2.html'), 'w')
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
264 try:
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
265 file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude"
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
266 xmlns:py="http://genshi.edgewall.org/">
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
267 <xi:include href="${name}.html" py:for="idx in range(3)" />
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
268 </html>""")
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
269 finally:
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
270 file2.close()
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
271
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
272 loader = TemplateLoader([dirname])
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
273 tmpl = loader.load('tmpl2.html')
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
274 self.assertEqual("""<html>
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
275 <div>Included 0</div><div>Included 1</div><div>Included 2</div>
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
276 </html>""", tmpl.generate(name='tmpl1').render())
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
277 finally:
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
278 shutil.rmtree(dirname)
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
279
656
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
280 def test_dynamic_include_href(self):
363
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
281 dirname = tempfile.mkdtemp(suffix='genshi_test')
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
282 try:
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
283 file1 = open(os.path.join(dirname, 'tmpl1.html'), 'w')
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
284 try:
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
285 file1.write("""<div>Included</div>""")
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
286 finally:
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
287 file1.close()
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
288
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
289 file2 = open(os.path.join(dirname, 'tmpl2.html'), 'w')
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
290 try:
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
291 file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude"
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
292 xmlns:py="http://genshi.edgewall.org/">
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
293 <xi:include href="${name}.html" />
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
294 </html>""")
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
295 finally:
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
296 file2.close()
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
297
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
298 loader = TemplateLoader([dirname])
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
299 tmpl = loader.load('tmpl2.html')
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
300 self.assertEqual("""<html>
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
301 <div>Included</div>
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
302 </html>""", tmpl.generate(name='tmpl1').render())
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
303 finally:
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
304 shutil.rmtree(dirname)
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
305
656
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
306 def test_select_included_elements(self):
363
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
307 dirname = tempfile.mkdtemp(suffix='genshi_test')
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
308 try:
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
309 file1 = open(os.path.join(dirname, 'tmpl1.html'), 'w')
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
310 try:
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
311 file1.write("""<li>$item</li>""")
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
312 finally:
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
313 file1.close()
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
314
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
315 file2 = open(os.path.join(dirname, 'tmpl2.html'), 'w')
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
316 try:
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
317 file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude"
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
318 xmlns:py="http://genshi.edgewall.org/">
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
319 <ul py:match="ul">${select('li')}</ul>
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
320 <ul py:with="items=(1, 2, 3)">
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
321 <xi:include href="tmpl1.html" py:for="item in items" />
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
322 </ul>
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
323 </html>""")
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
324 finally:
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
325 file2.close()
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
326
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
327 loader = TemplateLoader([dirname])
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
328 tmpl = loader.load('tmpl2.html')
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
329 self.assertEqual("""<html>
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
330 <ul><li>1</li><li>2</li><li>3</li></ul>
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
331 </html>""", tmpl.generate().render())
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
332 finally:
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
333 shutil.rmtree(dirname)
37e4b4bb0b53 Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents: 336
diff changeset
334
381
b9fc7a1f76ca 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 def test_fallback_when_include_found(self):
b9fc7a1f76ca 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 dirname = tempfile.mkdtemp(suffix='genshi_test')
b9fc7a1f76ca 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 try:
b9fc7a1f76ca 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 file1 = open(os.path.join(dirname, 'tmpl1.html'), 'w')
b9fc7a1f76ca 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 try:
b9fc7a1f76ca 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 file1.write("""<div>Included</div>""")
b9fc7a1f76ca 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 finally:
b9fc7a1f76ca 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 file1.close()
b9fc7a1f76ca 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
b9fc7a1f76ca 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 = open(os.path.join(dirname, 'tmpl2.html'), 'w')
b9fc7a1f76ca 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 try:
b9fc7a1f76ca 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 file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude">
b9fc7a1f76ca 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 <xi:include href="tmpl1.html"><xi:fallback>
b9fc7a1f76ca 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 Missing</xi:fallback></xi:include>
b9fc7a1f76ca 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 </html>""")
b9fc7a1f76ca 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 finally:
b9fc7a1f76ca 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 file2.close()
b9fc7a1f76ca 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
b9fc7a1f76ca 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 loader = TemplateLoader([dirname])
b9fc7a1f76ca 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
354 tmpl = loader.load('tmpl2.html')
b9fc7a1f76ca 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
355 self.assertEqual("""<html>
b9fc7a1f76ca 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
356 <div>Included</div>
b9fc7a1f76ca 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
357 </html>""", tmpl.generate().render())
b9fc7a1f76ca 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
358 finally:
b9fc7a1f76ca 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
359 shutil.rmtree(dirname)
b9fc7a1f76ca 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
360
590
36b5a03534a0 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 def test_error_when_include_not_found(self):
36b5a03534a0 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 dirname = tempfile.mkdtemp(suffix='genshi_test')
36b5a03534a0 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 try:
36b5a03534a0 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 file2 = open(os.path.join(dirname, 'tmpl2.html'), 'w')
36b5a03534a0 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 try:
36b5a03534a0 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 file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude">
36b5a03534a0 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 <xi:include href="tmpl1.html"/>
36b5a03534a0 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 </html>""")
36b5a03534a0 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 finally:
36b5a03534a0 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 file2.close()
36b5a03534a0 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
371
36b5a03534a0 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
372 loader = TemplateLoader([dirname], auto_reload=True)
36b5a03534a0 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
373 tmpl = loader.load('tmpl2.html')
36b5a03534a0 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
374 self.assertRaises(TemplateNotFound, tmpl.generate().render)
36b5a03534a0 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
375 finally:
36b5a03534a0 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
376 shutil.rmtree(dirname)
36b5a03534a0 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
377
381
b9fc7a1f76ca 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 def test_fallback_when_include_not_found(self):
b9fc7a1f76ca 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 dirname = tempfile.mkdtemp(suffix='genshi_test')
b9fc7a1f76ca 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 try:
b9fc7a1f76ca 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 = open(os.path.join(dirname, 'tmpl2.html'), 'w')
b9fc7a1f76ca 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 try:
b9fc7a1f76ca 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 file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude">
b9fc7a1f76ca 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 <xi:include href="tmpl1.html"><xi:fallback>
b9fc7a1f76ca 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 Missing</xi:fallback></xi:include>
b9fc7a1f76ca 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 </html>""")
b9fc7a1f76ca 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 finally:
b9fc7a1f76ca 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 file2.close()
b9fc7a1f76ca 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
b9fc7a1f76ca 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 loader = TemplateLoader([dirname])
b9fc7a1f76ca 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
391 tmpl = loader.load('tmpl2.html')
b9fc7a1f76ca 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
392 self.assertEqual("""<html>
b9fc7a1f76ca 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
393 Missing
b9fc7a1f76ca 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
394 </html>""", tmpl.generate().render())
b9fc7a1f76ca 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
395 finally:
b9fc7a1f76ca 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
396 shutil.rmtree(dirname)
b9fc7a1f76ca 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
397
639
8e11a6693bb3 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 def test_fallback_when_auto_reload_true(self):
8e11a6693bb3 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 dirname = tempfile.mkdtemp(suffix='genshi_test')
8e11a6693bb3 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 try:
8e11a6693bb3 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 = open(os.path.join(dirname, 'tmpl2.html'), 'w')
8e11a6693bb3 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 try:
8e11a6693bb3 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 file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude">
8e11a6693bb3 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 <xi:include href="tmpl1.html"><xi:fallback>
8e11a6693bb3 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 Missing</xi:fallback></xi:include>
8e11a6693bb3 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 </html>""")
8e11a6693bb3 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 finally:
8e11a6693bb3 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 file2.close()
8e11a6693bb3 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
8e11a6693bb3 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 loader = TemplateLoader([dirname], auto_reload=True)
8e11a6693bb3 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
411 tmpl = loader.load('tmpl2.html')
8e11a6693bb3 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
412 self.assertEqual("""<html>
8e11a6693bb3 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
413 Missing
8e11a6693bb3 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
414 </html>""", tmpl.generate().render())
8e11a6693bb3 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
415 finally:
8e11a6693bb3 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
416 shutil.rmtree(dirname)
8e11a6693bb3 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
417
381
b9fc7a1f76ca 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 def test_include_in_fallback(self):
b9fc7a1f76ca 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 dirname = tempfile.mkdtemp(suffix='genshi_test')
b9fc7a1f76ca 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 try:
b9fc7a1f76ca 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 file1 = open(os.path.join(dirname, 'tmpl1.html'), 'w')
b9fc7a1f76ca 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 try:
b9fc7a1f76ca 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 file1.write("""<div>Included</div>""")
b9fc7a1f76ca 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 finally:
b9fc7a1f76ca 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 file1.close()
b9fc7a1f76ca 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
b9fc7a1f76ca 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 file2 = open(os.path.join(dirname, 'tmpl3.html'), 'w')
b9fc7a1f76ca 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 try:
b9fc7a1f76ca 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 file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude">
b9fc7a1f76ca 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 <xi:include href="tmpl2.html">
b9fc7a1f76ca 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 <xi:fallback>
b9fc7a1f76ca 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 <xi:include href="tmpl1.html">
b9fc7a1f76ca 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 <xi:fallback>Missing</xi:fallback>
b9fc7a1f76ca 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 </xi:include>
b9fc7a1f76ca 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 </xi:fallback>
b9fc7a1f76ca 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 </xi:include>
b9fc7a1f76ca 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
437 </html>""")
b9fc7a1f76ca 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 finally:
b9fc7a1f76ca 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 file2.close()
b9fc7a1f76ca 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
b9fc7a1f76ca 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 loader = TemplateLoader([dirname])
b9fc7a1f76ca 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 tmpl = loader.load('tmpl3.html')
b9fc7a1f76ca 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 self.assertEqual("""<html>
590
36b5a03534a0 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
444 <div>Included</div>
381
b9fc7a1f76ca 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 </html>""", tmpl.generate().render())
b9fc7a1f76ca 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 finally:
b9fc7a1f76ca 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 shutil.rmtree(dirname)
b9fc7a1f76ca 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
b9fc7a1f76ca 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 def test_nested_include_fallback(self):
b9fc7a1f76ca 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 dirname = tempfile.mkdtemp(suffix='genshi_test')
b9fc7a1f76ca 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 try:
b9fc7a1f76ca 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 file2 = open(os.path.join(dirname, 'tmpl3.html'), 'w')
b9fc7a1f76ca 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 try:
b9fc7a1f76ca 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 file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude">
b9fc7a1f76ca 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 <xi:include href="tmpl2.html">
b9fc7a1f76ca 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 <xi:fallback>
b9fc7a1f76ca 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 <xi:include href="tmpl1.html">
b9fc7a1f76ca 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 <xi:fallback>Missing</xi:fallback>
b9fc7a1f76ca 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 </xi:include>
b9fc7a1f76ca 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 </xi:fallback>
b9fc7a1f76ca 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 </xi:include>
b9fc7a1f76ca 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
462 </html>""")
b9fc7a1f76ca 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
463 finally:
b9fc7a1f76ca 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
464 file2.close()
b9fc7a1f76ca 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
465
b9fc7a1f76ca 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
466 loader = TemplateLoader([dirname])
b9fc7a1f76ca 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
467 tmpl = loader.load('tmpl3.html')
b9fc7a1f76ca 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
468 self.assertEqual("""<html>
590
36b5a03534a0 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 Missing
36b5a03534a0 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 </html>""", tmpl.generate().render())
36b5a03534a0 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 finally:
36b5a03534a0 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 shutil.rmtree(dirname)
36b5a03534a0 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
36b5a03534a0 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 def test_nested_include_in_fallback(self):
36b5a03534a0 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 dirname = tempfile.mkdtemp(suffix='genshi_test')
36b5a03534a0 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 try:
36b5a03534a0 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 file1 = open(os.path.join(dirname, 'tmpl2.html'), 'w')
36b5a03534a0 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 try:
36b5a03534a0 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 file1.write("""<div>Included</div>""")
36b5a03534a0 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 finally:
36b5a03534a0 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 file1.close()
36b5a03534a0 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
36b5a03534a0 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 file2 = open(os.path.join(dirname, 'tmpl3.html'), 'w')
36b5a03534a0 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 try:
36b5a03534a0 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 file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude">
36b5a03534a0 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 <xi:include href="tmpl2.html">
36b5a03534a0 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 <xi:fallback>
36b5a03534a0 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 <xi:include href="tmpl1.html" />
36b5a03534a0 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 </xi:fallback>
36b5a03534a0 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 </xi:include>
36b5a03534a0 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 </html>""")
36b5a03534a0 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
492 finally:
36b5a03534a0 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
493 file2.close()
36b5a03534a0 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
494
36b5a03534a0 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
495 loader = TemplateLoader([dirname])
36b5a03534a0 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
496 tmpl = loader.load('tmpl3.html')
36b5a03534a0 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
497 self.assertEqual("""<html>
36b5a03534a0 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
498 <div>Included</div>
381
b9fc7a1f76ca 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 </html>""", tmpl.generate().render())
b9fc7a1f76ca 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 finally:
b9fc7a1f76ca 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 shutil.rmtree(dirname)
b9fc7a1f76ca 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
b9fc7a1f76ca 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 def test_include_fallback_with_directive(self):
b9fc7a1f76ca 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 dirname = tempfile.mkdtemp(suffix='genshi_test')
b9fc7a1f76ca 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 try:
b9fc7a1f76ca 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 file2 = open(os.path.join(dirname, 'tmpl2.html'), 'w')
b9fc7a1f76ca 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 try:
b9fc7a1f76ca 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.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude"
b9fc7a1f76ca 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 xmlns:py="http://genshi.edgewall.org/">
b9fc7a1f76ca 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 <xi:include href="tmpl1.html"><xi:fallback>
b9fc7a1f76ca 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 <py:if test="True">tmpl1.html not found</py:if>
b9fc7a1f76ca 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 </xi:fallback></xi:include>
b9fc7a1f76ca 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 </html>""")
b9fc7a1f76ca 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 finally:
b9fc7a1f76ca 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 file2.close()
b9fc7a1f76ca 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
b9fc7a1f76ca 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 loader = TemplateLoader([dirname])
b9fc7a1f76ca 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
518 tmpl = loader.load('tmpl2.html')
b9fc7a1f76ca 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
519 self.assertEqual("""<html>
b9fc7a1f76ca 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
520 tmpl1.html not found
b9fc7a1f76ca 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
521 </html>""", tmpl.generate(debug=True).render())
b9fc7a1f76ca 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
522 finally:
b9fc7a1f76ca 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
523 shutil.rmtree(dirname)
b9fc7a1f76ca 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
524
548
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
525 def test_include_inlined(self):
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
526 dirname = tempfile.mkdtemp(suffix='genshi_test')
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
527 try:
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
528 file1 = open(os.path.join(dirname, 'tmpl1.html'), 'w')
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
529 try:
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
530 file1.write("""<div>Included</div>""")
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
531 finally:
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
532 file1.close()
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
533
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
534 file2 = open(os.path.join(dirname, 'tmpl2.html'), 'w')
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
535 try:
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
536 file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude"
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
537 xmlns:py="http://genshi.edgewall.org/">
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
538 <xi:include href="tmpl1.html" />
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
539 </html>""")
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
540 finally:
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
541 file2.close()
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
542
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
543 loader = TemplateLoader([dirname], auto_reload=False)
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
544 tmpl = loader.load('tmpl2.html')
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
545 # if not inlined the following would be 5
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
546 self.assertEqual(7, len(tmpl.stream))
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
547 self.assertEqual("""<html>
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
548 <div>Included</div>
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
549 </html>""", tmpl.generate().render())
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
550 finally:
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
551 shutil.rmtree(dirname)
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
552
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
553 def test_include_inlined_in_loop(self):
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
554 dirname = tempfile.mkdtemp(suffix='genshi_test')
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
555 try:
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
556 file1 = open(os.path.join(dirname, 'tmpl1.html'), 'w')
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
557 try:
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
558 file1.write("""<div>Included $idx</div>""")
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
559 finally:
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
560 file1.close()
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
561
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
562 file2 = open(os.path.join(dirname, 'tmpl2.html'), 'w')
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
563 try:
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
564 file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude"
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
565 xmlns:py="http://genshi.edgewall.org/">
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
566 <xi:include href="tmpl1.html" py:for="idx in range(3)" />
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
567 </html>""")
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
568 finally:
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
569 file2.close()
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
570
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
571 loader = TemplateLoader([dirname], auto_reload=False)
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
572 tmpl = loader.load('tmpl2.html')
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
573 self.assertEqual("""<html>
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
574 <div>Included 0</div><div>Included 1</div><div>Included 2</div>
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
575 </html>""", tmpl.generate().render())
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
576 finally:
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
577 shutil.rmtree(dirname)
1cc1afc39176 Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents: 546
diff changeset
578
545
619340e2d805 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
579 def test_allow_exec_false(self):
619340e2d805 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
580 xml = ("""<?python
619340e2d805 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
581 title = "A Genshi Template"
619340e2d805 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
582 ?>
619340e2d805 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
583 <html xmlns:py="http://genshi.edgewall.org/">
619340e2d805 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
584 <head>
619340e2d805 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
585 <title py:content="title">This is replaced.</title>
619340e2d805 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
586 </head>
619340e2d805 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
587 </html>""")
619340e2d805 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
588 try:
619340e2d805 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
589 tmpl = MarkupTemplate(xml, filename='test.html',
619340e2d805 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
590 allow_exec=False)
619340e2d805 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
591 self.fail('Expected SyntaxError')
619340e2d805 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
592 except TemplateSyntaxError, e:
619340e2d805 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
593 pass
619340e2d805 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
594
619340e2d805 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
595 def test_allow_exec_true(self):
619340e2d805 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
596 xml = ("""<?python
619340e2d805 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
597 title = "A Genshi Template"
619340e2d805 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
598 ?>
619340e2d805 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
599 <html xmlns:py="http://genshi.edgewall.org/">
619340e2d805 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
600 <head>
619340e2d805 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
601 <title py:content="title">This is replaced.</title>
619340e2d805 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
602 </head>
619340e2d805 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
603 </html>""")
619340e2d805 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 520
diff changeset
604 tmpl = MarkupTemplate(xml, filename='test.html', allow_exec=True)
336
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
605
650
9ff8eccc6f1f Code blocks in match templates are now executed. Closes #155. Many thanks to Andrew Sutherland for the patch!
cmlenz
parents: 639
diff changeset
606 def test_exec_in_match(self):
9ff8eccc6f1f Code blocks in match templates are now executed. Closes #155. Many thanks to Andrew Sutherland for the patch!
cmlenz
parents: 639
diff changeset
607 xml = ("""<html xmlns:py="http://genshi.edgewall.org/">
9ff8eccc6f1f Code blocks in match templates are now executed. Closes #155. Many thanks to Andrew Sutherland for the patch!
cmlenz
parents: 639
diff changeset
608 <py:match path="body/p">
9ff8eccc6f1f Code blocks in match templates are now executed. Closes #155. Many thanks to Andrew Sutherland for the patch!
cmlenz
parents: 639
diff changeset
609 <?python title="wakka wakka wakka" ?>
9ff8eccc6f1f Code blocks in match templates are now executed. Closes #155. Many thanks to Andrew Sutherland for the patch!
cmlenz
parents: 639
diff changeset
610 ${title}
9ff8eccc6f1f Code blocks in match templates are now executed. Closes #155. Many thanks to Andrew Sutherland for the patch!
cmlenz
parents: 639
diff changeset
611 </py:match>
9ff8eccc6f1f Code blocks in match templates are now executed. Closes #155. Many thanks to Andrew Sutherland for the patch!
cmlenz
parents: 639
diff changeset
612 <body><p>moot text</p></body>
9ff8eccc6f1f Code blocks in match templates are now executed. Closes #155. Many thanks to Andrew Sutherland for the patch!
cmlenz
parents: 639
diff changeset
613 </html>""")
9ff8eccc6f1f Code blocks in match templates are now executed. Closes #155. Many thanks to Andrew Sutherland for the patch!
cmlenz
parents: 639
diff changeset
614 tmpl = MarkupTemplate(xml, filename='test.html', allow_exec=True)
9ff8eccc6f1f Code blocks in match templates are now executed. Closes #155. Many thanks to Andrew Sutherland for the patch!
cmlenz
parents: 639
diff changeset
615 self.assertEqual("""<html>
9ff8eccc6f1f Code blocks in match templates are now executed. Closes #155. Many thanks to Andrew Sutherland for the patch!
cmlenz
parents: 639
diff changeset
616 <body>
9ff8eccc6f1f Code blocks in match templates are now executed. Closes #155. Many thanks to Andrew Sutherland for the patch!
cmlenz
parents: 639
diff changeset
617 wakka wakka wakka
9ff8eccc6f1f Code blocks in match templates are now executed. Closes #155. Many thanks to Andrew Sutherland for the patch!
cmlenz
parents: 639
diff changeset
618 </body>
9ff8eccc6f1f Code blocks in match templates are now executed. Closes #155. Many thanks to Andrew Sutherland for the patch!
cmlenz
parents: 639
diff changeset
619 </html>""", tmpl.generate().render())
9ff8eccc6f1f Code blocks in match templates are now executed. Closes #155. Many thanks to Andrew Sutherland for the patch!
cmlenz
parents: 639
diff changeset
620
700
08f22328303d Add option for unbuffered match template processing, which could cause excessive memory usage. Closes #190.
cmlenz
parents: 656
diff changeset
621 def test_with_in_match(self):
08f22328303d Add option for unbuffered match template processing, which could cause excessive memory usage. Closes #190.
cmlenz
parents: 656
diff changeset
622 xml = ("""<html xmlns:py="http://genshi.edgewall.org/">
08f22328303d Add option for unbuffered match template processing, which could cause excessive memory usage. Closes #190.
cmlenz
parents: 656
diff changeset
623 <py:match path="body/p">
08f22328303d Add option for unbuffered match template processing, which could cause excessive memory usage. Closes #190.
cmlenz
parents: 656
diff changeset
624 <h1>${select('text()')}</h1>
08f22328303d Add option for unbuffered match template processing, which could cause excessive memory usage. Closes #190.
cmlenz
parents: 656
diff changeset
625 ${select('.')}
08f22328303d Add option for unbuffered match template processing, which could cause excessive memory usage. Closes #190.
cmlenz
parents: 656
diff changeset
626 </py:match>
08f22328303d Add option for unbuffered match template processing, which could cause excessive memory usage. Closes #190.
cmlenz
parents: 656
diff changeset
627 <body><p py:with="foo='bar'">${foo}</p></body>
08f22328303d Add option for unbuffered match template processing, which could cause excessive memory usage. Closes #190.
cmlenz
parents: 656
diff changeset
628 </html>""")
08f22328303d Add option for unbuffered match template processing, which could cause excessive memory usage. Closes #190.
cmlenz
parents: 656
diff changeset
629 tmpl = MarkupTemplate(xml, filename='test.html')
08f22328303d Add option for unbuffered match template processing, which could cause excessive memory usage. Closes #190.
cmlenz
parents: 656
diff changeset
630 self.assertEqual("""<html>
08f22328303d Add option for unbuffered match template processing, which could cause excessive memory usage. Closes #190.
cmlenz
parents: 656
diff changeset
631 <body>
08f22328303d Add option for unbuffered match template processing, which could cause excessive memory usage. Closes #190.
cmlenz
parents: 656
diff changeset
632 <h1>bar</h1>
08f22328303d Add option for unbuffered match template processing, which could cause excessive memory usage. Closes #190.
cmlenz
parents: 656
diff changeset
633 <p>bar</p>
08f22328303d Add option for unbuffered match template processing, which could cause excessive memory usage. Closes #190.
cmlenz
parents: 656
diff changeset
634 </body>
08f22328303d Add option for unbuffered match template processing, which could cause excessive memory usage. Closes #190.
cmlenz
parents: 656
diff changeset
635 </html>""", tmpl.generate().render())
08f22328303d Add option for unbuffered match template processing, which could cause excessive memory usage. Closes #190.
cmlenz
parents: 656
diff changeset
636
656
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
637 def test_nested_include_matches(self):
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
638 # See ticket #157
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
639 dirname = tempfile.mkdtemp(suffix='genshi_test')
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
640 try:
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
641 file1 = open(os.path.join(dirname, 'tmpl1.html'), 'w')
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
642 try:
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
643 file1.write("""<html xmlns:py="http://genshi.edgewall.org/" py:strip="">
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
644 <div class="target">Some content.</div>
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
645 </html>""")
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
646 finally:
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
647 file1.close()
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
648
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
649 file2 = open(os.path.join(dirname, 'tmpl2.html'), 'w')
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
650 try:
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
651 file2.write("""<html xmlns:py="http://genshi.edgewall.org/"
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
652 xmlns:xi="http://www.w3.org/2001/XInclude">
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
653 <body>
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
654 <h1>Some full html document that includes file1.html</h1>
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
655 <xi:include href="tmpl1.html" />
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
656 </body>
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
657 </html>""")
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
658 finally:
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
659 file2.close()
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
660
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
661 file3 = open(os.path.join(dirname, 'tmpl3.html'), 'w')
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
662 try:
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
663 file3.write("""<html xmlns:py="http://genshi.edgewall.org/"
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
664 xmlns:xi="http://www.w3.org/2001/XInclude" py:strip="">
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
665 <div py:match="div[@class='target']" py:attrs="select('@*')">
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
666 Some added stuff.
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
667 ${select('*|text()')}
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
668 </div>
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
669 <xi:include href="tmpl2.html" />
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
670 </html>
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
671 """)
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
672 finally:
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
673 file3.close()
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
674
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
675 loader = TemplateLoader([dirname])
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
676 tmpl = loader.load('tmpl3.html')
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
677 self.assertEqual("""
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
678 <html>
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
679 <body>
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
680 <h1>Some full html document that includes file1.html</h1>
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
681 <div class="target">
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
682 Some added stuff.
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
683 Some content.
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
684 </div>
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
685 </body>
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
686 </html>
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
687 """, tmpl.generate().render())
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
688 finally:
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
689 shutil.rmtree(dirname)
f3bc1de7138d Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents: 650
diff changeset
690
758
9f28d17b1f72 Fix problem with nested match templates not being applied when buffering on the outer `py:match` is disabled. Thanks to Erik Bray for reporting the problem and providing a test case.
cmlenz
parents: 750
diff changeset
691 def test_nested_matches_without_buffering(self):
9f28d17b1f72 Fix problem with nested match templates not being applied when buffering on the outer `py:match` is disabled. Thanks to Erik Bray for reporting the problem and providing a test case.
cmlenz
parents: 750
diff changeset
692 xml = ("""<html xmlns:py="http://genshi.edgewall.org/">
9f28d17b1f72 Fix problem with nested match templates not being applied when buffering on the outer `py:match` is disabled. Thanks to Erik Bray for reporting the problem and providing a test case.
cmlenz
parents: 750
diff changeset
693 <py:match path="body" once="true" buffer="false">
9f28d17b1f72 Fix problem with nested match templates not being applied when buffering on the outer `py:match` is disabled. Thanks to Erik Bray for reporting the problem and providing a test case.
cmlenz
parents: 750
diff changeset
694 <body>
9f28d17b1f72 Fix problem with nested match templates not being applied when buffering on the outer `py:match` is disabled. Thanks to Erik Bray for reporting the problem and providing a test case.
cmlenz
parents: 750
diff changeset
695 ${select('*|text')}
9f28d17b1f72 Fix problem with nested match templates not being applied when buffering on the outer `py:match` is disabled. Thanks to Erik Bray for reporting the problem and providing a test case.
cmlenz
parents: 750
diff changeset
696 And some other stuff...
9f28d17b1f72 Fix problem with nested match templates not being applied when buffering on the outer `py:match` is disabled. Thanks to Erik Bray for reporting the problem and providing a test case.
cmlenz
parents: 750
diff changeset
697 </body>
9f28d17b1f72 Fix problem with nested match templates not being applied when buffering on the outer `py:match` is disabled. Thanks to Erik Bray for reporting the problem and providing a test case.
cmlenz
parents: 750
diff changeset
698 </py:match>
9f28d17b1f72 Fix problem with nested match templates not being applied when buffering on the outer `py:match` is disabled. Thanks to Erik Bray for reporting the problem and providing a test case.
cmlenz
parents: 750
diff changeset
699 <body>
9f28d17b1f72 Fix problem with nested match templates not being applied when buffering on the outer `py:match` is disabled. Thanks to Erik Bray for reporting the problem and providing a test case.
cmlenz
parents: 750
diff changeset
700 <span py:match="span">Foo</span>
9f28d17b1f72 Fix problem with nested match templates not being applied when buffering on the outer `py:match` is disabled. Thanks to Erik Bray for reporting the problem and providing a test case.
cmlenz
parents: 750
diff changeset
701 <span>Bar</span>
9f28d17b1f72 Fix problem with nested match templates not being applied when buffering on the outer `py:match` is disabled. Thanks to Erik Bray for reporting the problem and providing a test case.
cmlenz
parents: 750
diff changeset
702 </body>
9f28d17b1f72 Fix problem with nested match templates not being applied when buffering on the outer `py:match` is disabled. Thanks to Erik Bray for reporting the problem and providing a test case.
cmlenz
parents: 750
diff changeset
703 </html>""")
9f28d17b1f72 Fix problem with nested match templates not being applied when buffering on the outer `py:match` is disabled. Thanks to Erik Bray for reporting the problem and providing a test case.
cmlenz
parents: 750
diff changeset
704 tmpl = MarkupTemplate(xml, filename='test.html')
9f28d17b1f72 Fix problem with nested match templates not being applied when buffering on the outer `py:match` is disabled. Thanks to Erik Bray for reporting the problem and providing a test case.
cmlenz
parents: 750
diff changeset
705 self.assertEqual("""<html>
9f28d17b1f72 Fix problem with nested match templates not being applied when buffering on the outer `py:match` is disabled. Thanks to Erik Bray for reporting the problem and providing a test case.
cmlenz
parents: 750
diff changeset
706 <body>
9f28d17b1f72 Fix problem with nested match templates not being applied when buffering on the outer `py:match` is disabled. Thanks to Erik Bray for reporting the problem and providing a test case.
cmlenz
parents: 750
diff changeset
707 <span>Foo</span>
9f28d17b1f72 Fix problem with nested match templates not being applied when buffering on the outer `py:match` is disabled. Thanks to Erik Bray for reporting the problem and providing a test case.
cmlenz
parents: 750
diff changeset
708 And some other stuff...
9f28d17b1f72 Fix problem with nested match templates not being applied when buffering on the outer `py:match` is disabled. Thanks to Erik Bray for reporting the problem and providing a test case.
cmlenz
parents: 750
diff changeset
709 </body>
9f28d17b1f72 Fix problem with nested match templates not being applied when buffering on the outer `py:match` is disabled. Thanks to Erik Bray for reporting the problem and providing a test case.
cmlenz
parents: 750
diff changeset
710 </html>""", tmpl.generate().render())
9f28d17b1f72 Fix problem with nested match templates not being applied when buffering on the outer `py:match` is disabled. Thanks to Erik Bray for reporting the problem and providing a test case.
cmlenz
parents: 750
diff changeset
711
771
2c2e9e685424 Unbuffered match templates could result in parts of the matched content being included in the output if the match template didn't actually consume it via one or more calls to the `select()` function. Closes #243. Thanks to Felix Schwarz for the report and test case.
cmlenz
parents: 758
diff changeset
712 def test_match_without_select(self):
2c2e9e685424 Unbuffered match templates could result in parts of the matched content being included in the output if the match template didn't actually consume it via one or more calls to the `select()` function. Closes #243. Thanks to Felix Schwarz for the report and test case.
cmlenz
parents: 758
diff changeset
713 # See <http://genshi.edgewall.org/ticket/243>
2c2e9e685424 Unbuffered match templates could result in parts of the matched content being included in the output if the match template didn't actually consume it via one or more calls to the `select()` function. Closes #243. Thanks to Felix Schwarz for the report and test case.
cmlenz
parents: 758
diff changeset
714 xml = ("""<html xmlns:py="http://genshi.edgewall.org/">
2c2e9e685424 Unbuffered match templates could result in parts of the matched content being included in the output if the match template didn't actually consume it via one or more calls to the `select()` function. Closes #243. Thanks to Felix Schwarz for the report and test case.
cmlenz
parents: 758
diff changeset
715 <py:match path="body" buffer="false">
2c2e9e685424 Unbuffered match templates could result in parts of the matched content being included in the output if the match template didn't actually consume it via one or more calls to the `select()` function. Closes #243. Thanks to Felix Schwarz for the report and test case.
cmlenz
parents: 758
diff changeset
716 <body>
2c2e9e685424 Unbuffered match templates could result in parts of the matched content being included in the output if the match template didn't actually consume it via one or more calls to the `select()` function. Closes #243. Thanks to Felix Schwarz for the report and test case.
cmlenz
parents: 758
diff changeset
717 This replaces the other text.
2c2e9e685424 Unbuffered match templates could result in parts of the matched content being included in the output if the match template didn't actually consume it via one or more calls to the `select()` function. Closes #243. Thanks to Felix Schwarz for the report and test case.
cmlenz
parents: 758
diff changeset
718 </body>
2c2e9e685424 Unbuffered match templates could result in parts of the matched content being included in the output if the match template didn't actually consume it via one or more calls to the `select()` function. Closes #243. Thanks to Felix Schwarz for the report and test case.
cmlenz
parents: 758
diff changeset
719 </py:match>
2c2e9e685424 Unbuffered match templates could result in parts of the matched content being included in the output if the match template didn't actually consume it via one or more calls to the `select()` function. Closes #243. Thanks to Felix Schwarz for the report and test case.
cmlenz
parents: 758
diff changeset
720 <body>
2c2e9e685424 Unbuffered match templates could result in parts of the matched content being included in the output if the match template didn't actually consume it via one or more calls to the `select()` function. Closes #243. Thanks to Felix Schwarz for the report and test case.
cmlenz
parents: 758
diff changeset
721 This gets replaced.
2c2e9e685424 Unbuffered match templates could result in parts of the matched content being included in the output if the match template didn't actually consume it via one or more calls to the `select()` function. Closes #243. Thanks to Felix Schwarz for the report and test case.
cmlenz
parents: 758
diff changeset
722 </body>
2c2e9e685424 Unbuffered match templates could result in parts of the matched content being included in the output if the match template didn't actually consume it via one or more calls to the `select()` function. Closes #243. Thanks to Felix Schwarz for the report and test case.
cmlenz
parents: 758
diff changeset
723 </html>""")
2c2e9e685424 Unbuffered match templates could result in parts of the matched content being included in the output if the match template didn't actually consume it via one or more calls to the `select()` function. Closes #243. Thanks to Felix Schwarz for the report and test case.
cmlenz
parents: 758
diff changeset
724 tmpl = MarkupTemplate(xml, filename='test.html')
2c2e9e685424 Unbuffered match templates could result in parts of the matched content being included in the output if the match template didn't actually consume it via one or more calls to the `select()` function. Closes #243. Thanks to Felix Schwarz for the report and test case.
cmlenz
parents: 758
diff changeset
725 self.assertEqual("""<html>
2c2e9e685424 Unbuffered match templates could result in parts of the matched content being included in the output if the match template didn't actually consume it via one or more calls to the `select()` function. Closes #243. Thanks to Felix Schwarz for the report and test case.
cmlenz
parents: 758
diff changeset
726 <body>
2c2e9e685424 Unbuffered match templates could result in parts of the matched content being included in the output if the match template didn't actually consume it via one or more calls to the `select()` function. Closes #243. Thanks to Felix Schwarz for the report and test case.
cmlenz
parents: 758
diff changeset
727 This replaces the other text.
2c2e9e685424 Unbuffered match templates could result in parts of the matched content being included in the output if the match template didn't actually consume it via one or more calls to the `select()` function. Closes #243. Thanks to Felix Schwarz for the report and test case.
cmlenz
parents: 758
diff changeset
728 </body>
2c2e9e685424 Unbuffered match templates could result in parts of the matched content being included in the output if the match template didn't actually consume it via one or more calls to the `select()` function. Closes #243. Thanks to Felix Schwarz for the report and test case.
cmlenz
parents: 758
diff changeset
729 </html>""", tmpl.generate().render())
2c2e9e685424 Unbuffered match templates could result in parts of the matched content being included in the output if the match template didn't actually consume it via one or more calls to the `select()` function. Closes #243. Thanks to Felix Schwarz for the report and test case.
cmlenz
parents: 758
diff changeset
730
546
2a3fc03b11de White space.
cmlenz
parents: 545
diff changeset
731
336
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
732 def suite():
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
733 suite = unittest.TestSuite()
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
734 suite.addTest(doctest.DocTestSuite(MarkupTemplate.__module__))
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
735 suite.addTest(unittest.makeSuite(MarkupTemplateTestCase, 'test'))
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
736 return suite
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
737
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
738 if __name__ == '__main__':
7763f7aec949 Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff changeset
739 unittest.main(defaultTest='suite')
Copyright (C) 2012-2017 Edgewall Software