Mercurial > genshi > mirror
annotate genshi/template/tests/markup.py @ 1033:348ba73df25c stable-0.6.x
Merge r1257 from trunk (fix for infinite template inlining).
author | hodgestar |
---|---|
date | Wed, 19 Mar 2014 13:56:46 +0000 |
parents | 832bdab41eee |
children |
rev | line source |
---|---|
336
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
2 # |
854
4d9bef447df9
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
825
diff
changeset
|
3 # Copyright (C) 2006-2009 Edgewall Software |
336
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
4 # All rights reserved. |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
5 # |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
6 # This software is licensed as described in the file COPYING, which |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
7 # you should have received as part of this distribution. The terms |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
8 # are also available at http://genshi.edgewall.org/wiki/License. |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
9 # |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
10 # This software consists of voluntary contributions made by many |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
11 # individuals. For the exact contribution history, see the revision |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
12 # history and logs, available at http://genshi.edgewall.org/log/. |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
13 |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
14 import doctest |
363
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
15 import os |
715 | 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 | 43 def test_pickle(self): |
44 stream = XML('<root>$var</root>') | |
45 tmpl = MarkupTemplate(stream) | |
46 buf = StringIO() | |
47 pickle.dump(tmpl, buf, 2) | |
48 buf.seek(0) | |
49 unpickled = pickle.load(buf) | |
50 self.assertEqual('<root>42</root>', str(unpickled.generate(var=42))) | |
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 |
825
728f25c1d1a3
Minor simplification and performance improvement to the flattening of dynamic attribute values. Thanks to Christoph Zwerschke for the suggestion (see #295).
cmlenz
parents:
790
diff
changeset
|
78 def test_empty_attr_interpolated(self): |
728f25c1d1a3
Minor simplification and performance improvement to the flattening of dynamic attribute values. Thanks to Christoph Zwerschke for the suggestion (see #295).
cmlenz
parents:
790
diff
changeset
|
79 tmpl = MarkupTemplate('<root attr="$attr"/>') |
728f25c1d1a3
Minor simplification and performance improvement to the flattening of dynamic attribute values. Thanks to Christoph Zwerschke for the suggestion (see #295).
cmlenz
parents:
790
diff
changeset
|
80 self.assertEqual('<root attr=""/>', str(tmpl.generate(attr=''))) |
728f25c1d1a3
Minor simplification and performance improvement to the flattening of dynamic attribute values. Thanks to Christoph Zwerschke for the suggestion (see #295).
cmlenz
parents:
790
diff
changeset
|
81 |
336
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
82 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
|
83 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
|
84 try: |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
85 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
|
86 except BadDirectiveError, e: |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
87 self.assertEqual('test.html', e.filename) |
750 | 88 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
|
89 |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
90 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
|
91 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
|
92 try: |
790
da90cee22560
Merged the custom-directives branch back into trunk.
cmlenz
parents:
771
diff
changeset
|
93 tmpl = MarkupTemplate(xml, filename='test.html').generate() |
da90cee22560
Merged the custom-directives branch back into trunk.
cmlenz
parents:
771
diff
changeset
|
94 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
|
95 except TemplateSyntaxError, e: |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
96 self.assertEqual('test.html', e.filename) |
750 | 97 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
|
98 |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
99 def test_expression_syntax_error(self): |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
100 xml = """<p> |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
101 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
|
102 </p>""" |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
103 try: |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
104 tmpl = MarkupTemplate(xml, filename='test.html') |
790
da90cee22560
Merged the custom-directives branch back into trunk.
cmlenz
parents:
771
diff
changeset
|
105 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
|
106 except TemplateSyntaxError, e: |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
107 self.assertEqual('test.html', e.filename) |
750 | 108 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
|
109 |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
110 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
|
111 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
|
112 |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
113 ${bar"} |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
114 |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
115 </p>""" |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
116 try: |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
117 tmpl = MarkupTemplate(xml, filename='test.html') |
790
da90cee22560
Merged the custom-directives branch back into trunk.
cmlenz
parents:
771
diff
changeset
|
118 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
|
119 except TemplateSyntaxError, e: |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
120 self.assertEqual('test.html', e.filename) |
750 | 121 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
|
122 |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
123 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
|
124 """ |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
125 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
|
126 escaped. |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
127 """ |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
128 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
|
129 $myvar |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
130 </div>""") |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
131 self.assertEqual("""<div> |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
132 <b>foo</b> |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
133 </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
|
134 |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
135 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
|
136 """ |
790
da90cee22560
Merged the custom-directives branch back into trunk.
cmlenz
parents:
771
diff
changeset
|
137 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
|
138 quotes. |
336
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
139 """ |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
140 tmpl = MarkupTemplate("""<div xmlns:py="http://genshi.edgewall.org/"> |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
141 $myvar |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
142 </div>""") |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
143 self.assertEqual("""<div> |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
144 "foo" |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
145 </div>""", str(tmpl.generate(myvar='"foo"'))) |
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 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
|
148 """ |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
149 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
|
150 """ |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
151 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
|
152 <elem class="$myvar"/> |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
153 </div>""") |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
154 self.assertEqual("""<div> |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
155 <elem class=""foo""/> |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
156 </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
|
157 |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
158 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
|
159 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
|
160 <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
|
161 </div>""") |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
162 self.assertEqual("""<div> |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
163 bar |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
164 </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
|
165 |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
166 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
|
167 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
|
168 <!-- foo bar --> |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
169 </div>""") |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
170 self.assertEqual("""<div> |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
171 <!-- foo bar --> |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
172 </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
|
173 |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
174 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
|
175 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
|
176 <!-- !foo --> |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
177 <!--!bar--> |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
178 </div>""") |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
179 self.assertEqual("""<div> |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
180 </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
|
181 |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
182 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
|
183 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
|
184 <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
|
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>""") |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
187 self.assertEqual("""<div> |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
188 <span> |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
189 </span> |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
190 </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
|
191 |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
192 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
|
193 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
|
194 <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
|
195 \xf6 |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
196 </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
|
197 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
|
198 \xf6 |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
199 </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
|
200 |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
201 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
|
202 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
|
203 \xf6 |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
204 </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
|
205 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
|
206 \xf6 |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
207 </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
|
208 |
520
203bd6a3c93d
Applied patch by Dale Sedivec to fix #127. Many thanks!
cmlenz
parents:
460
diff
changeset
|
209 def test_exec_with_trailing_space(self): |
203bd6a3c93d
Applied patch by Dale Sedivec to fix #127. Many thanks!
cmlenz
parents:
460
diff
changeset
|
210 """ |
203bd6a3c93d
Applied patch by Dale Sedivec to fix #127. Many thanks!
cmlenz
parents:
460
diff
changeset
|
211 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
|
212 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
|
213 """ |
854
4d9bef447df9
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
825
diff
changeset
|
214 MarkupTemplate("""<foo> |
520
203bd6a3c93d
Applied patch by Dale Sedivec to fix #127. Many thanks!
cmlenz
parents:
460
diff
changeset
|
215 <?python |
203bd6a3c93d
Applied patch by Dale Sedivec to fix #127. Many thanks!
cmlenz
parents:
460
diff
changeset
|
216 bar = 42 |
203bd6a3c93d
Applied patch by Dale Sedivec to fix #127. Many thanks!
cmlenz
parents:
460
diff
changeset
|
217 ?> |
203bd6a3c93d
Applied patch by Dale Sedivec to fix #127. Many thanks!
cmlenz
parents:
460
diff
changeset
|
218 </foo>""") |
203bd6a3c93d
Applied patch by Dale Sedivec to fix #127. Many thanks!
cmlenz
parents:
460
diff
changeset
|
219 |
405
5340931530e2
Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents:
400
diff
changeset
|
220 def test_exec_import(self): |
854
4d9bef447df9
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
825
diff
changeset
|
221 tmpl = MarkupTemplate("""<?python from datetime import timedelta ?> |
405
5340931530e2
Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents:
400
diff
changeset
|
222 <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
|
223 ${timedelta(days=2)} |
5340931530e2
Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents:
400
diff
changeset
|
224 </div>""") |
854
4d9bef447df9
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
825
diff
changeset
|
225 self.assertEqual("""<div> |
405
5340931530e2
Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents:
400
diff
changeset
|
226 2 days, 0:00:00 |
5340931530e2
Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents:
400
diff
changeset
|
227 </div>""", str(tmpl.generate())) |
5340931530e2
Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents:
400
diff
changeset
|
228 |
5340931530e2
Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents:
400
diff
changeset
|
229 def test_exec_def(self): |
854
4d9bef447df9
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
825
diff
changeset
|
230 tmpl = MarkupTemplate(""" |
405
5340931530e2
Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents:
400
diff
changeset
|
231 <?python |
5340931530e2
Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents:
400
diff
changeset
|
232 def foo(): |
5340931530e2
Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents:
400
diff
changeset
|
233 return 42 |
5340931530e2
Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents:
400
diff
changeset
|
234 ?> |
5340931530e2
Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents:
400
diff
changeset
|
235 <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
|
236 ${foo()} |
5340931530e2
Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents:
400
diff
changeset
|
237 </div>""") |
854
4d9bef447df9
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
825
diff
changeset
|
238 self.assertEqual("""<div> |
405
5340931530e2
Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents:
400
diff
changeset
|
239 42 |
5340931530e2
Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents:
400
diff
changeset
|
240 </div>""", str(tmpl.generate())) |
5340931530e2
Support for Python code blocks using the `<?python ?>` processing instruction. Closes #84.
cmlenz
parents:
400
diff
changeset
|
241 |
437 | 242 def test_namespace_on_removed_elem(self): |
243 """ | |
244 Verify that a namespace declaration on an element that is removed from | |
245 the generated stream does not get pushed up to the next non-stripped | |
246 element (see ticket #107). | |
247 """ | |
248 tmpl = MarkupTemplate("""<?xml version="1.0"?> | |
249 <Test xmlns:py="http://genshi.edgewall.org/"> | |
250 <Size py:if="0" xmlns:t="test">Size</Size> | |
251 <Item/> | |
252 </Test>""") | |
460
75425671b437
Apply patch by Alec Thomas for processing XML declarations (#111). Thanks!
cmlenz
parents:
437
diff
changeset
|
253 self.assertEqual("""<?xml version="1.0"?>\n<Test> |
437 | 254 |
255 <Item/> | |
256 </Test>""", str(tmpl.generate())) | |
257 | |
363
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
258 def test_include_in_loop(self): |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
259 dirname = tempfile.mkdtemp(suffix='genshi_test') |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
260 try: |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
261 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
|
262 try: |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
263 file1.write("""<div>Included $idx</div>""") |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
264 finally: |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
265 file1.close() |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
266 |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
267 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
|
268 try: |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
269 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
|
270 xmlns:py="http://genshi.edgewall.org/"> |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
271 <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
|
272 </html>""") |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
273 finally: |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
274 file2.close() |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
275 |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
276 loader = TemplateLoader([dirname]) |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
277 tmpl = loader.load('tmpl2.html') |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
278 self.assertEqual("""<html> |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
279 <div>Included 0</div><div>Included 1</div><div>Included 2</div> |
865 | 280 </html>""", tmpl.generate(name='tmpl1').render(encoding=None)) |
363
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
281 finally: |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
282 shutil.rmtree(dirname) |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
283 |
656
f3bc1de7138d
Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents:
650
diff
changeset
|
284 def test_dynamic_include_href(self): |
363
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
285 dirname = tempfile.mkdtemp(suffix='genshi_test') |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
286 try: |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
287 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
|
288 try: |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
289 file1.write("""<div>Included</div>""") |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
290 finally: |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
291 file1.close() |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
292 |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
293 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
|
294 try: |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
295 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
|
296 xmlns:py="http://genshi.edgewall.org/"> |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
297 <xi:include href="${name}.html" /> |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
298 </html>""") |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
299 finally: |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
300 file2.close() |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
301 |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
302 loader = TemplateLoader([dirname]) |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
303 tmpl = loader.load('tmpl2.html') |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
304 self.assertEqual("""<html> |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
305 <div>Included</div> |
865 | 306 </html>""", tmpl.generate(name='tmpl1').render(encoding=None)) |
363
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
307 finally: |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
308 shutil.rmtree(dirname) |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
309 |
656
f3bc1de7138d
Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents:
650
diff
changeset
|
310 def test_select_included_elements(self): |
363
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
311 dirname = tempfile.mkdtemp(suffix='genshi_test') |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
312 try: |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
313 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
|
314 try: |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
315 file1.write("""<li>$item</li>""") |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
316 finally: |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
317 file1.close() |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
318 |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
319 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
|
320 try: |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
321 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
|
322 xmlns:py="http://genshi.edgewall.org/"> |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
323 <ul py:match="ul">${select('li')}</ul> |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
324 <ul py:with="items=(1, 2, 3)"> |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
325 <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
|
326 </ul> |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
327 </html>""") |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
328 finally: |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
329 file2.close() |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
330 |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
331 loader = TemplateLoader([dirname]) |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
332 tmpl = loader.load('tmpl2.html') |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
333 self.assertEqual("""<html> |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
334 <ul><li>1</li><li>2</li><li>3</li></ul> |
865 | 335 </html>""", tmpl.generate().render(encoding=None)) |
363
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
336 finally: |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
337 shutil.rmtree(dirname) |
37e4b4bb0b53
Parse template includes at parse time to avoid some runtime overhead.
cmlenz
parents:
336
diff
changeset
|
338 |
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
|
339 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
|
340 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
|
341 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
|
342 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
|
343 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
|
344 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
|
345 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
|
346 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
|
347 |
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 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
|
349 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
|
350 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
|
351 <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
|
352 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
|
353 </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
|
354 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
|
355 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
|
356 |
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 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
|
358 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
|
359 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
|
360 <div>Included</div> |
865 | 361 </html>""", tmpl.generate().render(encoding=None)) |
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
|
362 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
|
363 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
|
364 |
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
|
365 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
|
366 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
|
367 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
|
368 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
|
369 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
|
370 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
|
371 <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
|
372 </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
|
373 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
|
374 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
|
375 |
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 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
|
377 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
|
378 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
|
379 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
|
380 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
|
381 |
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
|
382 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
|
383 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
|
384 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
|
385 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
|
386 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
|
387 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
|
388 <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
|
389 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
|
390 </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
|
391 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
|
392 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
|
393 |
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 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
|
395 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
|
396 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
|
397 Missing |
865 | 398 </html>""", tmpl.generate().render(encoding=None)) |
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
|
399 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
|
400 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
|
401 |
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
|
402 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
|
403 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
|
404 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
|
405 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
|
406 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
|
407 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
|
408 <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
|
409 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
|
410 </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
|
411 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
|
412 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
|
413 |
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 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
|
415 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
|
416 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
|
417 Missing |
865 | 418 </html>""", tmpl.generate().render(encoding=None)) |
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
|
419 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
|
420 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
|
421 |
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
|
422 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
|
423 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
|
424 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
|
425 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
|
426 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
|
427 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
|
428 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
|
429 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
|
430 |
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 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
|
432 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
|
433 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
|
434 <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
|
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 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
|
437 <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
|
438 </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
|
439 </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
|
440 </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
|
441 </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
|
442 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
|
443 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
|
444 |
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 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
|
446 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
|
447 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
|
448 <div>Included</div> |
865 | 449 </html>""", tmpl.generate().render(encoding=None)) |
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
|
450 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
|
451 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
|
452 |
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 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
|
454 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
|
455 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
|
456 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
|
457 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
|
458 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
|
459 <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
|
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 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
|
462 <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
|
463 </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
|
464 </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
|
465 </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
|
466 </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
|
467 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
|
468 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
|
469 |
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
|
470 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
|
471 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
|
472 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
|
473 Missing |
865 | 474 </html>""", tmpl.generate().render(encoding=None)) |
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
|
475 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
|
476 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
|
477 |
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 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
|
479 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
|
480 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
|
481 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
|
482 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
|
483 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
|
484 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
|
485 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
|
486 |
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 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
|
488 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
|
489 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
|
490 <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
|
491 <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
|
492 <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
|
493 </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
|
494 </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
|
495 </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
|
496 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
|
497 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
|
498 |
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
|
499 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
|
500 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
|
501 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
|
502 <div>Included</div> |
865 | 503 </html>""", tmpl.generate().render(encoding=None)) |
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
|
504 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
|
505 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
|
506 |
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 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
|
508 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
|
509 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
|
510 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
|
511 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
|
512 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
|
513 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
|
514 <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
|
515 <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
|
516 </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
|
517 </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
|
518 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
|
519 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
|
520 |
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 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
|
522 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
|
523 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
|
524 tmpl1.html not found |
865 | 525 </html>""", tmpl.generate(debug=True).render(encoding=None)) |
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
|
526 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
|
527 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
|
528 |
548
1cc1afc39176
Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents:
546
diff
changeset
|
529 def test_include_inlined(self): |
1cc1afc39176
Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents:
546
diff
changeset
|
530 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
|
531 try: |
1cc1afc39176
Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents:
546
diff
changeset
|
532 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
|
533 try: |
1cc1afc39176
Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents:
546
diff
changeset
|
534 file1.write("""<div>Included</div>""") |
1cc1afc39176
Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents:
546
diff
changeset
|
535 finally: |
1cc1afc39176
Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents:
546
diff
changeset
|
536 file1.close() |
1cc1afc39176
Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents:
546
diff
changeset
|
537 |
1cc1afc39176
Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents:
546
diff
changeset
|
538 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
|
539 try: |
1cc1afc39176
Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents:
546
diff
changeset
|
540 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
|
541 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
|
542 <xi:include href="tmpl1.html" /> |
1cc1afc39176
Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents:
546
diff
changeset
|
543 </html>""") |
1cc1afc39176
Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents:
546
diff
changeset
|
544 finally: |
1cc1afc39176
Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents:
546
diff
changeset
|
545 file2.close() |
1cc1afc39176
Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents:
546
diff
changeset
|
546 |
1cc1afc39176
Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents:
546
diff
changeset
|
547 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
|
548 tmpl = loader.load('tmpl2.html') |
1cc1afc39176
Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents:
546
diff
changeset
|
549 # 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
|
550 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
|
551 self.assertEqual("""<html> |
1cc1afc39176
Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents:
546
diff
changeset
|
552 <div>Included</div> |
865 | 553 </html>""", tmpl.generate().render(encoding=None)) |
548
1cc1afc39176
Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents:
546
diff
changeset
|
554 finally: |
1cc1afc39176
Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents:
546
diff
changeset
|
555 shutil.rmtree(dirname) |
1cc1afc39176
Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents:
546
diff
changeset
|
556 |
1cc1afc39176
Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents:
546
diff
changeset
|
557 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
|
558 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
|
559 try: |
1cc1afc39176
Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents:
546
diff
changeset
|
560 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
|
561 try: |
1cc1afc39176
Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents:
546
diff
changeset
|
562 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
|
563 finally: |
1cc1afc39176
Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents:
546
diff
changeset
|
564 file1.close() |
1cc1afc39176
Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents:
546
diff
changeset
|
565 |
1cc1afc39176
Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents:
546
diff
changeset
|
566 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
|
567 try: |
1cc1afc39176
Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents:
546
diff
changeset
|
568 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
|
569 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
|
570 <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
|
571 </html>""") |
1cc1afc39176
Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents:
546
diff
changeset
|
572 finally: |
1cc1afc39176
Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents:
546
diff
changeset
|
573 file2.close() |
1cc1afc39176
Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents:
546
diff
changeset
|
574 |
1cc1afc39176
Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents:
546
diff
changeset
|
575 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
|
576 tmpl = loader.load('tmpl2.html') |
1cc1afc39176
Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents:
546
diff
changeset
|
577 self.assertEqual("""<html> |
1cc1afc39176
Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents:
546
diff
changeset
|
578 <div>Included 0</div><div>Included 1</div><div>Included 2</div> |
865 | 579 </html>""", tmpl.generate().render(encoding=None)) |
548
1cc1afc39176
Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents:
546
diff
changeset
|
580 finally: |
1cc1afc39176
Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents:
546
diff
changeset
|
581 shutil.rmtree(dirname) |
1cc1afc39176
Implement static includes, which improves performance a bit when auto reloading is disabled.
cmlenz
parents:
546
diff
changeset
|
582 |
1033
348ba73df25c
Merge r1257 from trunk (fix for infinite template inlining).
hodgestar
parents:
927
diff
changeset
|
583 def test_include_inline_recursive(self): |
348ba73df25c
Merge r1257 from trunk (fix for infinite template inlining).
hodgestar
parents:
927
diff
changeset
|
584 dirname = tempfile.mkdtemp(suffix='genshi_test') |
348ba73df25c
Merge r1257 from trunk (fix for infinite template inlining).
hodgestar
parents:
927
diff
changeset
|
585 try: |
348ba73df25c
Merge r1257 from trunk (fix for infinite template inlining).
hodgestar
parents:
927
diff
changeset
|
586 file1 = open(os.path.join(dirname, 'tmpl1.html'), 'w') |
348ba73df25c
Merge r1257 from trunk (fix for infinite template inlining).
hodgestar
parents:
927
diff
changeset
|
587 try: |
348ba73df25c
Merge r1257 from trunk (fix for infinite template inlining).
hodgestar
parents:
927
diff
changeset
|
588 file1.write( |
348ba73df25c
Merge r1257 from trunk (fix for infinite template inlining).
hodgestar
parents:
927
diff
changeset
|
589 '<div xmlns:xi="http://www.w3.org/2001/XInclude"' |
348ba73df25c
Merge r1257 from trunk (fix for infinite template inlining).
hodgestar
parents:
927
diff
changeset
|
590 ' xmlns:py="http://genshi.edgewall.org/">' |
348ba73df25c
Merge r1257 from trunk (fix for infinite template inlining).
hodgestar
parents:
927
diff
changeset
|
591 '$depth' |
348ba73df25c
Merge r1257 from trunk (fix for infinite template inlining).
hodgestar
parents:
927
diff
changeset
|
592 '<py:with vars="depth = depth + 1">' |
348ba73df25c
Merge r1257 from trunk (fix for infinite template inlining).
hodgestar
parents:
927
diff
changeset
|
593 '<xi:include href="tmpl1.html"' |
348ba73df25c
Merge r1257 from trunk (fix for infinite template inlining).
hodgestar
parents:
927
diff
changeset
|
594 ' py:if="depth < 3"/>' |
348ba73df25c
Merge r1257 from trunk (fix for infinite template inlining).
hodgestar
parents:
927
diff
changeset
|
595 '</py:with>' |
348ba73df25c
Merge r1257 from trunk (fix for infinite template inlining).
hodgestar
parents:
927
diff
changeset
|
596 '</div>' |
348ba73df25c
Merge r1257 from trunk (fix for infinite template inlining).
hodgestar
parents:
927
diff
changeset
|
597 ) |
348ba73df25c
Merge r1257 from trunk (fix for infinite template inlining).
hodgestar
parents:
927
diff
changeset
|
598 finally: |
348ba73df25c
Merge r1257 from trunk (fix for infinite template inlining).
hodgestar
parents:
927
diff
changeset
|
599 file1.close() |
348ba73df25c
Merge r1257 from trunk (fix for infinite template inlining).
hodgestar
parents:
927
diff
changeset
|
600 |
348ba73df25c
Merge r1257 from trunk (fix for infinite template inlining).
hodgestar
parents:
927
diff
changeset
|
601 loader = TemplateLoader([dirname], auto_reload=False) |
348ba73df25c
Merge r1257 from trunk (fix for infinite template inlining).
hodgestar
parents:
927
diff
changeset
|
602 tmpl = loader.load(os.path.join(dirname, 'tmpl1.html')) |
348ba73df25c
Merge r1257 from trunk (fix for infinite template inlining).
hodgestar
parents:
927
diff
changeset
|
603 self.assertEqual( |
348ba73df25c
Merge r1257 from trunk (fix for infinite template inlining).
hodgestar
parents:
927
diff
changeset
|
604 "<div>0<div>1<div>2</div></div></div>", |
348ba73df25c
Merge r1257 from trunk (fix for infinite template inlining).
hodgestar
parents:
927
diff
changeset
|
605 tmpl.generate(depth=0).render(encoding=None)) |
348ba73df25c
Merge r1257 from trunk (fix for infinite template inlining).
hodgestar
parents:
927
diff
changeset
|
606 finally: |
348ba73df25c
Merge r1257 from trunk (fix for infinite template inlining).
hodgestar
parents:
927
diff
changeset
|
607 shutil.rmtree(dirname) |
348ba73df25c
Merge r1257 from trunk (fix for infinite template inlining).
hodgestar
parents:
927
diff
changeset
|
608 |
348ba73df25c
Merge r1257 from trunk (fix for infinite template inlining).
hodgestar
parents:
927
diff
changeset
|
609 def test_allow_exec_false(self): |
545
619340e2d805
Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents:
520
diff
changeset
|
610 xml = ("""<?python |
619340e2d805
Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents:
520
diff
changeset
|
611 title = "A Genshi Template" |
619340e2d805
Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents:
520
diff
changeset
|
612 ?> |
619340e2d805
Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents:
520
diff
changeset
|
613 <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
|
614 <head> |
619340e2d805
Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents:
520
diff
changeset
|
615 <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
|
616 </head> |
619340e2d805
Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents:
520
diff
changeset
|
617 </html>""") |
619340e2d805
Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents:
520
diff
changeset
|
618 try: |
619340e2d805
Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents:
520
diff
changeset
|
619 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
|
620 allow_exec=False) |
619340e2d805
Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents:
520
diff
changeset
|
621 self.fail('Expected SyntaxError') |
619340e2d805
Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents:
520
diff
changeset
|
622 except TemplateSyntaxError, e: |
619340e2d805
Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents:
520
diff
changeset
|
623 pass |
619340e2d805
Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents:
520
diff
changeset
|
624 |
619340e2d805
Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents:
520
diff
changeset
|
625 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
|
626 xml = ("""<?python |
619340e2d805
Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents:
520
diff
changeset
|
627 title = "A Genshi Template" |
619340e2d805
Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents:
520
diff
changeset
|
628 ?> |
619340e2d805
Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents:
520
diff
changeset
|
629 <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
|
630 <head> |
619340e2d805
Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents:
520
diff
changeset
|
631 <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
|
632 </head> |
619340e2d805
Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents:
520
diff
changeset
|
633 </html>""") |
619340e2d805
Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents:
520
diff
changeset
|
634 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
|
635 |
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
|
636 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
|
637 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
|
638 <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
|
639 <?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
|
640 ${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
|
641 </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
|
642 <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
|
643 </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
|
644 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
|
645 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
|
646 <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
|
647 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
|
648 </body> |
865 | 649 </html>""", tmpl.generate().render(encoding=None)) |
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
|
650 |
700
08f22328303d
Add option for unbuffered match template processing, which could cause excessive memory usage. Closes #190.
cmlenz
parents:
656
diff
changeset
|
651 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
|
652 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
|
653 <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
|
654 <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
|
655 ${select('.')} |
08f22328303d
Add option for unbuffered match template processing, which could cause excessive memory usage. Closes #190.
cmlenz
parents:
656
diff
changeset
|
656 </py:match> |
08f22328303d
Add option for unbuffered match template processing, which could cause excessive memory usage. Closes #190.
cmlenz
parents:
656
diff
changeset
|
657 <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
|
658 </html>""") |
08f22328303d
Add option for unbuffered match template processing, which could cause excessive memory usage. Closes #190.
cmlenz
parents:
656
diff
changeset
|
659 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
|
660 self.assertEqual("""<html> |
08f22328303d
Add option for unbuffered match template processing, which could cause excessive memory usage. Closes #190.
cmlenz
parents:
656
diff
changeset
|
661 <body> |
08f22328303d
Add option for unbuffered match template processing, which could cause excessive memory usage. Closes #190.
cmlenz
parents:
656
diff
changeset
|
662 <h1>bar</h1> |
08f22328303d
Add option for unbuffered match template processing, which could cause excessive memory usage. Closes #190.
cmlenz
parents:
656
diff
changeset
|
663 <p>bar</p> |
08f22328303d
Add option for unbuffered match template processing, which could cause excessive memory usage. Closes #190.
cmlenz
parents:
656
diff
changeset
|
664 </body> |
865 | 665 </html>""", tmpl.generate().render(encoding=None)) |
700
08f22328303d
Add option for unbuffered match template processing, which could cause excessive memory usage. Closes #190.
cmlenz
parents:
656
diff
changeset
|
666 |
656
f3bc1de7138d
Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents:
650
diff
changeset
|
667 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
|
668 # See ticket #157 |
f3bc1de7138d
Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents:
650
diff
changeset
|
669 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
|
670 try: |
f3bc1de7138d
Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents:
650
diff
changeset
|
671 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
|
672 try: |
f3bc1de7138d
Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents:
650
diff
changeset
|
673 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
|
674 <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
|
675 </html>""") |
f3bc1de7138d
Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents:
650
diff
changeset
|
676 finally: |
f3bc1de7138d
Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents:
650
diff
changeset
|
677 file1.close() |
f3bc1de7138d
Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents:
650
diff
changeset
|
678 |
f3bc1de7138d
Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents:
650
diff
changeset
|
679 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
|
680 try: |
f3bc1de7138d
Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents:
650
diff
changeset
|
681 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
|
682 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
|
683 <body> |
f3bc1de7138d
Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents:
650
diff
changeset
|
684 <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
|
685 <xi:include href="tmpl1.html" /> |
f3bc1de7138d
Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents:
650
diff
changeset
|
686 </body> |
f3bc1de7138d
Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents:
650
diff
changeset
|
687 </html>""") |
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 file2.close() |
f3bc1de7138d
Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents:
650
diff
changeset
|
690 |
f3bc1de7138d
Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents:
650
diff
changeset
|
691 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
|
692 try: |
f3bc1de7138d
Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents:
650
diff
changeset
|
693 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
|
694 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
|
695 <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
|
696 Some added stuff. |
f3bc1de7138d
Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents:
650
diff
changeset
|
697 ${select('*|text()')} |
f3bc1de7138d
Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents:
650
diff
changeset
|
698 </div> |
f3bc1de7138d
Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents:
650
diff
changeset
|
699 <xi:include href="tmpl2.html" /> |
f3bc1de7138d
Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents:
650
diff
changeset
|
700 </html> |
f3bc1de7138d
Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents:
650
diff
changeset
|
701 """) |
f3bc1de7138d
Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents:
650
diff
changeset
|
702 finally: |
f3bc1de7138d
Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents:
650
diff
changeset
|
703 file3.close() |
f3bc1de7138d
Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents:
650
diff
changeset
|
704 |
f3bc1de7138d
Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents:
650
diff
changeset
|
705 loader = TemplateLoader([dirname]) |
f3bc1de7138d
Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents:
650
diff
changeset
|
706 tmpl = loader.load('tmpl3.html') |
f3bc1de7138d
Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents:
650
diff
changeset
|
707 self.assertEqual(""" |
f3bc1de7138d
Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents:
650
diff
changeset
|
708 <html> |
f3bc1de7138d
Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents:
650
diff
changeset
|
709 <body> |
f3bc1de7138d
Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents:
650
diff
changeset
|
710 <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
|
711 <div class="target"> |
f3bc1de7138d
Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents:
650
diff
changeset
|
712 Some added stuff. |
f3bc1de7138d
Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents:
650
diff
changeset
|
713 Some content. |
f3bc1de7138d
Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents:
650
diff
changeset
|
714 </div> |
f3bc1de7138d
Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents:
650
diff
changeset
|
715 </body> |
f3bc1de7138d
Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents:
650
diff
changeset
|
716 </html> |
865 | 717 """, tmpl.generate().render(encoding=None)) |
656
f3bc1de7138d
Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents:
650
diff
changeset
|
718 finally: |
f3bc1de7138d
Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents:
650
diff
changeset
|
719 shutil.rmtree(dirname) |
f3bc1de7138d
Add unit test for #157, which seems to be working okay in trunk.
cmlenz
parents:
650
diff
changeset
|
720 |
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
|
721 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
|
722 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
|
723 <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
|
724 <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
|
725 ${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
|
726 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
|
727 </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
|
728 </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
|
729 <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
|
730 <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
|
731 <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
|
732 </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
|
733 </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
|
734 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
|
735 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
|
736 <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
|
737 <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
|
738 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
|
739 </body> |
865 | 740 </html>""", tmpl.generate().render(encoding=None)) |
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
|
741 |
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
|
742 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
|
743 # 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
|
744 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
|
745 <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
|
746 <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
|
747 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
|
748 </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
|
749 </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
|
750 <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
|
751 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
|
752 </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
|
753 </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
|
754 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
|
755 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
|
756 <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
|
757 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
|
758 </body> |
865 | 759 </html>""", tmpl.generate().render(encoding=None)) |
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
|
760 |
927
832bdab41eee
Merge r1149 from trunk (fix for tail selecting issue #399).
hodgestar
parents:
865
diff
changeset
|
761 def test_match_tail_handling(self): |
832bdab41eee
Merge r1149 from trunk (fix for tail selecting issue #399).
hodgestar
parents:
865
diff
changeset
|
762 # See <http://genshi.edgewall.org/ticket/399> |
832bdab41eee
Merge r1149 from trunk (fix for tail selecting issue #399).
hodgestar
parents:
865
diff
changeset
|
763 xml = ("""<rhyme xmlns:py="http://genshi.edgewall.org/"> |
832bdab41eee
Merge r1149 from trunk (fix for tail selecting issue #399).
hodgestar
parents:
865
diff
changeset
|
764 <py:match path="*[@type]"> |
832bdab41eee
Merge r1149 from trunk (fix for tail selecting issue #399).
hodgestar
parents:
865
diff
changeset
|
765 ${select('.')} |
832bdab41eee
Merge r1149 from trunk (fix for tail selecting issue #399).
hodgestar
parents:
865
diff
changeset
|
766 </py:match> |
832bdab41eee
Merge r1149 from trunk (fix for tail selecting issue #399).
hodgestar
parents:
865
diff
changeset
|
767 |
832bdab41eee
Merge r1149 from trunk (fix for tail selecting issue #399).
hodgestar
parents:
865
diff
changeset
|
768 <lines> |
832bdab41eee
Merge r1149 from trunk (fix for tail selecting issue #399).
hodgestar
parents:
865
diff
changeset
|
769 <first type="one">fish</first> |
832bdab41eee
Merge r1149 from trunk (fix for tail selecting issue #399).
hodgestar
parents:
865
diff
changeset
|
770 <second type="two">fish</second> |
832bdab41eee
Merge r1149 from trunk (fix for tail selecting issue #399).
hodgestar
parents:
865
diff
changeset
|
771 <third type="red">fish</third> |
832bdab41eee
Merge r1149 from trunk (fix for tail selecting issue #399).
hodgestar
parents:
865
diff
changeset
|
772 <fourth type="blue">fish</fourth> |
832bdab41eee
Merge r1149 from trunk (fix for tail selecting issue #399).
hodgestar
parents:
865
diff
changeset
|
773 </lines> |
832bdab41eee
Merge r1149 from trunk (fix for tail selecting issue #399).
hodgestar
parents:
865
diff
changeset
|
774 </rhyme>""") |
832bdab41eee
Merge r1149 from trunk (fix for tail selecting issue #399).
hodgestar
parents:
865
diff
changeset
|
775 tmpl = MarkupTemplate(xml, filename='test.html') |
832bdab41eee
Merge r1149 from trunk (fix for tail selecting issue #399).
hodgestar
parents:
865
diff
changeset
|
776 self.assertEqual("""<rhyme> |
832bdab41eee
Merge r1149 from trunk (fix for tail selecting issue #399).
hodgestar
parents:
865
diff
changeset
|
777 <lines> |
832bdab41eee
Merge r1149 from trunk (fix for tail selecting issue #399).
hodgestar
parents:
865
diff
changeset
|
778 <first type="one">fish</first> |
832bdab41eee
Merge r1149 from trunk (fix for tail selecting issue #399).
hodgestar
parents:
865
diff
changeset
|
779 <second type="two">fish</second> |
832bdab41eee
Merge r1149 from trunk (fix for tail selecting issue #399).
hodgestar
parents:
865
diff
changeset
|
780 <third type="red">fish</third> |
832bdab41eee
Merge r1149 from trunk (fix for tail selecting issue #399).
hodgestar
parents:
865
diff
changeset
|
781 <fourth type="blue">fish</fourth> |
832bdab41eee
Merge r1149 from trunk (fix for tail selecting issue #399).
hodgestar
parents:
865
diff
changeset
|
782 </lines> |
832bdab41eee
Merge r1149 from trunk (fix for tail selecting issue #399).
hodgestar
parents:
865
diff
changeset
|
783 </rhyme>""", tmpl.generate().render(encoding=None)) |
832bdab41eee
Merge r1149 from trunk (fix for tail selecting issue #399).
hodgestar
parents:
865
diff
changeset
|
784 |
546 | 785 |
336
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
786 def suite(): |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
787 suite = unittest.TestSuite() |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
788 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
|
789 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
|
790 return suite |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
791 |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
792 if __name__ == '__main__': |
7763f7aec949
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
793 unittest.main(defaultTest='suite') |