Mercurial > genshi > genshi-test
annotate markup/tests/template.py @ 202:4140bff0d7d2
Remove the (hopefully) last instance where directives store state in instance variables, allowing templates to be cached and reused in a threadsafe manner. Closes #39. Many thanks to Christian Boos for the patch!
author | cmlenz |
---|---|
date | Fri, 25 Aug 2006 12:43:01 +0000 |
parents | 929ef2913b87 |
children | d122ff386411 |
rev | line source |
---|---|
1 | 1 # -*- coding: utf-8 -*- |
2 # | |
66
822089ae65ce
Switch copyright to Edgewall and URLs to markup.edgewall.org.
cmlenz
parents:
65
diff
changeset
|
3 # Copyright (C) 2006 Edgewall Software |
1 | 4 # All rights reserved. |
5 # | |
6 # This software is licensed as described in the file COPYING, which | |
7 # you should have received as part of this distribution. The terms | |
66
822089ae65ce
Switch copyright to Edgewall and URLs to markup.edgewall.org.
cmlenz
parents:
65
diff
changeset
|
8 # are also available at http://markup.edgewall.org/wiki/License. |
1 | 9 # |
10 # This software consists of voluntary contributions made by many | |
11 # individuals. For the exact contribution history, see the revision | |
66
822089ae65ce
Switch copyright to Edgewall and URLs to markup.edgewall.org.
cmlenz
parents:
65
diff
changeset
|
12 # history and logs, available at http://markup.edgewall.org/log/. |
1 | 13 |
14 import doctest | |
152
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
15 import os |
1 | 16 import unittest |
152
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
17 import shutil |
1 | 18 import sys |
152
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
19 import tempfile |
1 | 20 |
54 | 21 from markup.core import Markup, Stream |
152
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
22 from markup.template import BadDirectiveError, Template, TemplateLoader, \ |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
23 TemplateSyntaxError |
1 | 24 |
25 | |
50
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
26 class AttrsDirectiveTestCase(unittest.TestCase): |
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
27 """Tests for the `py:attrs` template directive.""" |
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
28 |
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
29 def test_combined_with_loop(self): |
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
30 """ |
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
31 Verify that the directive has access to the loop variables. |
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
32 """ |
61 | 33 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/"> |
50
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
34 <elem py:for="item in items" py:attrs="item"/> |
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
35 </doc>""") |
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
36 items = [{'id': 1, 'class': 'foo'}, {'id': 2, 'class': 'bar'}] |
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
37 self.assertEqual("""<doc> |
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
38 <elem id="1" class="foo"/><elem id="2" class="bar"/> |
149
7306bf730ff3
`Template.generate()` now accepts the context data as keyword arguments, so that you don't have to import the `Context` class every time you want to pass data into a template.
cmlenz
parents:
145
diff
changeset
|
39 </doc>""", str(tmpl.generate(items=items))) |
50
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
40 |
54 | 41 def test_update_existing_attr(self): |
42 """ | |
43 Verify that an attribute value that evaluates to `None` removes an | |
44 existing attribute of that name. | |
45 """ | |
61 | 46 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/"> |
54 | 47 <elem class="foo" py:attrs="{'class': 'bar'}"/> |
48 </doc>""") | |
49 self.assertEqual("""<doc> | |
50 <elem class="bar"/> | |
51 </doc>""", str(tmpl.generate())) | |
52 | |
53 def test_remove_existing_attr(self): | |
54 """ | |
55 Verify that an attribute value that evaluates to `None` removes an | |
56 existing attribute of that name. | |
57 """ | |
61 | 58 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/"> |
54 | 59 <elem class="foo" py:attrs="{'class': None}"/> |
60 </doc>""") | |
61 self.assertEqual("""<doc> | |
62 <elem/> | |
63 </doc>""", str(tmpl.generate())) | |
64 | |
50
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
65 |
53
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
66 class ChooseDirectiveTestCase(unittest.TestCase): |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
67 """Tests for the `py:choose` template directive and the complementary |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
68 directives `py:when` and `py:otherwise`.""" |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
69 |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
70 def test_multiple_true_whens(self): |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
71 """ |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
72 Verify that, if multiple `py:when` bodies match, only the first is |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
73 output. |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
74 """ |
61 | 75 tmpl = Template("""<div xmlns:py="http://markup.edgewall.org/" py:choose=""> |
53
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
76 <span py:when="1 == 1">1</span> |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
77 <span py:when="2 == 2">2</span> |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
78 <span py:when="3 == 3">3</span> |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
79 </div>""") |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
80 self.assertEqual("""<div> |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
81 <span>1</span> |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
82 </div>""", str(tmpl.generate())) |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
83 |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
84 def test_otherwise(self): |
61 | 85 tmpl = Template("""<div xmlns:py="http://markup.edgewall.org/" py:choose=""> |
53
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
86 <span py:when="False">hidden</span> |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
87 <span py:otherwise="">hello</span> |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
88 </div>""") |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
89 self.assertEqual("""<div> |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
90 <span>hello</span> |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
91 </div>""", str(tmpl.generate())) |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
92 |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
93 def test_nesting(self): |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
94 """ |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
95 Verify that `py:choose` blocks can be nested: |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
96 """ |
61 | 97 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/"> |
53
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
98 <div py:choose="1"> |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
99 <div py:when="1" py:choose="3"> |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
100 <span py:when="2">2</span> |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
101 <span py:when="3">3</span> |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
102 </div> |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
103 </div> |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
104 </doc>""") |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
105 self.assertEqual("""<doc> |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
106 <div> |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
107 <div> |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
108 <span>3</span> |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
109 </div> |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
110 </div> |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
111 </doc>""", str(tmpl.generate())) |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
112 |
202
4140bff0d7d2
Remove the (hopefully) last instance where directives store state in instance variables, allowing templates to be cached and reused in a threadsafe manner. Closes #39. Many thanks to Christian Boos for the patch!
cmlenz
parents:
191
diff
changeset
|
113 def test_complex_nesting(self): |
4140bff0d7d2
Remove the (hopefully) last instance where directives store state in instance variables, allowing templates to be cached and reused in a threadsafe manner. Closes #39. Many thanks to Christian Boos for the patch!
cmlenz
parents:
191
diff
changeset
|
114 """ |
4140bff0d7d2
Remove the (hopefully) last instance where directives store state in instance variables, allowing templates to be cached and reused in a threadsafe manner. Closes #39. Many thanks to Christian Boos for the patch!
cmlenz
parents:
191
diff
changeset
|
115 Verify more complex nesting. |
4140bff0d7d2
Remove the (hopefully) last instance where directives store state in instance variables, allowing templates to be cached and reused in a threadsafe manner. Closes #39. Many thanks to Christian Boos for the patch!
cmlenz
parents:
191
diff
changeset
|
116 """ |
4140bff0d7d2
Remove the (hopefully) last instance where directives store state in instance variables, allowing templates to be cached and reused in a threadsafe manner. Closes #39. Many thanks to Christian Boos for the patch!
cmlenz
parents:
191
diff
changeset
|
117 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/"> |
4140bff0d7d2
Remove the (hopefully) last instance where directives store state in instance variables, allowing templates to be cached and reused in a threadsafe manner. Closes #39. Many thanks to Christian Boos for the patch!
cmlenz
parents:
191
diff
changeset
|
118 <div py:choose="1"> |
4140bff0d7d2
Remove the (hopefully) last instance where directives store state in instance variables, allowing templates to be cached and reused in a threadsafe manner. Closes #39. Many thanks to Christian Boos for the patch!
cmlenz
parents:
191
diff
changeset
|
119 <div py:when="1" py:choose=""> |
4140bff0d7d2
Remove the (hopefully) last instance where directives store state in instance variables, allowing templates to be cached and reused in a threadsafe manner. Closes #39. Many thanks to Christian Boos for the patch!
cmlenz
parents:
191
diff
changeset
|
120 <span py:when="2">OK</span> |
4140bff0d7d2
Remove the (hopefully) last instance where directives store state in instance variables, allowing templates to be cached and reused in a threadsafe manner. Closes #39. Many thanks to Christian Boos for the patch!
cmlenz
parents:
191
diff
changeset
|
121 <span py:when="1">FAIL</span> |
4140bff0d7d2
Remove the (hopefully) last instance where directives store state in instance variables, allowing templates to be cached and reused in a threadsafe manner. Closes #39. Many thanks to Christian Boos for the patch!
cmlenz
parents:
191
diff
changeset
|
122 </div> |
4140bff0d7d2
Remove the (hopefully) last instance where directives store state in instance variables, allowing templates to be cached and reused in a threadsafe manner. Closes #39. Many thanks to Christian Boos for the patch!
cmlenz
parents:
191
diff
changeset
|
123 </div> |
4140bff0d7d2
Remove the (hopefully) last instance where directives store state in instance variables, allowing templates to be cached and reused in a threadsafe manner. Closes #39. Many thanks to Christian Boos for the patch!
cmlenz
parents:
191
diff
changeset
|
124 </doc>""") |
4140bff0d7d2
Remove the (hopefully) last instance where directives store state in instance variables, allowing templates to be cached and reused in a threadsafe manner. Closes #39. Many thanks to Christian Boos for the patch!
cmlenz
parents:
191
diff
changeset
|
125 self.assertEqual("""<doc> |
4140bff0d7d2
Remove the (hopefully) last instance where directives store state in instance variables, allowing templates to be cached and reused in a threadsafe manner. Closes #39. Many thanks to Christian Boos for the patch!
cmlenz
parents:
191
diff
changeset
|
126 <div> |
4140bff0d7d2
Remove the (hopefully) last instance where directives store state in instance variables, allowing templates to be cached and reused in a threadsafe manner. Closes #39. Many thanks to Christian Boos for the patch!
cmlenz
parents:
191
diff
changeset
|
127 <div> |
4140bff0d7d2
Remove the (hopefully) last instance where directives store state in instance variables, allowing templates to be cached and reused in a threadsafe manner. Closes #39. Many thanks to Christian Boos for the patch!
cmlenz
parents:
191
diff
changeset
|
128 <span>OK</span> |
4140bff0d7d2
Remove the (hopefully) last instance where directives store state in instance variables, allowing templates to be cached and reused in a threadsafe manner. Closes #39. Many thanks to Christian Boos for the patch!
cmlenz
parents:
191
diff
changeset
|
129 </div> |
4140bff0d7d2
Remove the (hopefully) last instance where directives store state in instance variables, allowing templates to be cached and reused in a threadsafe manner. Closes #39. Many thanks to Christian Boos for the patch!
cmlenz
parents:
191
diff
changeset
|
130 </div> |
4140bff0d7d2
Remove the (hopefully) last instance where directives store state in instance variables, allowing templates to be cached and reused in a threadsafe manner. Closes #39. Many thanks to Christian Boos for the patch!
cmlenz
parents:
191
diff
changeset
|
131 </doc>""", str(tmpl.generate())) |
4140bff0d7d2
Remove the (hopefully) last instance where directives store state in instance variables, allowing templates to be cached and reused in a threadsafe manner. Closes #39. Many thanks to Christian Boos for the patch!
cmlenz
parents:
191
diff
changeset
|
132 |
4140bff0d7d2
Remove the (hopefully) last instance where directives store state in instance variables, allowing templates to be cached and reused in a threadsafe manner. Closes #39. Many thanks to Christian Boos for the patch!
cmlenz
parents:
191
diff
changeset
|
133 def test_complex_nesting_otherwise(self): |
4140bff0d7d2
Remove the (hopefully) last instance where directives store state in instance variables, allowing templates to be cached and reused in a threadsafe manner. Closes #39. Many thanks to Christian Boos for the patch!
cmlenz
parents:
191
diff
changeset
|
134 """ |
4140bff0d7d2
Remove the (hopefully) last instance where directives store state in instance variables, allowing templates to be cached and reused in a threadsafe manner. Closes #39. Many thanks to Christian Boos for the patch!
cmlenz
parents:
191
diff
changeset
|
135 Verify more complex nesting using otherwise. |
4140bff0d7d2
Remove the (hopefully) last instance where directives store state in instance variables, allowing templates to be cached and reused in a threadsafe manner. Closes #39. Many thanks to Christian Boos for the patch!
cmlenz
parents:
191
diff
changeset
|
136 """ |
4140bff0d7d2
Remove the (hopefully) last instance where directives store state in instance variables, allowing templates to be cached and reused in a threadsafe manner. Closes #39. Many thanks to Christian Boos for the patch!
cmlenz
parents:
191
diff
changeset
|
137 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/"> |
4140bff0d7d2
Remove the (hopefully) last instance where directives store state in instance variables, allowing templates to be cached and reused in a threadsafe manner. Closes #39. Many thanks to Christian Boos for the patch!
cmlenz
parents:
191
diff
changeset
|
138 <div py:choose="1"> |
4140bff0d7d2
Remove the (hopefully) last instance where directives store state in instance variables, allowing templates to be cached and reused in a threadsafe manner. Closes #39. Many thanks to Christian Boos for the patch!
cmlenz
parents:
191
diff
changeset
|
139 <div py:when="1" py:choose="2"> |
4140bff0d7d2
Remove the (hopefully) last instance where directives store state in instance variables, allowing templates to be cached and reused in a threadsafe manner. Closes #39. Many thanks to Christian Boos for the patch!
cmlenz
parents:
191
diff
changeset
|
140 <span py:when="1">FAIL</span> |
4140bff0d7d2
Remove the (hopefully) last instance where directives store state in instance variables, allowing templates to be cached and reused in a threadsafe manner. Closes #39. Many thanks to Christian Boos for the patch!
cmlenz
parents:
191
diff
changeset
|
141 <span py:otherwise="">OK</span> |
4140bff0d7d2
Remove the (hopefully) last instance where directives store state in instance variables, allowing templates to be cached and reused in a threadsafe manner. Closes #39. Many thanks to Christian Boos for the patch!
cmlenz
parents:
191
diff
changeset
|
142 </div> |
4140bff0d7d2
Remove the (hopefully) last instance where directives store state in instance variables, allowing templates to be cached and reused in a threadsafe manner. Closes #39. Many thanks to Christian Boos for the patch!
cmlenz
parents:
191
diff
changeset
|
143 </div> |
4140bff0d7d2
Remove the (hopefully) last instance where directives store state in instance variables, allowing templates to be cached and reused in a threadsafe manner. Closes #39. Many thanks to Christian Boos for the patch!
cmlenz
parents:
191
diff
changeset
|
144 </doc>""") |
4140bff0d7d2
Remove the (hopefully) last instance where directives store state in instance variables, allowing templates to be cached and reused in a threadsafe manner. Closes #39. Many thanks to Christian Boos for the patch!
cmlenz
parents:
191
diff
changeset
|
145 self.assertEqual("""<doc> |
4140bff0d7d2
Remove the (hopefully) last instance where directives store state in instance variables, allowing templates to be cached and reused in a threadsafe manner. Closes #39. Many thanks to Christian Boos for the patch!
cmlenz
parents:
191
diff
changeset
|
146 <div> |
4140bff0d7d2
Remove the (hopefully) last instance where directives store state in instance variables, allowing templates to be cached and reused in a threadsafe manner. Closes #39. Many thanks to Christian Boos for the patch!
cmlenz
parents:
191
diff
changeset
|
147 <div> |
4140bff0d7d2
Remove the (hopefully) last instance where directives store state in instance variables, allowing templates to be cached and reused in a threadsafe manner. Closes #39. Many thanks to Christian Boos for the patch!
cmlenz
parents:
191
diff
changeset
|
148 <span>OK</span> |
4140bff0d7d2
Remove the (hopefully) last instance where directives store state in instance variables, allowing templates to be cached and reused in a threadsafe manner. Closes #39. Many thanks to Christian Boos for the patch!
cmlenz
parents:
191
diff
changeset
|
149 </div> |
4140bff0d7d2
Remove the (hopefully) last instance where directives store state in instance variables, allowing templates to be cached and reused in a threadsafe manner. Closes #39. Many thanks to Christian Boos for the patch!
cmlenz
parents:
191
diff
changeset
|
150 </div> |
4140bff0d7d2
Remove the (hopefully) last instance where directives store state in instance variables, allowing templates to be cached and reused in a threadsafe manner. Closes #39. Many thanks to Christian Boos for the patch!
cmlenz
parents:
191
diff
changeset
|
151 </doc>""", str(tmpl.generate())) |
4140bff0d7d2
Remove the (hopefully) last instance where directives store state in instance variables, allowing templates to be cached and reused in a threadsafe manner. Closes #39. Many thanks to Christian Boos for the patch!
cmlenz
parents:
191
diff
changeset
|
152 |
53
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
153 def test_when_with_strip(self): |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
154 """ |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
155 Verify that a when directive with a strip directive actually strips of |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
156 the outer element. |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
157 """ |
61 | 158 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/"> |
53
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
159 <div py:choose="" py:strip=""> |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
160 <span py:otherwise="">foo</span> |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
161 </div> |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
162 </doc>""") |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
163 self.assertEqual("""<doc> |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
164 <span>foo</span> |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
165 </doc>""", str(tmpl.generate())) |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
166 |
166
718cba809cea
Better error reporting for errors in directive expressions, and when `py:otherwise`/`py:when` are used outside a `py:choose` directive. Thanks to Christian Boos for the initial patch.
cmlenz
parents:
165
diff
changeset
|
167 def test_when_outside_choose(self): |
718cba809cea
Better error reporting for errors in directive expressions, and when `py:otherwise`/`py:when` are used outside a `py:choose` directive. Thanks to Christian Boos for the initial patch.
cmlenz
parents:
165
diff
changeset
|
168 """ |
718cba809cea
Better error reporting for errors in directive expressions, and when `py:otherwise`/`py:when` are used outside a `py:choose` directive. Thanks to Christian Boos for the initial patch.
cmlenz
parents:
165
diff
changeset
|
169 Verify that a `when` directive outside of a `choose` directive is |
718cba809cea
Better error reporting for errors in directive expressions, and when `py:otherwise`/`py:when` are used outside a `py:choose` directive. Thanks to Christian Boos for the initial patch.
cmlenz
parents:
165
diff
changeset
|
170 reported as an error. |
718cba809cea
Better error reporting for errors in directive expressions, and when `py:otherwise`/`py:when` are used outside a `py:choose` directive. Thanks to Christian Boos for the initial patch.
cmlenz
parents:
165
diff
changeset
|
171 """ |
718cba809cea
Better error reporting for errors in directive expressions, and when `py:otherwise`/`py:when` are used outside a `py:choose` directive. Thanks to Christian Boos for the initial patch.
cmlenz
parents:
165
diff
changeset
|
172 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/"> |
718cba809cea
Better error reporting for errors in directive expressions, and when `py:otherwise`/`py:when` are used outside a `py:choose` directive. Thanks to Christian Boos for the initial patch.
cmlenz
parents:
165
diff
changeset
|
173 <div py:when="xy" /> |
718cba809cea
Better error reporting for errors in directive expressions, and when `py:otherwise`/`py:when` are used outside a `py:choose` directive. Thanks to Christian Boos for the initial patch.
cmlenz
parents:
165
diff
changeset
|
174 </doc>""") |
718cba809cea
Better error reporting for errors in directive expressions, and when `py:otherwise`/`py:when` are used outside a `py:choose` directive. Thanks to Christian Boos for the initial patch.
cmlenz
parents:
165
diff
changeset
|
175 self.assertRaises(TemplateSyntaxError, str, tmpl.generate()) |
718cba809cea
Better error reporting for errors in directive expressions, and when `py:otherwise`/`py:when` are used outside a `py:choose` directive. Thanks to Christian Boos for the initial patch.
cmlenz
parents:
165
diff
changeset
|
176 |
181
d07ce6c1dbbe
Some error message improvements for template directives. Thanks to Christian Boos for the patch!
cmlenz
parents:
179
diff
changeset
|
177 def test_otherwise_outside_choose(self): |
166
718cba809cea
Better error reporting for errors in directive expressions, and when `py:otherwise`/`py:when` are used outside a `py:choose` directive. Thanks to Christian Boos for the initial patch.
cmlenz
parents:
165
diff
changeset
|
178 """ |
718cba809cea
Better error reporting for errors in directive expressions, and when `py:otherwise`/`py:when` are used outside a `py:choose` directive. Thanks to Christian Boos for the initial patch.
cmlenz
parents:
165
diff
changeset
|
179 Verify that an `otherwise` directive outside of a `choose` directive is |
718cba809cea
Better error reporting for errors in directive expressions, and when `py:otherwise`/`py:when` are used outside a `py:choose` directive. Thanks to Christian Boos for the initial patch.
cmlenz
parents:
165
diff
changeset
|
180 reported as an error. |
718cba809cea
Better error reporting for errors in directive expressions, and when `py:otherwise`/`py:when` are used outside a `py:choose` directive. Thanks to Christian Boos for the initial patch.
cmlenz
parents:
165
diff
changeset
|
181 """ |
718cba809cea
Better error reporting for errors in directive expressions, and when `py:otherwise`/`py:when` are used outside a `py:choose` directive. Thanks to Christian Boos for the initial patch.
cmlenz
parents:
165
diff
changeset
|
182 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/"> |
718cba809cea
Better error reporting for errors in directive expressions, and when `py:otherwise`/`py:when` are used outside a `py:choose` directive. Thanks to Christian Boos for the initial patch.
cmlenz
parents:
165
diff
changeset
|
183 <div py:otherwise="" /> |
718cba809cea
Better error reporting for errors in directive expressions, and when `py:otherwise`/`py:when` are used outside a `py:choose` directive. Thanks to Christian Boos for the initial patch.
cmlenz
parents:
165
diff
changeset
|
184 </doc>""") |
718cba809cea
Better error reporting for errors in directive expressions, and when `py:otherwise`/`py:when` are used outside a `py:choose` directive. Thanks to Christian Boos for the initial patch.
cmlenz
parents:
165
diff
changeset
|
185 self.assertRaises(TemplateSyntaxError, str, tmpl.generate()) |
718cba809cea
Better error reporting for errors in directive expressions, and when `py:otherwise`/`py:when` are used outside a `py:choose` directive. Thanks to Christian Boos for the initial patch.
cmlenz
parents:
165
diff
changeset
|
186 |
181
d07ce6c1dbbe
Some error message improvements for template directives. Thanks to Christian Boos for the patch!
cmlenz
parents:
179
diff
changeset
|
187 def test_when_without_test(self): |
d07ce6c1dbbe
Some error message improvements for template directives. Thanks to Christian Boos for the patch!
cmlenz
parents:
179
diff
changeset
|
188 """ |
d07ce6c1dbbe
Some error message improvements for template directives. Thanks to Christian Boos for the patch!
cmlenz
parents:
179
diff
changeset
|
189 Verify that an `when` directive that doesn't have a `test` attribute |
d07ce6c1dbbe
Some error message improvements for template directives. Thanks to Christian Boos for the patch!
cmlenz
parents:
179
diff
changeset
|
190 is reported as an error. |
d07ce6c1dbbe
Some error message improvements for template directives. Thanks to Christian Boos for the patch!
cmlenz
parents:
179
diff
changeset
|
191 """ |
d07ce6c1dbbe
Some error message improvements for template directives. Thanks to Christian Boos for the patch!
cmlenz
parents:
179
diff
changeset
|
192 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/"> |
d07ce6c1dbbe
Some error message improvements for template directives. Thanks to Christian Boos for the patch!
cmlenz
parents:
179
diff
changeset
|
193 <div py:choose="" py:strip=""> |
d07ce6c1dbbe
Some error message improvements for template directives. Thanks to Christian Boos for the patch!
cmlenz
parents:
179
diff
changeset
|
194 <py:when>foo</py:when> |
d07ce6c1dbbe
Some error message improvements for template directives. Thanks to Christian Boos for the patch!
cmlenz
parents:
179
diff
changeset
|
195 </div> |
d07ce6c1dbbe
Some error message improvements for template directives. Thanks to Christian Boos for the patch!
cmlenz
parents:
179
diff
changeset
|
196 </doc>""") |
d07ce6c1dbbe
Some error message improvements for template directives. Thanks to Christian Boos for the patch!
cmlenz
parents:
179
diff
changeset
|
197 self.assertRaises(TemplateSyntaxError, str, tmpl.generate()) |
d07ce6c1dbbe
Some error message improvements for template directives. Thanks to Christian Boos for the patch!
cmlenz
parents:
179
diff
changeset
|
198 |
d07ce6c1dbbe
Some error message improvements for template directives. Thanks to Christian Boos for the patch!
cmlenz
parents:
179
diff
changeset
|
199 def test_otherwise_without_test(self): |
d07ce6c1dbbe
Some error message improvements for template directives. Thanks to Christian Boos for the patch!
cmlenz
parents:
179
diff
changeset
|
200 """ |
d07ce6c1dbbe
Some error message improvements for template directives. Thanks to Christian Boos for the patch!
cmlenz
parents:
179
diff
changeset
|
201 Verify that an `otherwise` directive can be used without a `test` |
d07ce6c1dbbe
Some error message improvements for template directives. Thanks to Christian Boos for the patch!
cmlenz
parents:
179
diff
changeset
|
202 attribute. |
d07ce6c1dbbe
Some error message improvements for template directives. Thanks to Christian Boos for the patch!
cmlenz
parents:
179
diff
changeset
|
203 """ |
d07ce6c1dbbe
Some error message improvements for template directives. Thanks to Christian Boos for the patch!
cmlenz
parents:
179
diff
changeset
|
204 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/"> |
d07ce6c1dbbe
Some error message improvements for template directives. Thanks to Christian Boos for the patch!
cmlenz
parents:
179
diff
changeset
|
205 <div py:choose="" py:strip=""> |
d07ce6c1dbbe
Some error message improvements for template directives. Thanks to Christian Boos for the patch!
cmlenz
parents:
179
diff
changeset
|
206 <py:otherwise>foo</py:otherwise> |
d07ce6c1dbbe
Some error message improvements for template directives. Thanks to Christian Boos for the patch!
cmlenz
parents:
179
diff
changeset
|
207 </div> |
d07ce6c1dbbe
Some error message improvements for template directives. Thanks to Christian Boos for the patch!
cmlenz
parents:
179
diff
changeset
|
208 </doc>""") |
d07ce6c1dbbe
Some error message improvements for template directives. Thanks to Christian Boos for the patch!
cmlenz
parents:
179
diff
changeset
|
209 self.assertEqual("""<doc> |
d07ce6c1dbbe
Some error message improvements for template directives. Thanks to Christian Boos for the patch!
cmlenz
parents:
179
diff
changeset
|
210 foo |
d07ce6c1dbbe
Some error message improvements for template directives. Thanks to Christian Boos for the patch!
cmlenz
parents:
179
diff
changeset
|
211 </doc>""", str(tmpl.generate())) |
d07ce6c1dbbe
Some error message improvements for template directives. Thanks to Christian Boos for the patch!
cmlenz
parents:
179
diff
changeset
|
212 |
65
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
213 def test_as_element(self): |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
214 """ |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
215 Verify that the directive can also be used as an element. |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
216 """ |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
217 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/"> |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
218 <py:choose> |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
219 <py:when test="1 == 1">1</py:when> |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
220 <py:when test="2 == 2">2</py:when> |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
221 <py:when test="3 == 3">3</py:when> |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
222 </py:choose> |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
223 </doc>""") |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
224 self.assertEqual("""<doc> |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
225 1 |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
226 </doc>""", str(tmpl.generate())) |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
227 |
53
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
228 |
50
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
229 class DefDirectiveTestCase(unittest.TestCase): |
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
230 """Tests for the `py:def` template directive.""" |
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
231 |
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
232 def test_function_with_strip(self): |
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
233 """ |
53
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
234 Verify that a named template function with a strip directive actually |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
235 strips of the outer element. |
50
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
236 """ |
61 | 237 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/"> |
50
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
238 <div py:def="echo(what)" py:strip=""> |
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
239 <b>${what}</b> |
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
240 </div> |
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
241 ${echo('foo')} |
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
242 </doc>""") |
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
243 self.assertEqual("""<doc> |
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
244 <b>foo</b> |
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
245 </doc>""", str(tmpl.generate())) |
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
246 |
90
242610137d1f
When an expression evaluates to a callable, it is called implicitly.
cmlenz
parents:
89
diff
changeset
|
247 def test_exec_in_replace(self): |
242610137d1f
When an expression evaluates to a callable, it is called implicitly.
cmlenz
parents:
89
diff
changeset
|
248 tmpl = Template("""<div xmlns:py="http://markup.edgewall.org/"> |
242610137d1f
When an expression evaluates to a callable, it is called implicitly.
cmlenz
parents:
89
diff
changeset
|
249 <p py:def="echo(greeting, name='world')" class="message"> |
242610137d1f
When an expression evaluates to a callable, it is called implicitly.
cmlenz
parents:
89
diff
changeset
|
250 ${greeting}, ${name}! |
242610137d1f
When an expression evaluates to a callable, it is called implicitly.
cmlenz
parents:
89
diff
changeset
|
251 </p> |
242610137d1f
When an expression evaluates to a callable, it is called implicitly.
cmlenz
parents:
89
diff
changeset
|
252 <div py:replace="echo('hello')"></div> |
242610137d1f
When an expression evaluates to a callable, it is called implicitly.
cmlenz
parents:
89
diff
changeset
|
253 </div>""") |
242610137d1f
When an expression evaluates to a callable, it is called implicitly.
cmlenz
parents:
89
diff
changeset
|
254 self.assertEqual("""<div> |
242610137d1f
When an expression evaluates to a callable, it is called implicitly.
cmlenz
parents:
89
diff
changeset
|
255 <p class="message"> |
242610137d1f
When an expression evaluates to a callable, it is called implicitly.
cmlenz
parents:
89
diff
changeset
|
256 hello, world! |
242610137d1f
When an expression evaluates to a callable, it is called implicitly.
cmlenz
parents:
89
diff
changeset
|
257 </p> |
242610137d1f
When an expression evaluates to a callable, it is called implicitly.
cmlenz
parents:
89
diff
changeset
|
258 </div>""", str(tmpl.generate())) |
242610137d1f
When an expression evaluates to a callable, it is called implicitly.
cmlenz
parents:
89
diff
changeset
|
259 |
65
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
260 def test_as_element(self): |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
261 """ |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
262 Verify that the directive can also be used as an element. |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
263 """ |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
264 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/"> |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
265 <py:def function="echo(what)"> |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
266 <b>${what}</b> |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
267 </py:def> |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
268 ${echo('foo')} |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
269 </doc>""") |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
270 self.assertEqual("""<doc> |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
271 <b>foo</b> |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
272 </doc>""", str(tmpl.generate())) |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
273 |
154
1c404be518d1
* Make sure `py:def` macros don't go out of scope if they are defined inside another directive.
cmlenz
parents:
152
diff
changeset
|
274 def test_nested_defs(self): |
1c404be518d1
* Make sure `py:def` macros don't go out of scope if they are defined inside another directive.
cmlenz
parents:
152
diff
changeset
|
275 """ |
1c404be518d1
* Make sure `py:def` macros don't go out of scope if they are defined inside another directive.
cmlenz
parents:
152
diff
changeset
|
276 Verify that a template function defined inside a conditional block can |
1c404be518d1
* Make sure `py:def` macros don't go out of scope if they are defined inside another directive.
cmlenz
parents:
152
diff
changeset
|
277 be called from outside that block. |
1c404be518d1
* Make sure `py:def` macros don't go out of scope if they are defined inside another directive.
cmlenz
parents:
152
diff
changeset
|
278 """ |
1c404be518d1
* Make sure `py:def` macros don't go out of scope if they are defined inside another directive.
cmlenz
parents:
152
diff
changeset
|
279 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/"> |
1c404be518d1
* Make sure `py:def` macros don't go out of scope if they are defined inside another directive.
cmlenz
parents:
152
diff
changeset
|
280 <py:if test="semantic"> |
1c404be518d1
* Make sure `py:def` macros don't go out of scope if they are defined inside another directive.
cmlenz
parents:
152
diff
changeset
|
281 <strong py:def="echo(what)">${what}</strong> |
1c404be518d1
* Make sure `py:def` macros don't go out of scope if they are defined inside another directive.
cmlenz
parents:
152
diff
changeset
|
282 </py:if> |
1c404be518d1
* Make sure `py:def` macros don't go out of scope if they are defined inside another directive.
cmlenz
parents:
152
diff
changeset
|
283 <py:if test="not semantic"> |
1c404be518d1
* Make sure `py:def` macros don't go out of scope if they are defined inside another directive.
cmlenz
parents:
152
diff
changeset
|
284 <b py:def="echo(what)">${what}</b> |
1c404be518d1
* Make sure `py:def` macros don't go out of scope if they are defined inside another directive.
cmlenz
parents:
152
diff
changeset
|
285 </py:if> |
1c404be518d1
* Make sure `py:def` macros don't go out of scope if they are defined inside another directive.
cmlenz
parents:
152
diff
changeset
|
286 ${echo('foo')} |
1c404be518d1
* Make sure `py:def` macros don't go out of scope if they are defined inside another directive.
cmlenz
parents:
152
diff
changeset
|
287 </doc>""") |
1c404be518d1
* Make sure `py:def` macros don't go out of scope if they are defined inside another directive.
cmlenz
parents:
152
diff
changeset
|
288 self.assertEqual("""<doc> |
1c404be518d1
* Make sure `py:def` macros don't go out of scope if they are defined inside another directive.
cmlenz
parents:
152
diff
changeset
|
289 <strong>foo</strong> |
1c404be518d1
* Make sure `py:def` macros don't go out of scope if they are defined inside another directive.
cmlenz
parents:
152
diff
changeset
|
290 </doc>""", str(tmpl.generate(semantic=True))) |
1c404be518d1
* Make sure `py:def` macros don't go out of scope if they are defined inside another directive.
cmlenz
parents:
152
diff
changeset
|
291 |
165
4ed68a904235
Fix handling of keyword arguments in `py:def` directive. Thanks to Christian Boos for reporting the problem and providing the basic patch for this change.
cmlenz
parents:
158
diff
changeset
|
292 def test_function_with_default_arg(self): |
4ed68a904235
Fix handling of keyword arguments in `py:def` directive. Thanks to Christian Boos for reporting the problem and providing the basic patch for this change.
cmlenz
parents:
158
diff
changeset
|
293 """ |
4ed68a904235
Fix handling of keyword arguments in `py:def` directive. Thanks to Christian Boos for reporting the problem and providing the basic patch for this change.
cmlenz
parents:
158
diff
changeset
|
294 Verify that keyword arguments work with `py:def` directives. |
4ed68a904235
Fix handling of keyword arguments in `py:def` directive. Thanks to Christian Boos for reporting the problem and providing the basic patch for this change.
cmlenz
parents:
158
diff
changeset
|
295 """ |
4ed68a904235
Fix handling of keyword arguments in `py:def` directive. Thanks to Christian Boos for reporting the problem and providing the basic patch for this change.
cmlenz
parents:
158
diff
changeset
|
296 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/"> |
4ed68a904235
Fix handling of keyword arguments in `py:def` directive. Thanks to Christian Boos for reporting the problem and providing the basic patch for this change.
cmlenz
parents:
158
diff
changeset
|
297 <b py:def="echo(what, bold=False)" py:strip="not bold">${what}</b> |
4ed68a904235
Fix handling of keyword arguments in `py:def` directive. Thanks to Christian Boos for reporting the problem and providing the basic patch for this change.
cmlenz
parents:
158
diff
changeset
|
298 ${echo('foo')} |
4ed68a904235
Fix handling of keyword arguments in `py:def` directive. Thanks to Christian Boos for reporting the problem and providing the basic patch for this change.
cmlenz
parents:
158
diff
changeset
|
299 </doc>""") |
4ed68a904235
Fix handling of keyword arguments in `py:def` directive. Thanks to Christian Boos for reporting the problem and providing the basic patch for this change.
cmlenz
parents:
158
diff
changeset
|
300 self.assertEqual("""<doc> |
4ed68a904235
Fix handling of keyword arguments in `py:def` directive. Thanks to Christian Boos for reporting the problem and providing the basic patch for this change.
cmlenz
parents:
158
diff
changeset
|
301 foo |
4ed68a904235
Fix handling of keyword arguments in `py:def` directive. Thanks to Christian Boos for reporting the problem and providing the basic patch for this change.
cmlenz
parents:
158
diff
changeset
|
302 </doc>""", str(tmpl.generate())) |
4ed68a904235
Fix handling of keyword arguments in `py:def` directive. Thanks to Christian Boos for reporting the problem and providing the basic patch for this change.
cmlenz
parents:
158
diff
changeset
|
303 |
185
8e5a3048b359
Fix for #34: `py:def` macros can now be invoked from within expressions in attribute values.
cmlenz
parents:
184
diff
changeset
|
304 def test_invocation_in_attribute(self): |
8e5a3048b359
Fix for #34: `py:def` macros can now be invoked from within expressions in attribute values.
cmlenz
parents:
184
diff
changeset
|
305 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/"> |
8e5a3048b359
Fix for #34: `py:def` macros can now be invoked from within expressions in attribute values.
cmlenz
parents:
184
diff
changeset
|
306 <py:def function="echo(what)">${what or 'something'}</py:def> |
8e5a3048b359
Fix for #34: `py:def` macros can now be invoked from within expressions in attribute values.
cmlenz
parents:
184
diff
changeset
|
307 <p class="${echo('foo')}">bar</p> |
8e5a3048b359
Fix for #34: `py:def` macros can now be invoked from within expressions in attribute values.
cmlenz
parents:
184
diff
changeset
|
308 </doc>""") |
8e5a3048b359
Fix for #34: `py:def` macros can now be invoked from within expressions in attribute values.
cmlenz
parents:
184
diff
changeset
|
309 self.assertEqual("""<doc> |
8e5a3048b359
Fix for #34: `py:def` macros can now be invoked from within expressions in attribute values.
cmlenz
parents:
184
diff
changeset
|
310 <p class="foo">bar</p> |
8e5a3048b359
Fix for #34: `py:def` macros can now be invoked from within expressions in attribute values.
cmlenz
parents:
184
diff
changeset
|
311 </doc>""", str(tmpl.generate())) |
8e5a3048b359
Fix for #34: `py:def` macros can now be invoked from within expressions in attribute values.
cmlenz
parents:
184
diff
changeset
|
312 |
8e5a3048b359
Fix for #34: `py:def` macros can now be invoked from within expressions in attribute values.
cmlenz
parents:
184
diff
changeset
|
313 def test_invocation_in_attribute_none(self): |
8e5a3048b359
Fix for #34: `py:def` macros can now be invoked from within expressions in attribute values.
cmlenz
parents:
184
diff
changeset
|
314 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/"> |
8e5a3048b359
Fix for #34: `py:def` macros can now be invoked from within expressions in attribute values.
cmlenz
parents:
184
diff
changeset
|
315 <py:def function="echo()">${None}</py:def> |
8e5a3048b359
Fix for #34: `py:def` macros can now be invoked from within expressions in attribute values.
cmlenz
parents:
184
diff
changeset
|
316 <p class="${echo()}">bar</p> |
8e5a3048b359
Fix for #34: `py:def` macros can now be invoked from within expressions in attribute values.
cmlenz
parents:
184
diff
changeset
|
317 </doc>""") |
8e5a3048b359
Fix for #34: `py:def` macros can now be invoked from within expressions in attribute values.
cmlenz
parents:
184
diff
changeset
|
318 self.assertEqual("""<doc> |
8e5a3048b359
Fix for #34: `py:def` macros can now be invoked from within expressions in attribute values.
cmlenz
parents:
184
diff
changeset
|
319 <p>bar</p> |
8e5a3048b359
Fix for #34: `py:def` macros can now be invoked from within expressions in attribute values.
cmlenz
parents:
184
diff
changeset
|
320 </doc>""", str(tmpl.generate())) |
8e5a3048b359
Fix for #34: `py:def` macros can now be invoked from within expressions in attribute values.
cmlenz
parents:
184
diff
changeset
|
321 |
50
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
322 |
51
a572b1018b66
Fix `py:for` directive when combined with other directives (such as `py:strip`).
cmlenz
parents:
50
diff
changeset
|
323 class ForDirectiveTestCase(unittest.TestCase): |
53
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
324 """Tests for the `py:for` template directive.""" |
51
a572b1018b66
Fix `py:for` directive when combined with other directives (such as `py:strip`).
cmlenz
parents:
50
diff
changeset
|
325 |
a572b1018b66
Fix `py:for` directive when combined with other directives (such as `py:strip`).
cmlenz
parents:
50
diff
changeset
|
326 def test_loop_with_strip(self): |
a572b1018b66
Fix `py:for` directive when combined with other directives (such as `py:strip`).
cmlenz
parents:
50
diff
changeset
|
327 """ |
53
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
328 Verify that the combining the `py:for` directive with `py:strip` works |
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
329 correctly. |
51
a572b1018b66
Fix `py:for` directive when combined with other directives (such as `py:strip`).
cmlenz
parents:
50
diff
changeset
|
330 """ |
61 | 331 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/"> |
51
a572b1018b66
Fix `py:for` directive when combined with other directives (such as `py:strip`).
cmlenz
parents:
50
diff
changeset
|
332 <div py:for="item in items" py:strip=""> |
a572b1018b66
Fix `py:for` directive when combined with other directives (such as `py:strip`).
cmlenz
parents:
50
diff
changeset
|
333 <b>${item}</b> |
a572b1018b66
Fix `py:for` directive when combined with other directives (such as `py:strip`).
cmlenz
parents:
50
diff
changeset
|
334 </div> |
a572b1018b66
Fix `py:for` directive when combined with other directives (such as `py:strip`).
cmlenz
parents:
50
diff
changeset
|
335 </doc>""") |
a572b1018b66
Fix `py:for` directive when combined with other directives (such as `py:strip`).
cmlenz
parents:
50
diff
changeset
|
336 self.assertEqual("""<doc> |
a572b1018b66
Fix `py:for` directive when combined with other directives (such as `py:strip`).
cmlenz
parents:
50
diff
changeset
|
337 <b>1</b> |
a572b1018b66
Fix `py:for` directive when combined with other directives (such as `py:strip`).
cmlenz
parents:
50
diff
changeset
|
338 <b>2</b> |
a572b1018b66
Fix `py:for` directive when combined with other directives (such as `py:strip`).
cmlenz
parents:
50
diff
changeset
|
339 <b>3</b> |
a572b1018b66
Fix `py:for` directive when combined with other directives (such as `py:strip`).
cmlenz
parents:
50
diff
changeset
|
340 <b>4</b> |
a572b1018b66
Fix `py:for` directive when combined with other directives (such as `py:strip`).
cmlenz
parents:
50
diff
changeset
|
341 <b>5</b> |
149
7306bf730ff3
`Template.generate()` now accepts the context data as keyword arguments, so that you don't have to import the `Context` class every time you want to pass data into a template.
cmlenz
parents:
145
diff
changeset
|
342 </doc>""", str(tmpl.generate(items=range(1, 6)))) |
51
a572b1018b66
Fix `py:for` directive when combined with other directives (such as `py:strip`).
cmlenz
parents:
50
diff
changeset
|
343 |
65
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
344 def test_as_element(self): |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
345 """ |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
346 Verify that the directive can also be used as an element. |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
347 """ |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
348 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/"> |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
349 <py:for each="item in items"> |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
350 <b>${item}</b> |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
351 </py:for> |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
352 </doc>""") |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
353 self.assertEqual("""<doc> |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
354 <b>1</b> |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
355 <b>2</b> |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
356 <b>3</b> |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
357 <b>4</b> |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
358 <b>5</b> |
149
7306bf730ff3
`Template.generate()` now accepts the context data as keyword arguments, so that you don't have to import the `Context` class every time you want to pass data into a template.
cmlenz
parents:
145
diff
changeset
|
359 </doc>""", str(tmpl.generate(items=range(1, 6)))) |
65
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
360 |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
361 |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
362 class IfDirectiveTestCase(unittest.TestCase): |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
363 """Tests for the `py:if` template directive.""" |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
364 |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
365 def test_loop_with_strip(self): |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
366 """ |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
367 Verify that the combining the `py:if` directive with `py:strip` works |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
368 correctly. |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
369 """ |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
370 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/"> |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
371 <b py:if="foo" py:strip="">${bar}</b> |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
372 </doc>""") |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
373 self.assertEqual("""<doc> |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
374 Hello |
149
7306bf730ff3
`Template.generate()` now accepts the context data as keyword arguments, so that you don't have to import the `Context` class every time you want to pass data into a template.
cmlenz
parents:
145
diff
changeset
|
375 </doc>""", str(tmpl.generate(foo=True, bar='Hello'))) |
65
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
376 |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
377 def test_as_element(self): |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
378 """ |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
379 Verify that the directive can also be used as an element. |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
380 """ |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
381 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/"> |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
382 <py:if test="foo">${bar}</py:if> |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
383 </doc>""") |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
384 self.assertEqual("""<doc> |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
385 Hello |
149
7306bf730ff3
`Template.generate()` now accepts the context data as keyword arguments, so that you don't have to import the `Context` class every time you want to pass data into a template.
cmlenz
parents:
145
diff
changeset
|
386 </doc>""", str(tmpl.generate(foo=True, bar='Hello'))) |
65
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
387 |
51
a572b1018b66
Fix `py:for` directive when combined with other directives (such as `py:strip`).
cmlenz
parents:
50
diff
changeset
|
388 |
36
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
389 class MatchDirectiveTestCase(unittest.TestCase): |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
390 """Tests for the `py:match` template directive.""" |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
391 |
50
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
392 def test_with_strip(self): |
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
393 """ |
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
394 Verify that a match template can produce the same kind of element that |
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
395 it matched without entering an infinite recursion. |
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
396 """ |
61 | 397 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/"> |
50
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
398 <elem py:match="elem" py:strip=""> |
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
399 <div class="elem">${select('*/text()')}</div> |
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
400 </elem> |
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
401 <elem>Hey Joe</elem> |
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
402 </doc>""") |
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
403 self.assertEqual("""<doc> |
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
404 <div class="elem">Hey Joe</div> |
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
405 </doc>""", str(tmpl.generate())) |
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
406 |
36
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
407 def test_without_strip(self): |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
408 """ |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
409 Verify that a match template can produce the same kind of element that |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
410 it matched without entering an infinite recursion. |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
411 """ |
61 | 412 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/"> |
36
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
413 <elem py:match="elem"> |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
414 <div class="elem">${select('*/text()')}</div> |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
415 </elem> |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
416 <elem>Hey Joe</elem> |
37
224b0b41d1da
Moved some of the tests for the strip directive to a new unittest test case to not clutter up the documentation.
cmlenz
parents:
36
diff
changeset
|
417 </doc>""") |
36
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
418 self.assertEqual("""<doc> |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
419 <elem> |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
420 <div class="elem">Hey Joe</div> |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
421 </elem> |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
422 </doc>""", str(tmpl.generate())) |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
423 |
65
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
424 def test_as_element(self): |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
425 """ |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
426 Verify that the directive can also be used as an element. |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
427 """ |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
428 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/"> |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
429 <py:match path="elem"> |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
430 <div class="elem">${select('*/text()')}</div> |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
431 </py:match> |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
432 <elem>Hey Joe</elem> |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
433 </doc>""") |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
434 self.assertEqual("""<doc> |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
435 <div class="elem">Hey Joe</div> |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
436 </doc>""", str(tmpl.generate())) |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
437 |
36
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
438 def test_recursive_match_1(self): |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
439 """ |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
440 Match directives are applied recursively, meaning that they are also |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
441 applied to any content they may have produced themselves: |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
442 """ |
61 | 443 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/"> |
36
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
444 <elem py:match="elem"> |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
445 <div class="elem"> |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
446 ${select('*/*')} |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
447 </div> |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
448 </elem> |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
449 <elem> |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
450 <subelem> |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
451 <elem/> |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
452 </subelem> |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
453 </elem> |
37
224b0b41d1da
Moved some of the tests for the strip directive to a new unittest test case to not clutter up the documentation.
cmlenz
parents:
36
diff
changeset
|
454 </doc>""") |
36
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
455 self.assertEqual("""<doc> |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
456 <elem> |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
457 <div class="elem"> |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
458 <subelem> |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
459 <elem> |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
460 <div class="elem"> |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
461 </div> |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
462 </elem> |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
463 </subelem> |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
464 </div> |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
465 </elem> |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
466 </doc>""", str(tmpl.generate())) |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
467 |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
468 def test_recursive_match_2(self): |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
469 """ |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
470 When two or more match templates match the same element and also |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
471 themselves output the element they match, avoiding recursion is even |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
472 more complex, but should work. |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
473 """ |
61 | 474 tmpl = Template("""<html xmlns:py="http://markup.edgewall.org/"> |
36
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
475 <body py:match="body"> |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
476 <div id="header"/> |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
477 ${select('*/*')} |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
478 </body> |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
479 <body py:match="body"> |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
480 ${select('*/*')} |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
481 <div id="footer"/> |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
482 </body> |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
483 <body> |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
484 <h1>Foo</h1> |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
485 </body> |
37
224b0b41d1da
Moved some of the tests for the strip directive to a new unittest test case to not clutter up the documentation.
cmlenz
parents:
36
diff
changeset
|
486 </html>""") |
36
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
487 self.assertEqual("""<html> |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
488 <body> |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
489 <div id="header"/><h1>Foo</h1> |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
490 <div id="footer"/> |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
491 </body> |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
492 </html>""", str(tmpl.generate())) |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
493 |
77
f1aa49c759b2
* Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents:
75
diff
changeset
|
494 def test_select_all_attrs(self): |
f1aa49c759b2
* Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents:
75
diff
changeset
|
495 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/"> |
f1aa49c759b2
* Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents:
75
diff
changeset
|
496 <div py:match="elem" py:attrs="select('@*')"> |
f1aa49c759b2
* Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents:
75
diff
changeset
|
497 ${select('*/text()')} |
f1aa49c759b2
* Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents:
75
diff
changeset
|
498 </div> |
f1aa49c759b2
* Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents:
75
diff
changeset
|
499 <elem id="joe">Hey Joe</elem> |
f1aa49c759b2
* Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents:
75
diff
changeset
|
500 </doc>""") |
f1aa49c759b2
* Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents:
75
diff
changeset
|
501 self.assertEqual("""<doc> |
f1aa49c759b2
* Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents:
75
diff
changeset
|
502 <div id="joe"> |
f1aa49c759b2
* Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents:
75
diff
changeset
|
503 Hey Joe |
f1aa49c759b2
* Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents:
75
diff
changeset
|
504 </div> |
f1aa49c759b2
* Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents:
75
diff
changeset
|
505 </doc>""", str(tmpl.generate())) |
f1aa49c759b2
* Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents:
75
diff
changeset
|
506 |
f1aa49c759b2
* Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents:
75
diff
changeset
|
507 def test_select_all_attrs_empty(self): |
f1aa49c759b2
* Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents:
75
diff
changeset
|
508 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/"> |
f1aa49c759b2
* Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents:
75
diff
changeset
|
509 <div py:match="elem" py:attrs="select('@*')"> |
f1aa49c759b2
* Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents:
75
diff
changeset
|
510 ${select('*/text()')} |
f1aa49c759b2
* Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents:
75
diff
changeset
|
511 </div> |
f1aa49c759b2
* Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents:
75
diff
changeset
|
512 <elem>Hey Joe</elem> |
f1aa49c759b2
* Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents:
75
diff
changeset
|
513 </doc>""") |
f1aa49c759b2
* Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents:
75
diff
changeset
|
514 self.assertEqual("""<doc> |
f1aa49c759b2
* Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents:
75
diff
changeset
|
515 <div> |
f1aa49c759b2
* Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents:
75
diff
changeset
|
516 Hey Joe |
f1aa49c759b2
* Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents:
75
diff
changeset
|
517 </div> |
f1aa49c759b2
* Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents:
75
diff
changeset
|
518 </doc>""", str(tmpl.generate())) |
f1aa49c759b2
* Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents:
75
diff
changeset
|
519 |
f1aa49c759b2
* Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents:
75
diff
changeset
|
520 def test_select_all_attrs_in_body(self): |
f1aa49c759b2
* Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents:
75
diff
changeset
|
521 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/"> |
f1aa49c759b2
* Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents:
75
diff
changeset
|
522 <div py:match="elem"> |
f1aa49c759b2
* Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents:
75
diff
changeset
|
523 Hey ${select('text()')} ${select('@*')} |
f1aa49c759b2
* Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents:
75
diff
changeset
|
524 </div> |
f1aa49c759b2
* Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents:
75
diff
changeset
|
525 <elem title="Cool">Joe</elem> |
f1aa49c759b2
* Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents:
75
diff
changeset
|
526 </doc>""") |
f1aa49c759b2
* Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents:
75
diff
changeset
|
527 self.assertEqual("""<doc> |
f1aa49c759b2
* Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents:
75
diff
changeset
|
528 <div> |
f1aa49c759b2
* Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents:
75
diff
changeset
|
529 Hey Joe Cool |
f1aa49c759b2
* Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents:
75
diff
changeset
|
530 </div> |
f1aa49c759b2
* Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents:
75
diff
changeset
|
531 </doc>""", str(tmpl.generate())) |
f1aa49c759b2
* Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents:
75
diff
changeset
|
532 |
172
4b4e80b2b0b5
Fix for #30 (trouble using `py:def`inside a match template)
cmlenz
parents:
166
diff
changeset
|
533 def test_def_in_match(self): |
4b4e80b2b0b5
Fix for #30 (trouble using `py:def`inside a match template)
cmlenz
parents:
166
diff
changeset
|
534 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/"> |
4b4e80b2b0b5
Fix for #30 (trouble using `py:def`inside a match template)
cmlenz
parents:
166
diff
changeset
|
535 <py:def function="maketitle(test)"><b py:replace="test" /></py:def> |
4b4e80b2b0b5
Fix for #30 (trouble using `py:def`inside a match template)
cmlenz
parents:
166
diff
changeset
|
536 <head py:match="head">${select('*')}</head> |
4b4e80b2b0b5
Fix for #30 (trouble using `py:def`inside a match template)
cmlenz
parents:
166
diff
changeset
|
537 <head><title>${maketitle(True)}</title></head> |
4b4e80b2b0b5
Fix for #30 (trouble using `py:def`inside a match template)
cmlenz
parents:
166
diff
changeset
|
538 </doc>""") |
4b4e80b2b0b5
Fix for #30 (trouble using `py:def`inside a match template)
cmlenz
parents:
166
diff
changeset
|
539 self.assertEqual("""<doc> |
4b4e80b2b0b5
Fix for #30 (trouble using `py:def`inside a match template)
cmlenz
parents:
166
diff
changeset
|
540 <head><title>True</title></head> |
4b4e80b2b0b5
Fix for #30 (trouble using `py:def`inside a match template)
cmlenz
parents:
166
diff
changeset
|
541 </doc>""", str(tmpl.generate())) |
4b4e80b2b0b5
Fix for #30 (trouble using `py:def`inside a match template)
cmlenz
parents:
166
diff
changeset
|
542 |
179
a2e0a7986d19
Implemented support for XPath variables in predicates (#31).
cmlenz
parents:
175
diff
changeset
|
543 def test_match_with_xpath_variable(self): |
a2e0a7986d19
Implemented support for XPath variables in predicates (#31).
cmlenz
parents:
175
diff
changeset
|
544 tmpl = Template("""<div xmlns:py="http://markup.edgewall.org/"> |
a2e0a7986d19
Implemented support for XPath variables in predicates (#31).
cmlenz
parents:
175
diff
changeset
|
545 <span py:match="*[name()=$tagname]"> |
a2e0a7986d19
Implemented support for XPath variables in predicates (#31).
cmlenz
parents:
175
diff
changeset
|
546 Hello ${select('@name')} |
a2e0a7986d19
Implemented support for XPath variables in predicates (#31).
cmlenz
parents:
175
diff
changeset
|
547 </span> |
a2e0a7986d19
Implemented support for XPath variables in predicates (#31).
cmlenz
parents:
175
diff
changeset
|
548 <greeting name="Dude"/> |
a2e0a7986d19
Implemented support for XPath variables in predicates (#31).
cmlenz
parents:
175
diff
changeset
|
549 </div>""") |
a2e0a7986d19
Implemented support for XPath variables in predicates (#31).
cmlenz
parents:
175
diff
changeset
|
550 self.assertEqual("""<div> |
a2e0a7986d19
Implemented support for XPath variables in predicates (#31).
cmlenz
parents:
175
diff
changeset
|
551 <span> |
a2e0a7986d19
Implemented support for XPath variables in predicates (#31).
cmlenz
parents:
175
diff
changeset
|
552 Hello Dude |
a2e0a7986d19
Implemented support for XPath variables in predicates (#31).
cmlenz
parents:
175
diff
changeset
|
553 </span> |
a2e0a7986d19
Implemented support for XPath variables in predicates (#31).
cmlenz
parents:
175
diff
changeset
|
554 </div>""", str(tmpl.generate(tagname='greeting'))) |
a2e0a7986d19
Implemented support for XPath variables in predicates (#31).
cmlenz
parents:
175
diff
changeset
|
555 self.assertEqual("""<div> |
a2e0a7986d19
Implemented support for XPath variables in predicates (#31).
cmlenz
parents:
175
diff
changeset
|
556 <greeting name="Dude"/> |
a2e0a7986d19
Implemented support for XPath variables in predicates (#31).
cmlenz
parents:
175
diff
changeset
|
557 </div>""", str(tmpl.generate(tagname='sayhello'))) |
a2e0a7986d19
Implemented support for XPath variables in predicates (#31).
cmlenz
parents:
175
diff
changeset
|
558 |
184
e27a48802987
Interpolate multiline expressions in templates. Thanks to Christian Boos for reporting the problem and providing the fix.
cmlenz
parents:
181
diff
changeset
|
559 # FIXME |
e27a48802987
Interpolate multiline expressions in templates. Thanks to Christian Boos for reporting the problem and providing the fix.
cmlenz
parents:
181
diff
changeset
|
560 #def test_match_after_step(self): |
e27a48802987
Interpolate multiline expressions in templates. Thanks to Christian Boos for reporting the problem and providing the fix.
cmlenz
parents:
181
diff
changeset
|
561 # tmpl = Template("""<div xmlns:py="http://markup.edgewall.org/"> |
e27a48802987
Interpolate multiline expressions in templates. Thanks to Christian Boos for reporting the problem and providing the fix.
cmlenz
parents:
181
diff
changeset
|
562 # <span py:match="div/greeting"> |
e27a48802987
Interpolate multiline expressions in templates. Thanks to Christian Boos for reporting the problem and providing the fix.
cmlenz
parents:
181
diff
changeset
|
563 # Hello ${select('@name')} |
e27a48802987
Interpolate multiline expressions in templates. Thanks to Christian Boos for reporting the problem and providing the fix.
cmlenz
parents:
181
diff
changeset
|
564 # </span> |
e27a48802987
Interpolate multiline expressions in templates. Thanks to Christian Boos for reporting the problem and providing the fix.
cmlenz
parents:
181
diff
changeset
|
565 # <greeting name="Dude" /> |
e27a48802987
Interpolate multiline expressions in templates. Thanks to Christian Boos for reporting the problem and providing the fix.
cmlenz
parents:
181
diff
changeset
|
566 # </div>""") |
e27a48802987
Interpolate multiline expressions in templates. Thanks to Christian Boos for reporting the problem and providing the fix.
cmlenz
parents:
181
diff
changeset
|
567 # self.assertEqual("""<div> |
e27a48802987
Interpolate multiline expressions in templates. Thanks to Christian Boos for reporting the problem and providing the fix.
cmlenz
parents:
181
diff
changeset
|
568 # <span> |
e27a48802987
Interpolate multiline expressions in templates. Thanks to Christian Boos for reporting the problem and providing the fix.
cmlenz
parents:
181
diff
changeset
|
569 # Hello Dude |
e27a48802987
Interpolate multiline expressions in templates. Thanks to Christian Boos for reporting the problem and providing the fix.
cmlenz
parents:
181
diff
changeset
|
570 # </span> |
e27a48802987
Interpolate multiline expressions in templates. Thanks to Christian Boos for reporting the problem and providing the fix.
cmlenz
parents:
181
diff
changeset
|
571 # </div>""", str(tmpl.generate())) |
e27a48802987
Interpolate multiline expressions in templates. Thanks to Christian Boos for reporting the problem and providing the fix.
cmlenz
parents:
181
diff
changeset
|
572 |
36
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
573 |
37
224b0b41d1da
Moved some of the tests for the strip directive to a new unittest test case to not clutter up the documentation.
cmlenz
parents:
36
diff
changeset
|
574 class StripDirectiveTestCase(unittest.TestCase): |
224b0b41d1da
Moved some of the tests for the strip directive to a new unittest test case to not clutter up the documentation.
cmlenz
parents:
36
diff
changeset
|
575 """Tests for the `py:strip` template directive.""" |
224b0b41d1da
Moved some of the tests for the strip directive to a new unittest test case to not clutter up the documentation.
cmlenz
parents:
36
diff
changeset
|
576 |
224b0b41d1da
Moved some of the tests for the strip directive to a new unittest test case to not clutter up the documentation.
cmlenz
parents:
36
diff
changeset
|
577 def test_strip_false(self): |
61 | 578 tmpl = Template("""<div xmlns:py="http://markup.edgewall.org/"> |
37
224b0b41d1da
Moved some of the tests for the strip directive to a new unittest test case to not clutter up the documentation.
cmlenz
parents:
36
diff
changeset
|
579 <div py:strip="False"><b>foo</b></div> |
224b0b41d1da
Moved some of the tests for the strip directive to a new unittest test case to not clutter up the documentation.
cmlenz
parents:
36
diff
changeset
|
580 </div>""") |
224b0b41d1da
Moved some of the tests for the strip directive to a new unittest test case to not clutter up the documentation.
cmlenz
parents:
36
diff
changeset
|
581 self.assertEqual("""<div> |
224b0b41d1da
Moved some of the tests for the strip directive to a new unittest test case to not clutter up the documentation.
cmlenz
parents:
36
diff
changeset
|
582 <div><b>foo</b></div> |
224b0b41d1da
Moved some of the tests for the strip directive to a new unittest test case to not clutter up the documentation.
cmlenz
parents:
36
diff
changeset
|
583 </div>""", str(tmpl.generate())) |
224b0b41d1da
Moved some of the tests for the strip directive to a new unittest test case to not clutter up the documentation.
cmlenz
parents:
36
diff
changeset
|
584 |
224b0b41d1da
Moved some of the tests for the strip directive to a new unittest test case to not clutter up the documentation.
cmlenz
parents:
36
diff
changeset
|
585 def test_strip_empty(self): |
61 | 586 tmpl = Template("""<div xmlns:py="http://markup.edgewall.org/"> |
37
224b0b41d1da
Moved some of the tests for the strip directive to a new unittest test case to not clutter up the documentation.
cmlenz
parents:
36
diff
changeset
|
587 <div py:strip=""><b>foo</b></div> |
224b0b41d1da
Moved some of the tests for the strip directive to a new unittest test case to not clutter up the documentation.
cmlenz
parents:
36
diff
changeset
|
588 </div>""") |
224b0b41d1da
Moved some of the tests for the strip directive to a new unittest test case to not clutter up the documentation.
cmlenz
parents:
36
diff
changeset
|
589 self.assertEqual("""<div> |
224b0b41d1da
Moved some of the tests for the strip directive to a new unittest test case to not clutter up the documentation.
cmlenz
parents:
36
diff
changeset
|
590 <b>foo</b> |
224b0b41d1da
Moved some of the tests for the strip directive to a new unittest test case to not clutter up the documentation.
cmlenz
parents:
36
diff
changeset
|
591 </div>""", str(tmpl.generate())) |
224b0b41d1da
Moved some of the tests for the strip directive to a new unittest test case to not clutter up the documentation.
cmlenz
parents:
36
diff
changeset
|
592 |
224b0b41d1da
Moved some of the tests for the strip directive to a new unittest test case to not clutter up the documentation.
cmlenz
parents:
36
diff
changeset
|
593 |
104
e9259920db05
Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents:
90
diff
changeset
|
594 class WithDirectiveTestCase(unittest.TestCase): |
e9259920db05
Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents:
90
diff
changeset
|
595 """Tests for the `py:with` template directive.""" |
e9259920db05
Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents:
90
diff
changeset
|
596 |
e9259920db05
Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents:
90
diff
changeset
|
597 def test_shadowing(self): |
e9259920db05
Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents:
90
diff
changeset
|
598 tmpl = Template("""<div xmlns:py="http://markup.edgewall.org/"> |
e9259920db05
Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents:
90
diff
changeset
|
599 ${x} |
e9259920db05
Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents:
90
diff
changeset
|
600 <span py:with="x = x * 2" py:replace="x"/> |
e9259920db05
Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents:
90
diff
changeset
|
601 ${x} |
e9259920db05
Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents:
90
diff
changeset
|
602 </div>""") |
e9259920db05
Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents:
90
diff
changeset
|
603 self.assertEqual("""<div> |
e9259920db05
Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents:
90
diff
changeset
|
604 42 |
e9259920db05
Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents:
90
diff
changeset
|
605 84 |
e9259920db05
Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents:
90
diff
changeset
|
606 42 |
149
7306bf730ff3
`Template.generate()` now accepts the context data as keyword arguments, so that you don't have to import the `Context` class every time you want to pass data into a template.
cmlenz
parents:
145
diff
changeset
|
607 </div>""", str(tmpl.generate(x=42))) |
104
e9259920db05
Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents:
90
diff
changeset
|
608 |
e9259920db05
Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents:
90
diff
changeset
|
609 def test_as_element(self): |
e9259920db05
Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents:
90
diff
changeset
|
610 tmpl = Template("""<div xmlns:py="http://markup.edgewall.org/"> |
e9259920db05
Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents:
90
diff
changeset
|
611 <py:with vars="x = x * 2">${x}</py:with> |
e9259920db05
Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents:
90
diff
changeset
|
612 </div>""") |
e9259920db05
Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents:
90
diff
changeset
|
613 self.assertEqual("""<div> |
e9259920db05
Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents:
90
diff
changeset
|
614 84 |
149
7306bf730ff3
`Template.generate()` now accepts the context data as keyword arguments, so that you don't have to import the `Context` class every time you want to pass data into a template.
cmlenz
parents:
145
diff
changeset
|
615 </div>""", str(tmpl.generate(x=42))) |
104
e9259920db05
Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents:
90
diff
changeset
|
616 |
190 | 617 def test_multiple_vars_same_name(self): |
618 tmpl = Template("""<div xmlns:py="http://markup.edgewall.org/"> | |
619 <py:with vars=" | |
620 foo = 'bar'; | |
621 foo = foo.replace('r', 'z') | |
622 "> | |
623 $foo | |
624 </py:with> | |
625 </div>""") | |
626 self.assertEqual("""<div> | |
627 baz | |
628 </div>""", str(tmpl.generate(x=42))) | |
629 | |
630 def test_multiple_vars_single_assignment(self): | |
631 tmpl = Template("""<div xmlns:py="http://markup.edgewall.org/"> | |
632 <py:with vars="x = y = z = 1">${x} ${y} ${z}</py:with> | |
633 </div>""") | |
634 self.assertEqual("""<div> | |
635 1 1 1 | |
636 </div>""", str(tmpl.generate(x=42))) | |
637 | |
638 def test_multiple_vars_trailing_semicolon(self): | |
639 tmpl = Template("""<div xmlns:py="http://markup.edgewall.org/"> | |
640 <py:with vars="x = x * 2; y = x / 2;">${x} ${y}</py:with> | |
641 </div>""") | |
642 self.assertEqual("""<div> | |
643 84 42 | |
644 </div>""", str(tmpl.generate(x=42))) | |
645 | |
646 def test_semicolon_escape(self): | |
647 tmpl = Template("""<div xmlns:py="http://markup.edgewall.org/"> | |
648 <py:with vars="x = 'here is a semicolon: ;'; y = 'here are two semicolons: ;;' ;"> | |
649 ${x} | |
650 ${y} | |
651 </py:with> | |
652 </div>""") | |
653 self.assertEqual("""<div> | |
654 here is a semicolon: ; | |
655 here are two semicolons: ;; | |
656 </div>""", str(tmpl.generate())) | |
657 | |
104
e9259920db05
Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents:
90
diff
changeset
|
658 |
1 | 659 class TemplateTestCase(unittest.TestCase): |
36
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
660 """Tests for basic template processing, expression evaluation and error |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
661 reporting. |
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
662 """ |
1 | 663 |
664 def test_interpolate_string(self): | |
665 parts = list(Template._interpolate('bla')) | |
666 self.assertEqual(1, len(parts)) | |
667 self.assertEqual(Stream.TEXT, parts[0][0]) | |
668 self.assertEqual('bla', parts[0][1]) | |
669 | |
670 def test_interpolate_simple(self): | |
671 parts = list(Template._interpolate('${bla}')) | |
672 self.assertEqual(1, len(parts)) | |
10
c5890ef863ba
Moved the template-specific stream event kinds into the template module.
cmlenz
parents:
1
diff
changeset
|
673 self.assertEqual(Template.EXPR, parts[0][0]) |
1 | 674 self.assertEqual('bla', parts[0][1].source) |
675 | |
676 def test_interpolate_escaped(self): | |
677 parts = list(Template._interpolate('$${bla}')) | |
678 self.assertEqual(1, len(parts)) | |
679 self.assertEqual(Stream.TEXT, parts[0][0]) | |
680 self.assertEqual('${bla}', parts[0][1]) | |
681 | |
682 def test_interpolate_short(self): | |
683 parts = list(Template._interpolate('$bla')) | |
684 self.assertEqual(1, len(parts)) | |
10
c5890ef863ba
Moved the template-specific stream event kinds into the template module.
cmlenz
parents:
1
diff
changeset
|
685 self.assertEqual(Template.EXPR, parts[0][0]) |
1 | 686 self.assertEqual('bla', parts[0][1].source) |
687 | |
688 def test_interpolate_mixed1(self): | |
689 parts = list(Template._interpolate('$foo bar $baz')) | |
690 self.assertEqual(3, len(parts)) | |
10
c5890ef863ba
Moved the template-specific stream event kinds into the template module.
cmlenz
parents:
1
diff
changeset
|
691 self.assertEqual(Template.EXPR, parts[0][0]) |
1 | 692 self.assertEqual('foo', parts[0][1].source) |
693 self.assertEqual(Stream.TEXT, parts[1][0]) | |
694 self.assertEqual(' bar ', parts[1][1]) | |
10
c5890ef863ba
Moved the template-specific stream event kinds into the template module.
cmlenz
parents:
1
diff
changeset
|
695 self.assertEqual(Template.EXPR, parts[2][0]) |
1 | 696 self.assertEqual('baz', parts[2][1].source) |
697 | |
698 def test_interpolate_mixed2(self): | |
699 parts = list(Template._interpolate('foo $bar baz')) | |
700 self.assertEqual(3, len(parts)) | |
701 self.assertEqual(Stream.TEXT, parts[0][0]) | |
702 self.assertEqual('foo ', parts[0][1]) | |
10
c5890ef863ba
Moved the template-specific stream event kinds into the template module.
cmlenz
parents:
1
diff
changeset
|
703 self.assertEqual(Template.EXPR, parts[1][0]) |
1 | 704 self.assertEqual('bar', parts[1][1].source) |
705 self.assertEqual(Stream.TEXT, parts[2][0]) | |
706 self.assertEqual(' baz', parts[2][1]) | |
707 | |
74
3c271699c398
Fix expression interpolation where both shorthand notation and full notation are used inside a single text node. Thanks Jonas.
cmlenz
parents:
66
diff
changeset
|
708 def test_interpolate_mixed3(self): |
3c271699c398
Fix expression interpolation where both shorthand notation and full notation are used inside a single text node. Thanks Jonas.
cmlenz
parents:
66
diff
changeset
|
709 tmpl = Template('<root> ${var} $var</root>') |
149
7306bf730ff3
`Template.generate()` now accepts the context data as keyword arguments, so that you don't have to import the `Context` class every time you want to pass data into a template.
cmlenz
parents:
145
diff
changeset
|
710 self.assertEqual('<root> 42 42</root>', str(tmpl.generate(var=42))) |
74
3c271699c398
Fix expression interpolation where both shorthand notation and full notation are used inside a single text node. Thanks Jonas.
cmlenz
parents:
66
diff
changeset
|
711 |
191
929ef2913b87
Allow leading whitespace in expressions. Closes #38. Thanks to Christian Boos for the patch!
cmlenz
parents:
190
diff
changeset
|
712 def test_interpolate_leading_trailing_space(self): |
929ef2913b87
Allow leading whitespace in expressions. Closes #38. Thanks to Christian Boos for the patch!
cmlenz
parents:
190
diff
changeset
|
713 tmpl = Template('<root>${ foo }</root>') |
929ef2913b87
Allow leading whitespace in expressions. Closes #38. Thanks to Christian Boos for the patch!
cmlenz
parents:
190
diff
changeset
|
714 self.assertEqual('<root>bar</root>', str(tmpl.generate(foo='bar'))) |
929ef2913b87
Allow leading whitespace in expressions. Closes #38. Thanks to Christian Boos for the patch!
cmlenz
parents:
190
diff
changeset
|
715 |
184
e27a48802987
Interpolate multiline expressions in templates. Thanks to Christian Boos for reporting the problem and providing the fix.
cmlenz
parents:
181
diff
changeset
|
716 def test_interpolate_multiline(self): |
e27a48802987
Interpolate multiline expressions in templates. Thanks to Christian Boos for reporting the problem and providing the fix.
cmlenz
parents:
181
diff
changeset
|
717 tmpl = Template("""<root>${dict( |
e27a48802987
Interpolate multiline expressions in templates. Thanks to Christian Boos for reporting the problem and providing the fix.
cmlenz
parents:
181
diff
changeset
|
718 bar = 'baz' |
e27a48802987
Interpolate multiline expressions in templates. Thanks to Christian Boos for reporting the problem and providing the fix.
cmlenz
parents:
181
diff
changeset
|
719 )[foo]}</root>""") |
e27a48802987
Interpolate multiline expressions in templates. Thanks to Christian Boos for reporting the problem and providing the fix.
cmlenz
parents:
181
diff
changeset
|
720 self.assertEqual('<root>baz</root>', str(tmpl.generate(foo='bar'))) |
e27a48802987
Interpolate multiline expressions in templates. Thanks to Christian Boos for reporting the problem and providing the fix.
cmlenz
parents:
181
diff
changeset
|
721 |
48
06c642ba2b08
convert the result of expressions in attributes to strings so that values like ints are output correctly
mgood
parents:
37
diff
changeset
|
722 def test_interpolate_non_string_attrs(self): |
06c642ba2b08
convert the result of expressions in attributes to strings so that values like ints are output correctly
mgood
parents:
37
diff
changeset
|
723 tmpl = Template('<root attr="${1}"/>') |
75
c3c26300a46d
Empty attributes in templates were being stripped out. Thanks to Jonas for the patch.
cmlenz
parents:
74
diff
changeset
|
724 self.assertEqual('<root attr="1"/>', str(tmpl.generate())) |
c3c26300a46d
Empty attributes in templates were being stripped out. Thanks to Jonas for the patch.
cmlenz
parents:
74
diff
changeset
|
725 |
145
56d534eb53f9
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
134
diff
changeset
|
726 def test_interpolate_list_result(self): |
56d534eb53f9
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
134
diff
changeset
|
727 tmpl = Template('<root>$foo</root>') |
149
7306bf730ff3
`Template.generate()` now accepts the context data as keyword arguments, so that you don't have to import the `Context` class every time you want to pass data into a template.
cmlenz
parents:
145
diff
changeset
|
728 self.assertEqual('<root>buzz</root>', str(tmpl.generate(foo=('buzz',)))) |
145
56d534eb53f9
* Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents:
134
diff
changeset
|
729 |
75
c3c26300a46d
Empty attributes in templates were being stripped out. Thanks to Jonas for the patch.
cmlenz
parents:
74
diff
changeset
|
730 def test_empty_attr(self): |
c3c26300a46d
Empty attributes in templates were being stripped out. Thanks to Jonas for the patch.
cmlenz
parents:
74
diff
changeset
|
731 tmpl = Template('<root attr=""/>') |
c3c26300a46d
Empty attributes in templates were being stripped out. Thanks to Jonas for the patch.
cmlenz
parents:
74
diff
changeset
|
732 self.assertEqual('<root attr=""/>', str(tmpl.generate())) |
48
06c642ba2b08
convert the result of expressions in attributes to strings so that values like ints are output correctly
mgood
parents:
37
diff
changeset
|
733 |
1 | 734 def test_bad_directive_error(self): |
61 | 735 xml = '<p xmlns:py="http://markup.edgewall.org/" py:do="nothing" />' |
1 | 736 try: |
21
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
10
diff
changeset
|
737 tmpl = Template(xml, filename='test.html') |
1 | 738 except BadDirectiveError, e: |
739 self.assertEqual('test.html', e.filename) | |
740 if sys.version_info[:2] >= (2, 4): | |
741 self.assertEqual(1, e.lineno) | |
742 | |
743 def test_directive_value_syntax_error(self): | |
81
cc034182061e
Template expressions are now compiled to Python bytecode.
cmlenz
parents:
77
diff
changeset
|
744 xml = """<p xmlns:py="http://markup.edgewall.org/" py:if="bar'" />""" |
1 | 745 try: |
81
cc034182061e
Template expressions are now compiled to Python bytecode.
cmlenz
parents:
77
diff
changeset
|
746 tmpl = Template(xml, filename='test.html') |
1 | 747 self.fail('Expected SyntaxError') |
748 except TemplateSyntaxError, e: | |
749 self.assertEqual('test.html', e.filename) | |
750 if sys.version_info[:2] >= (2, 4): | |
751 self.assertEqual(1, e.lineno) | |
752 | |
753 def test_expression_syntax_error(self): | |
81
cc034182061e
Template expressions are now compiled to Python bytecode.
cmlenz
parents:
77
diff
changeset
|
754 xml = """<p> |
cc034182061e
Template expressions are now compiled to Python bytecode.
cmlenz
parents:
77
diff
changeset
|
755 Foo <em>${bar"}</em> |
cc034182061e
Template expressions are now compiled to Python bytecode.
cmlenz
parents:
77
diff
changeset
|
756 </p>""" |
1 | 757 try: |
81
cc034182061e
Template expressions are now compiled to Python bytecode.
cmlenz
parents:
77
diff
changeset
|
758 tmpl = Template(xml, filename='test.html') |
1 | 759 self.fail('Expected SyntaxError') |
760 except TemplateSyntaxError, e: | |
761 self.assertEqual('test.html', e.filename) | |
762 if sys.version_info[:2] >= (2, 4): | |
763 self.assertEqual(2, e.lineno) | |
764 | |
134
df44110ca91d
* Improve the accuracy of line numbers for text nodes, so that reported errors about syntax or evaluation errors in expressions point to the right line (not quite perfect yet, though).
cmlenz
parents:
104
diff
changeset
|
765 def test_expression_syntax_error_multi_line(self): |
df44110ca91d
* Improve the accuracy of line numbers for text nodes, so that reported errors about syntax or evaluation errors in expressions point to the right line (not quite perfect yet, though).
cmlenz
parents:
104
diff
changeset
|
766 xml = """<p><em></em> |
df44110ca91d
* Improve the accuracy of line numbers for text nodes, so that reported errors about syntax or evaluation errors in expressions point to the right line (not quite perfect yet, though).
cmlenz
parents:
104
diff
changeset
|
767 |
df44110ca91d
* Improve the accuracy of line numbers for text nodes, so that reported errors about syntax or evaluation errors in expressions point to the right line (not quite perfect yet, though).
cmlenz
parents:
104
diff
changeset
|
768 ${bar"} |
df44110ca91d
* Improve the accuracy of line numbers for text nodes, so that reported errors about syntax or evaluation errors in expressions point to the right line (not quite perfect yet, though).
cmlenz
parents:
104
diff
changeset
|
769 |
df44110ca91d
* Improve the accuracy of line numbers for text nodes, so that reported errors about syntax or evaluation errors in expressions point to the right line (not quite perfect yet, though).
cmlenz
parents:
104
diff
changeset
|
770 </p>""" |
df44110ca91d
* Improve the accuracy of line numbers for text nodes, so that reported errors about syntax or evaluation errors in expressions point to the right line (not quite perfect yet, though).
cmlenz
parents:
104
diff
changeset
|
771 try: |
df44110ca91d
* Improve the accuracy of line numbers for text nodes, so that reported errors about syntax or evaluation errors in expressions point to the right line (not quite perfect yet, though).
cmlenz
parents:
104
diff
changeset
|
772 tmpl = Template(xml, filename='test.html') |
df44110ca91d
* Improve the accuracy of line numbers for text nodes, so that reported errors about syntax or evaluation errors in expressions point to the right line (not quite perfect yet, though).
cmlenz
parents:
104
diff
changeset
|
773 self.fail('Expected SyntaxError') |
df44110ca91d
* Improve the accuracy of line numbers for text nodes, so that reported errors about syntax or evaluation errors in expressions point to the right line (not quite perfect yet, though).
cmlenz
parents:
104
diff
changeset
|
774 except TemplateSyntaxError, e: |
df44110ca91d
* Improve the accuracy of line numbers for text nodes, so that reported errors about syntax or evaluation errors in expressions point to the right line (not quite perfect yet, though).
cmlenz
parents:
104
diff
changeset
|
775 self.assertEqual('test.html', e.filename) |
df44110ca91d
* Improve the accuracy of line numbers for text nodes, so that reported errors about syntax or evaluation errors in expressions point to the right line (not quite perfect yet, though).
cmlenz
parents:
104
diff
changeset
|
776 if sys.version_info[:2] >= (2, 4): |
df44110ca91d
* Improve the accuracy of line numbers for text nodes, so that reported errors about syntax or evaluation errors in expressions point to the right line (not quite perfect yet, though).
cmlenz
parents:
104
diff
changeset
|
777 self.assertEqual(3, e.lineno) |
df44110ca91d
* Improve the accuracy of line numbers for text nodes, so that reported errors about syntax or evaluation errors in expressions point to the right line (not quite perfect yet, though).
cmlenz
parents:
104
diff
changeset
|
778 |
54 | 779 def test_markup_noescape(self): |
780 """ | |
781 Verify that outputting context data that is a `Markup` instance is not | |
782 escaped. | |
783 """ | |
61 | 784 tmpl = Template("""<div xmlns:py="http://markup.edgewall.org/"> |
54 | 785 $myvar |
786 </div>""") | |
787 self.assertEqual("""<div> | |
788 <b>foo</b> | |
149
7306bf730ff3
`Template.generate()` now accepts the context data as keyword arguments, so that you don't have to import the `Context` class every time you want to pass data into a template.
cmlenz
parents:
145
diff
changeset
|
789 </div>""", str(tmpl.generate(myvar=Markup('<b>foo</b>')))) |
54 | 790 |
791 def test_text_noescape_quotes(self): | |
792 """ | |
793 Verify that outputting context data in text nodes doesn't escape quotes. | |
794 """ | |
61 | 795 tmpl = Template("""<div xmlns:py="http://markup.edgewall.org/"> |
54 | 796 $myvar |
797 </div>""") | |
798 self.assertEqual("""<div> | |
799 "foo" | |
149
7306bf730ff3
`Template.generate()` now accepts the context data as keyword arguments, so that you don't have to import the `Context` class every time you want to pass data into a template.
cmlenz
parents:
145
diff
changeset
|
800 </div>""", str(tmpl.generate(myvar='"foo"'))) |
54 | 801 |
802 def test_attr_escape_quotes(self): | |
803 """ | |
804 Verify that outputting context data in attribtes escapes quotes. | |
805 """ | |
61 | 806 tmpl = Template("""<div xmlns:py="http://markup.edgewall.org/"> |
54 | 807 <elem class="$myvar"/> |
808 </div>""") | |
809 self.assertEqual("""<div> | |
810 <elem class=""foo""/> | |
149
7306bf730ff3
`Template.generate()` now accepts the context data as keyword arguments, so that you don't have to import the `Context` class every time you want to pass data into a template.
cmlenz
parents:
145
diff
changeset
|
811 </div>""", str(tmpl.generate(myvar='"foo"'))) |
54 | 812 |
65
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
813 def test_directive_element(self): |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
814 tmpl = Template("""<div xmlns:py="http://markup.edgewall.org/"> |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
815 <py:if test="myvar">bar</py:if> |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
816 </div>""") |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
817 self.assertEqual("""<div> |
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
818 bar |
149
7306bf730ff3
`Template.generate()` now accepts the context data as keyword arguments, so that you don't have to import the `Context` class every time you want to pass data into a template.
cmlenz
parents:
145
diff
changeset
|
819 </div>""", str(tmpl.generate(myvar='"foo"'))) |
65
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
820 |
89
d4c7617900e3
Support comments in templates that are not included in the output, in the same way Kid does: if the comment text starts with a `!` character, it is stripped from the output.
cmlenz
parents:
81
diff
changeset
|
821 def test_normal_comment(self): |
d4c7617900e3
Support comments in templates that are not included in the output, in the same way Kid does: if the comment text starts with a `!` character, it is stripped from the output.
cmlenz
parents:
81
diff
changeset
|
822 tmpl = Template("""<div xmlns:py="http://markup.edgewall.org/"> |
d4c7617900e3
Support comments in templates that are not included in the output, in the same way Kid does: if the comment text starts with a `!` character, it is stripped from the output.
cmlenz
parents:
81
diff
changeset
|
823 <!-- foo bar --> |
d4c7617900e3
Support comments in templates that are not included in the output, in the same way Kid does: if the comment text starts with a `!` character, it is stripped from the output.
cmlenz
parents:
81
diff
changeset
|
824 </div>""") |
d4c7617900e3
Support comments in templates that are not included in the output, in the same way Kid does: if the comment text starts with a `!` character, it is stripped from the output.
cmlenz
parents:
81
diff
changeset
|
825 self.assertEqual("""<div> |
d4c7617900e3
Support comments in templates that are not included in the output, in the same way Kid does: if the comment text starts with a `!` character, it is stripped from the output.
cmlenz
parents:
81
diff
changeset
|
826 <!-- foo bar --> |
d4c7617900e3
Support comments in templates that are not included in the output, in the same way Kid does: if the comment text starts with a `!` character, it is stripped from the output.
cmlenz
parents:
81
diff
changeset
|
827 </div>""", str(tmpl.generate())) |
d4c7617900e3
Support comments in templates that are not included in the output, in the same way Kid does: if the comment text starts with a `!` character, it is stripped from the output.
cmlenz
parents:
81
diff
changeset
|
828 |
d4c7617900e3
Support comments in templates that are not included in the output, in the same way Kid does: if the comment text starts with a `!` character, it is stripped from the output.
cmlenz
parents:
81
diff
changeset
|
829 def test_template_comment(self): |
d4c7617900e3
Support comments in templates that are not included in the output, in the same way Kid does: if the comment text starts with a `!` character, it is stripped from the output.
cmlenz
parents:
81
diff
changeset
|
830 tmpl = Template("""<div xmlns:py="http://markup.edgewall.org/"> |
d4c7617900e3
Support comments in templates that are not included in the output, in the same way Kid does: if the comment text starts with a `!` character, it is stripped from the output.
cmlenz
parents:
81
diff
changeset
|
831 <!-- !foo --> |
d4c7617900e3
Support comments in templates that are not included in the output, in the same way Kid does: if the comment text starts with a `!` character, it is stripped from the output.
cmlenz
parents:
81
diff
changeset
|
832 <!--!bar--> |
d4c7617900e3
Support comments in templates that are not included in the output, in the same way Kid does: if the comment text starts with a `!` character, it is stripped from the output.
cmlenz
parents:
81
diff
changeset
|
833 </div>""") |
d4c7617900e3
Support comments in templates that are not included in the output, in the same way Kid does: if the comment text starts with a `!` character, it is stripped from the output.
cmlenz
parents:
81
diff
changeset
|
834 self.assertEqual("""<div> |
d4c7617900e3
Support comments in templates that are not included in the output, in the same way Kid does: if the comment text starts with a `!` character, it is stripped from the output.
cmlenz
parents:
81
diff
changeset
|
835 </div>""", str(tmpl.generate())) |
d4c7617900e3
Support comments in templates that are not included in the output, in the same way Kid does: if the comment text starts with a `!` character, it is stripped from the output.
cmlenz
parents:
81
diff
changeset
|
836 |
1 | 837 |
152
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
838 class TemplateLoaderTestCase(unittest.TestCase): |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
839 """Tests for the template loader.""" |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
840 |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
841 def setUp(self): |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
842 self.dirname = tempfile.mkdtemp(suffix='markup_test') |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
843 |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
844 def tearDown(self): |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
845 shutil.rmtree(self.dirname) |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
846 |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
847 def test_relative_include_samedir(self): |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
848 file1 = open(os.path.join(self.dirname, 'tmpl1.html'), 'w') |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
849 try: |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
850 file1.write("""<div>Included</div>""") |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
851 finally: |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
852 file1.close() |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
853 |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
854 file2 = open(os.path.join(self.dirname, 'tmpl2.html'), 'w') |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
855 try: |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
856 file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude"> |
158
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
154
diff
changeset
|
857 <xi:include href="tmpl1.html" /> |
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
154
diff
changeset
|
858 </html>""") |
152
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
859 finally: |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
860 file2.close() |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
861 |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
862 loader = TemplateLoader([self.dirname]) |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
863 tmpl = loader.load('tmpl2.html') |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
864 self.assertEqual("""<html> |
158
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
154
diff
changeset
|
865 <div>Included</div> |
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
154
diff
changeset
|
866 </html>""", tmpl.generate().render()) |
152
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
867 |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
868 def test_relative_include_subdir(self): |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
869 os.mkdir(os.path.join(self.dirname, 'sub')) |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
870 file1 = open(os.path.join(self.dirname, 'sub', 'tmpl1.html'), 'w') |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
871 try: |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
872 file1.write("""<div>Included</div>""") |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
873 finally: |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
874 file1.close() |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
875 |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
876 file2 = open(os.path.join(self.dirname, 'tmpl2.html'), 'w') |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
877 try: |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
878 file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude"> |
158
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
154
diff
changeset
|
879 <xi:include href="sub/tmpl1.html" /> |
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
154
diff
changeset
|
880 </html>""") |
152
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
881 finally: |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
882 file2.close() |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
883 |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
884 loader = TemplateLoader([self.dirname]) |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
885 tmpl = loader.load('tmpl2.html') |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
886 self.assertEqual("""<html> |
158
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
154
diff
changeset
|
887 <div>Included</div> |
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
154
diff
changeset
|
888 </html>""", tmpl.generate().render()) |
152
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
889 |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
890 def test_relative_include_parentdir(self): |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
891 file1 = open(os.path.join(self.dirname, 'tmpl1.html'), 'w') |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
892 try: |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
893 file1.write("""<div>Included</div>""") |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
894 finally: |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
895 file1.close() |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
896 |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
897 os.mkdir(os.path.join(self.dirname, 'sub')) |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
898 file2 = open(os.path.join(self.dirname, 'sub', 'tmpl2.html'), 'w') |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
899 try: |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
900 file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude"> |
158
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
154
diff
changeset
|
901 <xi:include href="../tmpl1.html" /> |
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
154
diff
changeset
|
902 </html>""") |
152
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
903 finally: |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
904 file2.close() |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
905 |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
906 loader = TemplateLoader([self.dirname]) |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
907 tmpl = loader.load('sub/tmpl2.html') |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
908 self.assertEqual("""<html> |
158
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
154
diff
changeset
|
909 <div>Included</div> |
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
154
diff
changeset
|
910 </html>""", tmpl.generate().render()) |
152
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
911 |
174 | 912 def test_relative_include_without_search_path(self): |
913 file1 = open(os.path.join(self.dirname, 'tmpl1.html'), 'w') | |
914 try: | |
915 file1.write("""<div>Included</div>""") | |
916 finally: | |
917 file1.close() | |
918 | |
919 file2 = open(os.path.join(self.dirname, 'tmpl2.html'), 'w') | |
920 try: | |
921 file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude"> | |
922 <xi:include href="tmpl1.html" /> | |
923 </html>""") | |
924 finally: | |
925 file2.close() | |
926 | |
927 loader = TemplateLoader() | |
175 | 928 tmpl = loader.load(os.path.join(self.dirname, 'tmpl2.html')) |
174 | 929 self.assertEqual("""<html> |
930 <div>Included</div> | |
931 </html>""", tmpl.generate().render()) | |
932 | |
152
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
933 |
1 | 934 def suite(): |
935 suite = unittest.TestSuite() | |
936 suite.addTest(doctest.DocTestSuite(Template.__module__)) | |
50
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
937 suite.addTest(unittest.makeSuite(AttrsDirectiveTestCase, 'test')) |
53
60f1a556690e
* Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents:
51
diff
changeset
|
938 suite.addTest(unittest.makeSuite(ChooseDirectiveTestCase, 'test')) |
50
a053ffb834cb
Fix the way multiple directives are applied to a single `SUB` in many cases by making the directives themselves responsible for applying any remaining directives.
cmlenz
parents:
48
diff
changeset
|
939 suite.addTest(unittest.makeSuite(DefDirectiveTestCase, 'test')) |
51
a572b1018b66
Fix `py:for` directive when combined with other directives (such as `py:strip`).
cmlenz
parents:
50
diff
changeset
|
940 suite.addTest(unittest.makeSuite(ForDirectiveTestCase, 'test')) |
65
5c024cf58ecb
Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents:
61
diff
changeset
|
941 suite.addTest(unittest.makeSuite(IfDirectiveTestCase, 'test')) |
36
57d607f25484
Fix for #7: match templates no longer process their own output.
cmlenz
parents:
27
diff
changeset
|
942 suite.addTest(unittest.makeSuite(MatchDirectiveTestCase, 'test')) |
37
224b0b41d1da
Moved some of the tests for the strip directive to a new unittest test case to not clutter up the documentation.
cmlenz
parents:
36
diff
changeset
|
943 suite.addTest(unittest.makeSuite(StripDirectiveTestCase, 'test')) |
104
e9259920db05
Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents:
90
diff
changeset
|
944 suite.addTest(unittest.makeSuite(WithDirectiveTestCase, 'test')) |
152
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
945 suite.addTest(unittest.makeSuite(TemplateTestCase, 'test')) |
064ba1078f92
Add some tests for relative template includes (see #27).
cmlenz
parents:
149
diff
changeset
|
946 suite.addTest(unittest.makeSuite(TemplateLoaderTestCase, 'test')) |
1 | 947 return suite |
948 | |
949 if __name__ == '__main__': | |
950 unittest.main(defaultTest='suite') |