annotate markup/tests/template.py @ 149:537f819c547b trunk

`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.
author cmlenz
date Tue, 15 Aug 2006 21:59:07 +0000
parents 47bbd9d2a5af
children cdb2a1f930e2
rev   line source
1
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
1 # -*- coding: utf-8 -*-
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
2 #
66
59eb24184e9c Switch copyright to Edgewall and URLs to markup.edgewall.org.
cmlenz
parents: 65
diff changeset
3 # Copyright (C) 2006 Edgewall Software
1
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
4 # All rights reserved.
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
5 #
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
6 # This software is licensed as described in the file COPYING, which
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
7 # you should have received as part of this distribution. The terms
66
59eb24184e9c 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
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
9 #
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
10 # This software consists of voluntary contributions made by many
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
11 # individuals. For the exact contribution history, see the revision
66
59eb24184e9c 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
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
13
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
14 import doctest
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
15 import unittest
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
16 import sys
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
17
54
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
18 from markup.core import Markup, Stream
149
537f819c547b `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
19 from markup.template import BadDirectiveError, Template, TemplateSyntaxError
1
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
20
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
21
50
d3842cd76e92 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
22 class AttrsDirectiveTestCase(unittest.TestCase):
d3842cd76e92 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
23 """Tests for the `py:attrs` template directive."""
d3842cd76e92 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
24
d3842cd76e92 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
25 def test_combined_with_loop(self):
d3842cd76e92 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 """
d3842cd76e92 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 Verify that the directive has access to the loop variables.
d3842cd76e92 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 """
61
448792ab1303 Use a different namespace than Kid uses.
cmlenz
parents: 54
diff changeset
29 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/">
50
d3842cd76e92 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 <elem py:for="item in items" py:attrs="item"/>
d3842cd76e92 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 </doc>""")
d3842cd76e92 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 items = [{'id': 1, 'class': 'foo'}, {'id': 2, 'class': 'bar'}]
d3842cd76e92 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
33 self.assertEqual("""<doc>
d3842cd76e92 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 id="1" class="foo"/><elem id="2" class="bar"/>
149
537f819c547b `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
35 </doc>""", str(tmpl.generate(items=items)))
50
d3842cd76e92 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
54
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
37 def test_update_existing_attr(self):
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
38 """
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
39 Verify that an attribute value that evaluates to `None` removes an
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
40 existing attribute of that name.
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
41 """
61
448792ab1303 Use a different namespace than Kid uses.
cmlenz
parents: 54
diff changeset
42 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/">
54
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
43 <elem class="foo" py:attrs="{'class': 'bar'}"/>
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
44 </doc>""")
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
45 self.assertEqual("""<doc>
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
46 <elem class="bar"/>
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
47 </doc>""", str(tmpl.generate()))
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
48
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
49 def test_remove_existing_attr(self):
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
50 """
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
51 Verify that an attribute value that evaluates to `None` removes an
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
52 existing attribute of that name.
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
53 """
61
448792ab1303 Use a different namespace than Kid uses.
cmlenz
parents: 54
diff changeset
54 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/">
54
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
55 <elem class="foo" py:attrs="{'class': None}"/>
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
56 </doc>""")
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
57 self.assertEqual("""<doc>
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
58 <elem/>
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
59 </doc>""", str(tmpl.generate()))
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
60
50
d3842cd76e92 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
61
53
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
62 class ChooseDirectiveTestCase(unittest.TestCase):
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
63 """Tests for the `py:choose` template directive and the complementary
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
64 directives `py:when` and `py:otherwise`."""
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
65
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
66 def test_multiple_true_whens(self):
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
67 """
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
68 Verify that, if multiple `py:when` bodies match, only the first is
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
69 output.
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
70 """
61
448792ab1303 Use a different namespace than Kid uses.
cmlenz
parents: 54
diff changeset
71 tmpl = Template("""<div xmlns:py="http://markup.edgewall.org/" py:choose="">
53
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
72 <span py:when="1 == 1">1</span>
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
73 <span py:when="2 == 2">2</span>
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
74 <span py:when="3 == 3">3</span>
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
75 </div>""")
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
76 self.assertEqual("""<div>
512eb72dbb19 * 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>1</span>
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
78 </div>""", str(tmpl.generate()))
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
79
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
80 def test_otherwise(self):
61
448792ab1303 Use a different namespace than Kid uses.
cmlenz
parents: 54
diff changeset
81 tmpl = Template("""<div xmlns:py="http://markup.edgewall.org/" py:choose="">
53
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
82 <span py:when="False">hidden</span>
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
83 <span py:otherwise="">hello</span>
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
84 </div>""")
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
85 self.assertEqual("""<div>
512eb72dbb19 * 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>hello</span>
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
87 </div>""", str(tmpl.generate()))
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
88
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
89 def test_nesting(self):
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
90 """
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
91 Verify that `py:choose` blocks can be nested:
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
92 """
61
448792ab1303 Use a different namespace than Kid uses.
cmlenz
parents: 54
diff changeset
93 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/">
53
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
94 <div py:choose="1">
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
95 <div py:when="1" py:choose="3">
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
96 <span py:when="2">2</span>
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
97 <span py:when="3">3</span>
512eb72dbb19 * 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>
512eb72dbb19 * 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>
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
100 </doc>""")
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
101 self.assertEqual("""<doc>
512eb72dbb19 * 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>
512eb72dbb19 * 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>
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
104 <span>3</span>
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
105 </div>
512eb72dbb19 * 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>
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
107 </doc>""", str(tmpl.generate()))
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
108
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
109 def test_when_with_strip(self):
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
110 """
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
111 Verify that a when directive with a strip directive actually strips of
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
112 the outer element.
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
113 """
61
448792ab1303 Use a different namespace than Kid uses.
cmlenz
parents: 54
diff changeset
114 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/">
53
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
115 <div py:choose="" py:strip="">
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
116 <span py:otherwise="">foo</span>
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
117 </div>
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
118 </doc>""")
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
119 self.assertEqual("""<doc>
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
120 <span>foo</span>
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
121 </doc>""", str(tmpl.generate()))
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
122
65
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
123 def test_as_element(self):
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
124 """
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
125 Verify that the directive can also be used as an element.
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
126 """
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
127 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/">
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
128 <py:choose>
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
129 <py:when test="1 == 1">1</py:when>
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
130 <py:when test="2 == 2">2</py:when>
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
131 <py:when test="3 == 3">3</py:when>
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
132 </py:choose>
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
133 </doc>""")
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
134 self.assertEqual("""<doc>
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
135 1
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
136 </doc>""", str(tmpl.generate()))
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
137
53
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
138
50
d3842cd76e92 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
139 class DefDirectiveTestCase(unittest.TestCase):
d3842cd76e92 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
140 """Tests for the `py:def` template directive."""
d3842cd76e92 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
141
d3842cd76e92 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
142 def test_function_with_strip(self):
d3842cd76e92 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
143 """
53
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
144 Verify that a named template function with a strip directive actually
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
145 strips of the outer element.
50
d3842cd76e92 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
146 """
61
448792ab1303 Use a different namespace than Kid uses.
cmlenz
parents: 54
diff changeset
147 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/">
50
d3842cd76e92 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
148 <div py:def="echo(what)" py:strip="">
d3842cd76e92 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
149 <b>${what}</b>
d3842cd76e92 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
150 </div>
d3842cd76e92 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
151 ${echo('foo')}
d3842cd76e92 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
152 </doc>""")
d3842cd76e92 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
153 self.assertEqual("""<doc>
d3842cd76e92 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
154 <b>foo</b>
d3842cd76e92 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
155 </doc>""", str(tmpl.generate()))
d3842cd76e92 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
156
90
c835e81c50af When an expression evaluates to a callable, it is called implicitly.
cmlenz
parents: 89
diff changeset
157 def test_exec_in_replace(self):
c835e81c50af When an expression evaluates to a callable, it is called implicitly.
cmlenz
parents: 89
diff changeset
158 tmpl = Template("""<div xmlns:py="http://markup.edgewall.org/">
c835e81c50af When an expression evaluates to a callable, it is called implicitly.
cmlenz
parents: 89
diff changeset
159 <p py:def="echo(greeting, name='world')" class="message">
c835e81c50af When an expression evaluates to a callable, it is called implicitly.
cmlenz
parents: 89
diff changeset
160 ${greeting}, ${name}!
c835e81c50af When an expression evaluates to a callable, it is called implicitly.
cmlenz
parents: 89
diff changeset
161 </p>
c835e81c50af When an expression evaluates to a callable, it is called implicitly.
cmlenz
parents: 89
diff changeset
162 <div py:replace="echo('hello')"></div>
c835e81c50af When an expression evaluates to a callable, it is called implicitly.
cmlenz
parents: 89
diff changeset
163 </div>""")
c835e81c50af When an expression evaluates to a callable, it is called implicitly.
cmlenz
parents: 89
diff changeset
164 self.assertEqual("""<div>
c835e81c50af When an expression evaluates to a callable, it is called implicitly.
cmlenz
parents: 89
diff changeset
165 <p class="message">
c835e81c50af When an expression evaluates to a callable, it is called implicitly.
cmlenz
parents: 89
diff changeset
166 hello, world!
c835e81c50af When an expression evaluates to a callable, it is called implicitly.
cmlenz
parents: 89
diff changeset
167 </p>
c835e81c50af When an expression evaluates to a callable, it is called implicitly.
cmlenz
parents: 89
diff changeset
168 </div>""", str(tmpl.generate()))
c835e81c50af When an expression evaluates to a callable, it is called implicitly.
cmlenz
parents: 89
diff changeset
169
65
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
170 def test_as_element(self):
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
171 """
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
172 Verify that the directive can also be used as an element.
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
173 """
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
174 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/">
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
175 <py:def function="echo(what)">
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
176 <b>${what}</b>
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
177 </py:def>
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
178 ${echo('foo')}
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
179 </doc>""")
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
180 self.assertEqual("""<doc>
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
181 <b>foo</b>
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
182 </doc>""", str(tmpl.generate()))
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
183
50
d3842cd76e92 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
184
51
b2383634ec04 Fix `py:for` directive when combined with other directives (such as `py:strip`).
cmlenz
parents: 50
diff changeset
185 class ForDirectiveTestCase(unittest.TestCase):
53
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
186 """Tests for the `py:for` template directive."""
51
b2383634ec04 Fix `py:for` directive when combined with other directives (such as `py:strip`).
cmlenz
parents: 50
diff changeset
187
b2383634ec04 Fix `py:for` directive when combined with other directives (such as `py:strip`).
cmlenz
parents: 50
diff changeset
188 def test_loop_with_strip(self):
b2383634ec04 Fix `py:for` directive when combined with other directives (such as `py:strip`).
cmlenz
parents: 50
diff changeset
189 """
53
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
190 Verify that the combining the `py:for` directive with `py:strip` works
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
191 correctly.
51
b2383634ec04 Fix `py:for` directive when combined with other directives (such as `py:strip`).
cmlenz
parents: 50
diff changeset
192 """
61
448792ab1303 Use a different namespace than Kid uses.
cmlenz
parents: 54
diff changeset
193 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/">
51
b2383634ec04 Fix `py:for` directive when combined with other directives (such as `py:strip`).
cmlenz
parents: 50
diff changeset
194 <div py:for="item in items" py:strip="">
b2383634ec04 Fix `py:for` directive when combined with other directives (such as `py:strip`).
cmlenz
parents: 50
diff changeset
195 <b>${item}</b>
b2383634ec04 Fix `py:for` directive when combined with other directives (such as `py:strip`).
cmlenz
parents: 50
diff changeset
196 </div>
b2383634ec04 Fix `py:for` directive when combined with other directives (such as `py:strip`).
cmlenz
parents: 50
diff changeset
197 </doc>""")
b2383634ec04 Fix `py:for` directive when combined with other directives (such as `py:strip`).
cmlenz
parents: 50
diff changeset
198 self.assertEqual("""<doc>
b2383634ec04 Fix `py:for` directive when combined with other directives (such as `py:strip`).
cmlenz
parents: 50
diff changeset
199 <b>1</b>
b2383634ec04 Fix `py:for` directive when combined with other directives (such as `py:strip`).
cmlenz
parents: 50
diff changeset
200 <b>2</b>
b2383634ec04 Fix `py:for` directive when combined with other directives (such as `py:strip`).
cmlenz
parents: 50
diff changeset
201 <b>3</b>
b2383634ec04 Fix `py:for` directive when combined with other directives (such as `py:strip`).
cmlenz
parents: 50
diff changeset
202 <b>4</b>
b2383634ec04 Fix `py:for` directive when combined with other directives (such as `py:strip`).
cmlenz
parents: 50
diff changeset
203 <b>5</b>
149
537f819c547b `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
204 </doc>""", str(tmpl.generate(items=range(1, 6))))
51
b2383634ec04 Fix `py:for` directive when combined with other directives (such as `py:strip`).
cmlenz
parents: 50
diff changeset
205
65
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
206 def test_as_element(self):
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
207 """
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
208 Verify that the directive can also be used as an element.
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
209 """
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
210 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/">
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
211 <py:for each="item in items">
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
212 <b>${item}</b>
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
213 </py:for>
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
214 </doc>""")
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
215 self.assertEqual("""<doc>
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
216 <b>1</b>
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
217 <b>2</b>
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
218 <b>3</b>
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
219 <b>4</b>
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
220 <b>5</b>
149
537f819c547b `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
221 </doc>""", str(tmpl.generate(items=range(1, 6))))
65
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
222
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
223
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
224 class IfDirectiveTestCase(unittest.TestCase):
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
225 """Tests for the `py:if` template directive."""
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
226
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
227 def test_loop_with_strip(self):
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
228 """
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
229 Verify that the combining the `py:if` directive with `py:strip` works
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
230 correctly.
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
231 """
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
232 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/">
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
233 <b py:if="foo" py:strip="">${bar}</b>
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
234 </doc>""")
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
235 self.assertEqual("""<doc>
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
236 Hello
149
537f819c547b `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
237 </doc>""", str(tmpl.generate(foo=True, bar='Hello')))
65
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
238
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
239 def test_as_element(self):
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
240 """
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
241 Verify that the directive can also be used as an element.
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
242 """
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
243 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/">
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
244 <py:if test="foo">${bar}</py:if>
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
245 </doc>""")
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
246 self.assertEqual("""<doc>
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
247 Hello
149
537f819c547b `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
248 </doc>""", str(tmpl.generate(foo=True, bar='Hello')))
65
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
249
51
b2383634ec04 Fix `py:for` directive when combined with other directives (such as `py:strip`).
cmlenz
parents: 50
diff changeset
250
36
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
251 class MatchDirectiveTestCase(unittest.TestCase):
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
252 """Tests for the `py:match` template directive."""
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
253
50
d3842cd76e92 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
254 def test_with_strip(self):
d3842cd76e92 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
255 """
d3842cd76e92 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
256 Verify that a match template can produce the same kind of element that
d3842cd76e92 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
257 it matched without entering an infinite recursion.
d3842cd76e92 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
258 """
61
448792ab1303 Use a different namespace than Kid uses.
cmlenz
parents: 54
diff changeset
259 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/">
50
d3842cd76e92 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
260 <elem py:match="elem" py:strip="">
d3842cd76e92 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
261 <div class="elem">${select('*/text()')}</div>
d3842cd76e92 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
262 </elem>
d3842cd76e92 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
263 <elem>Hey Joe</elem>
d3842cd76e92 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
264 </doc>""")
d3842cd76e92 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
265 self.assertEqual("""<doc>
d3842cd76e92 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
266 <div class="elem">Hey Joe</div>
d3842cd76e92 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
267 </doc>""", str(tmpl.generate()))
d3842cd76e92 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
268
36
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
269 def test_without_strip(self):
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
270 """
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
271 Verify that a match template can produce the same kind of element that
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
272 it matched without entering an infinite recursion.
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
273 """
61
448792ab1303 Use a different namespace than Kid uses.
cmlenz
parents: 54
diff changeset
274 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/">
36
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
275 <elem py:match="elem">
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
276 <div class="elem">${select('*/text()')}</div>
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
277 </elem>
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
278 <elem>Hey Joe</elem>
37
37557b8fb925 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
279 </doc>""")
36
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
280 self.assertEqual("""<doc>
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
281 <elem>
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
282 <div class="elem">Hey Joe</div>
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
283 </elem>
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
284 </doc>""", str(tmpl.generate()))
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
285
65
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
286 def test_as_element(self):
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
287 """
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
288 Verify that the directive can also be used as an element.
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
289 """
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
290 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/">
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
291 <py:match path="elem">
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
292 <div class="elem">${select('*/text()')}</div>
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
293 </py:match>
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
294 <elem>Hey Joe</elem>
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
295 </doc>""")
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
296 self.assertEqual("""<doc>
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
297 <div class="elem">Hey Joe</div>
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
298 </doc>""", str(tmpl.generate()))
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
299
36
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
300 def test_recursive_match_1(self):
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
301 """
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
302 Match directives are applied recursively, meaning that they are also
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
303 applied to any content they may have produced themselves:
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
304 """
61
448792ab1303 Use a different namespace than Kid uses.
cmlenz
parents: 54
diff changeset
305 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/">
36
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
306 <elem py:match="elem">
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
307 <div class="elem">
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
308 ${select('*/*')}
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
309 </div>
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
310 </elem>
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
311 <elem>
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
312 <subelem>
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
313 <elem/>
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
314 </subelem>
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
315 </elem>
37
37557b8fb925 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
316 </doc>""")
36
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
317 self.assertEqual("""<doc>
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
318 <elem>
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
319 <div class="elem">
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
320 <subelem>
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
321 <elem>
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
322 <div class="elem">
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
323 </div>
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
324 </elem>
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
325 </subelem>
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
326 </div>
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
327 </elem>
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
328 </doc>""", str(tmpl.generate()))
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
329
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
330 def test_recursive_match_2(self):
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
331 """
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
332 When two or more match templates match the same element and also
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
333 themselves output the element they match, avoiding recursion is even
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
334 more complex, but should work.
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
335 """
61
448792ab1303 Use a different namespace than Kid uses.
cmlenz
parents: 54
diff changeset
336 tmpl = Template("""<html xmlns:py="http://markup.edgewall.org/">
36
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
337 <body py:match="body">
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
338 <div id="header"/>
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
339 ${select('*/*')}
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
340 </body>
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
341 <body py:match="body">
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
342 ${select('*/*')}
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
343 <div id="footer"/>
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
344 </body>
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
345 <body>
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
346 <h1>Foo</h1>
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
347 </body>
37
37557b8fb925 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
348 </html>""")
36
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
349 self.assertEqual("""<html>
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
350 <body>
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
351 <div id="header"/><h1>Foo</h1>
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
352 <div id="footer"/>
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
353 </body>
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
354 </html>""", str(tmpl.generate()))
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
355
77
f5ec6d4a61e4 * Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents: 75
diff changeset
356 def test_select_all_attrs(self):
f5ec6d4a61e4 * Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents: 75
diff changeset
357 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/">
f5ec6d4a61e4 * Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents: 75
diff changeset
358 <div py:match="elem" py:attrs="select('@*')">
f5ec6d4a61e4 * Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents: 75
diff changeset
359 ${select('*/text()')}
f5ec6d4a61e4 * Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents: 75
diff changeset
360 </div>
f5ec6d4a61e4 * Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents: 75
diff changeset
361 <elem id="joe">Hey Joe</elem>
f5ec6d4a61e4 * Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents: 75
diff changeset
362 </doc>""")
f5ec6d4a61e4 * Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents: 75
diff changeset
363 self.assertEqual("""<doc>
f5ec6d4a61e4 * Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents: 75
diff changeset
364 <div id="joe">
f5ec6d4a61e4 * Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents: 75
diff changeset
365 Hey Joe
f5ec6d4a61e4 * Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents: 75
diff changeset
366 </div>
f5ec6d4a61e4 * Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents: 75
diff changeset
367 </doc>""", str(tmpl.generate()))
f5ec6d4a61e4 * Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents: 75
diff changeset
368
f5ec6d4a61e4 * Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents: 75
diff changeset
369 def test_select_all_attrs_empty(self):
f5ec6d4a61e4 * Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents: 75
diff changeset
370 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/">
f5ec6d4a61e4 * Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents: 75
diff changeset
371 <div py:match="elem" py:attrs="select('@*')">
f5ec6d4a61e4 * Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents: 75
diff changeset
372 ${select('*/text()')}
f5ec6d4a61e4 * Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents: 75
diff changeset
373 </div>
f5ec6d4a61e4 * Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents: 75
diff changeset
374 <elem>Hey Joe</elem>
f5ec6d4a61e4 * Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents: 75
diff changeset
375 </doc>""")
f5ec6d4a61e4 * Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents: 75
diff changeset
376 self.assertEqual("""<doc>
f5ec6d4a61e4 * Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents: 75
diff changeset
377 <div>
f5ec6d4a61e4 * Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents: 75
diff changeset
378 Hey Joe
f5ec6d4a61e4 * Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents: 75
diff changeset
379 </div>
f5ec6d4a61e4 * Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents: 75
diff changeset
380 </doc>""", str(tmpl.generate()))
f5ec6d4a61e4 * Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents: 75
diff changeset
381
f5ec6d4a61e4 * Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents: 75
diff changeset
382 def test_select_all_attrs_in_body(self):
f5ec6d4a61e4 * Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents: 75
diff changeset
383 tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/">
f5ec6d4a61e4 * Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents: 75
diff changeset
384 <div py:match="elem">
f5ec6d4a61e4 * Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents: 75
diff changeset
385 Hey ${select('text()')} ${select('@*')}
f5ec6d4a61e4 * Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents: 75
diff changeset
386 </div>
f5ec6d4a61e4 * Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents: 75
diff changeset
387 <elem title="Cool">Joe</elem>
f5ec6d4a61e4 * Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents: 75
diff changeset
388 </doc>""")
f5ec6d4a61e4 * Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents: 75
diff changeset
389 self.assertEqual("""<doc>
f5ec6d4a61e4 * Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents: 75
diff changeset
390 <div>
f5ec6d4a61e4 * Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents: 75
diff changeset
391 Hey Joe Cool
f5ec6d4a61e4 * Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents: 75
diff changeset
392 </div>
f5ec6d4a61e4 * Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents: 75
diff changeset
393 </doc>""", str(tmpl.generate()))
f5ec6d4a61e4 * Simplify implementation of the individual XPath tests (use closures instead of callable classes)
cmlenz
parents: 75
diff changeset
394
36
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
395
37
37557b8fb925 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
396 class StripDirectiveTestCase(unittest.TestCase):
37557b8fb925 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
397 """Tests for the `py:strip` template directive."""
37557b8fb925 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
398
37557b8fb925 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
399 def test_strip_false(self):
61
448792ab1303 Use a different namespace than Kid uses.
cmlenz
parents: 54
diff changeset
400 tmpl = Template("""<div xmlns:py="http://markup.edgewall.org/">
37
37557b8fb925 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
401 <div py:strip="False"><b>foo</b></div>
37557b8fb925 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
402 </div>""")
37557b8fb925 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
403 self.assertEqual("""<div>
37557b8fb925 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
404 <div><b>foo</b></div>
37557b8fb925 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
405 </div>""", str(tmpl.generate()))
37557b8fb925 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
406
37557b8fb925 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
407 def test_strip_empty(self):
61
448792ab1303 Use a different namespace than Kid uses.
cmlenz
parents: 54
diff changeset
408 tmpl = Template("""<div xmlns:py="http://markup.edgewall.org/">
37
37557b8fb925 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
409 <div py:strip=""><b>foo</b></div>
37557b8fb925 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
410 </div>""")
37557b8fb925 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
411 self.assertEqual("""<div>
37557b8fb925 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
412 <b>foo</b>
37557b8fb925 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
413 </div>""", str(tmpl.generate()))
37557b8fb925 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
414
37557b8fb925 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
415
104
f12e7987d7f4 Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents: 90
diff changeset
416 class WithDirectiveTestCase(unittest.TestCase):
f12e7987d7f4 Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents: 90
diff changeset
417 """Tests for the `py:with` template directive."""
f12e7987d7f4 Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents: 90
diff changeset
418
f12e7987d7f4 Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents: 90
diff changeset
419 def test_shadowing(self):
f12e7987d7f4 Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents: 90
diff changeset
420 tmpl = Template("""<div xmlns:py="http://markup.edgewall.org/">
f12e7987d7f4 Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents: 90
diff changeset
421 ${x}
f12e7987d7f4 Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents: 90
diff changeset
422 <span py:with="x = x * 2" py:replace="x"/>
f12e7987d7f4 Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents: 90
diff changeset
423 ${x}
f12e7987d7f4 Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents: 90
diff changeset
424 </div>""")
f12e7987d7f4 Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents: 90
diff changeset
425 self.assertEqual("""<div>
f12e7987d7f4 Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents: 90
diff changeset
426 42
f12e7987d7f4 Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents: 90
diff changeset
427 84
f12e7987d7f4 Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents: 90
diff changeset
428 42
149
537f819c547b `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
429 </div>""", str(tmpl.generate(x=42)))
104
f12e7987d7f4 Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents: 90
diff changeset
430
f12e7987d7f4 Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents: 90
diff changeset
431 def test_as_element(self):
f12e7987d7f4 Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents: 90
diff changeset
432 tmpl = Template("""<div xmlns:py="http://markup.edgewall.org/">
f12e7987d7f4 Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents: 90
diff changeset
433 <py:with vars="x = x * 2">${x}</py:with>
f12e7987d7f4 Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents: 90
diff changeset
434 </div>""")
f12e7987d7f4 Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents: 90
diff changeset
435 self.assertEqual("""<div>
f12e7987d7f4 Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents: 90
diff changeset
436 84
149
537f819c547b `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
437 </div>""", str(tmpl.generate(x=42)))
104
f12e7987d7f4 Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents: 90
diff changeset
438
f12e7987d7f4 Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents: 90
diff changeset
439
1
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
440 class TemplateTestCase(unittest.TestCase):
36
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
441 """Tests for basic template processing, expression evaluation and error
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
442 reporting.
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
443 """
1
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
444
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
445 def test_interpolate_string(self):
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
446 parts = list(Template._interpolate('bla'))
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
447 self.assertEqual(1, len(parts))
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
448 self.assertEqual(Stream.TEXT, parts[0][0])
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
449 self.assertEqual('bla', parts[0][1])
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
450
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
451 def test_interpolate_simple(self):
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
452 parts = list(Template._interpolate('${bla}'))
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
453 self.assertEqual(1, len(parts))
10
f77f7a91aa46 Moved the template-specific stream event kinds into the template module.
cmlenz
parents: 1
diff changeset
454 self.assertEqual(Template.EXPR, parts[0][0])
1
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
455 self.assertEqual('bla', parts[0][1].source)
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
456
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
457 def test_interpolate_escaped(self):
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
458 parts = list(Template._interpolate('$${bla}'))
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
459 self.assertEqual(1, len(parts))
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
460 self.assertEqual(Stream.TEXT, parts[0][0])
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
461 self.assertEqual('${bla}', parts[0][1])
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
462
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
463 def test_interpolate_short(self):
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
464 parts = list(Template._interpolate('$bla'))
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
465 self.assertEqual(1, len(parts))
10
f77f7a91aa46 Moved the template-specific stream event kinds into the template module.
cmlenz
parents: 1
diff changeset
466 self.assertEqual(Template.EXPR, parts[0][0])
1
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
467 self.assertEqual('bla', parts[0][1].source)
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
468
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
469 def test_interpolate_mixed1(self):
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
470 parts = list(Template._interpolate('$foo bar $baz'))
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
471 self.assertEqual(3, len(parts))
10
f77f7a91aa46 Moved the template-specific stream event kinds into the template module.
cmlenz
parents: 1
diff changeset
472 self.assertEqual(Template.EXPR, parts[0][0])
1
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
473 self.assertEqual('foo', parts[0][1].source)
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
474 self.assertEqual(Stream.TEXT, parts[1][0])
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
475 self.assertEqual(' bar ', parts[1][1])
10
f77f7a91aa46 Moved the template-specific stream event kinds into the template module.
cmlenz
parents: 1
diff changeset
476 self.assertEqual(Template.EXPR, parts[2][0])
1
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
477 self.assertEqual('baz', parts[2][1].source)
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
478
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
479 def test_interpolate_mixed2(self):
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
480 parts = list(Template._interpolate('foo $bar baz'))
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
481 self.assertEqual(3, len(parts))
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
482 self.assertEqual(Stream.TEXT, parts[0][0])
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
483 self.assertEqual('foo ', parts[0][1])
10
f77f7a91aa46 Moved the template-specific stream event kinds into the template module.
cmlenz
parents: 1
diff changeset
484 self.assertEqual(Template.EXPR, parts[1][0])
1
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
485 self.assertEqual('bar', parts[1][1].source)
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
486 self.assertEqual(Stream.TEXT, parts[2][0])
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
487 self.assertEqual(' baz', parts[2][1])
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
488
74
d54b5fd60b52 Fix expression interpolation where both shorthand notation and full notation are used inside a single text node. Thanks Jonas.
cmlenz
parents: 66
diff changeset
489 def test_interpolate_mixed3(self):
d54b5fd60b52 Fix expression interpolation where both shorthand notation and full notation are used inside a single text node. Thanks Jonas.
cmlenz
parents: 66
diff changeset
490 tmpl = Template('<root> ${var} $var</root>')
149
537f819c547b `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
491 self.assertEqual('<root> 42 42</root>', str(tmpl.generate(var=42)))
74
d54b5fd60b52 Fix expression interpolation where both shorthand notation and full notation are used inside a single text node. Thanks Jonas.
cmlenz
parents: 66
diff changeset
492
48
a5d585dd38c4 convert the result of expressions in attributes to strings so that values like ints are output correctly
mgood
parents: 37
diff changeset
493 def test_interpolate_non_string_attrs(self):
a5d585dd38c4 convert the result of expressions in attributes to strings so that values like ints are output correctly
mgood
parents: 37
diff changeset
494 tmpl = Template('<root attr="${1}"/>')
75
3722696d0343 Empty attributes in templates were being stripped out. Thanks to Jonas for the patch.
cmlenz
parents: 74
diff changeset
495 self.assertEqual('<root attr="1"/>', str(tmpl.generate()))
3722696d0343 Empty attributes in templates were being stripped out. Thanks to Jonas for the patch.
cmlenz
parents: 74
diff changeset
496
145
47bbd9d2a5af * Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents: 134
diff changeset
497 def test_interpolate_list_result(self):
47bbd9d2a5af * Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents: 134
diff changeset
498 tmpl = Template('<root>$foo</root>')
149
537f819c547b `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
499 self.assertEqual('<root>buzz</root>', str(tmpl.generate(foo=('buzz',))))
145
47bbd9d2a5af * Fix error in expression evaluation when the expression evaluates to an iterable that does not produce event tuples.
cmlenz
parents: 134
diff changeset
500
75
3722696d0343 Empty attributes in templates were being stripped out. Thanks to Jonas for the patch.
cmlenz
parents: 74
diff changeset
501 def test_empty_attr(self):
3722696d0343 Empty attributes in templates were being stripped out. Thanks to Jonas for the patch.
cmlenz
parents: 74
diff changeset
502 tmpl = Template('<root attr=""/>')
3722696d0343 Empty attributes in templates were being stripped out. Thanks to Jonas for the patch.
cmlenz
parents: 74
diff changeset
503 self.assertEqual('<root attr=""/>', str(tmpl.generate()))
48
a5d585dd38c4 convert the result of expressions in attributes to strings so that values like ints are output correctly
mgood
parents: 37
diff changeset
504
1
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
505 def test_bad_directive_error(self):
61
448792ab1303 Use a different namespace than Kid uses.
cmlenz
parents: 54
diff changeset
506 xml = '<p xmlns:py="http://markup.edgewall.org/" py:do="nothing" />'
1
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
507 try:
21
b4d17897d053 * Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents: 10
diff changeset
508 tmpl = Template(xml, filename='test.html')
1
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
509 except BadDirectiveError, e:
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
510 self.assertEqual('test.html', e.filename)
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
511 if sys.version_info[:2] >= (2, 4):
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
512 self.assertEqual(1, e.lineno)
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
513
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
514 def test_directive_value_syntax_error(self):
81
d60486018004 Template expressions are now compiled to Python bytecode.
cmlenz
parents: 77
diff changeset
515 xml = """<p xmlns:py="http://markup.edgewall.org/" py:if="bar'" />"""
1
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
516 try:
81
d60486018004 Template expressions are now compiled to Python bytecode.
cmlenz
parents: 77
diff changeset
517 tmpl = Template(xml, filename='test.html')
1
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
518 self.fail('Expected SyntaxError')
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
519 except TemplateSyntaxError, e:
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
520 self.assertEqual('test.html', e.filename)
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
521 if sys.version_info[:2] >= (2, 4):
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
522 self.assertEqual(1, e.lineno)
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
523
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
524 def test_expression_syntax_error(self):
81
d60486018004 Template expressions are now compiled to Python bytecode.
cmlenz
parents: 77
diff changeset
525 xml = """<p>
d60486018004 Template expressions are now compiled to Python bytecode.
cmlenz
parents: 77
diff changeset
526 Foo <em>${bar"}</em>
d60486018004 Template expressions are now compiled to Python bytecode.
cmlenz
parents: 77
diff changeset
527 </p>"""
1
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
528 try:
81
d60486018004 Template expressions are now compiled to Python bytecode.
cmlenz
parents: 77
diff changeset
529 tmpl = Template(xml, filename='test.html')
1
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
530 self.fail('Expected SyntaxError')
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
531 except TemplateSyntaxError, e:
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
532 self.assertEqual('test.html', e.filename)
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
533 if sys.version_info[:2] >= (2, 4):
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
534 self.assertEqual(2, e.lineno)
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
535
134
d681d2c3cd8d * 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
536 def test_expression_syntax_error_multi_line(self):
d681d2c3cd8d * 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
537 xml = """<p><em></em>
d681d2c3cd8d * 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
538
d681d2c3cd8d * 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
539 ${bar"}
d681d2c3cd8d * 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
540
d681d2c3cd8d * 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
541 </p>"""
d681d2c3cd8d * 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
542 try:
d681d2c3cd8d * 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
543 tmpl = Template(xml, filename='test.html')
d681d2c3cd8d * 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
544 self.fail('Expected SyntaxError')
d681d2c3cd8d * 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
545 except TemplateSyntaxError, e:
d681d2c3cd8d * 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
546 self.assertEqual('test.html', e.filename)
d681d2c3cd8d * 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
547 if sys.version_info[:2] >= (2, 4):
d681d2c3cd8d * 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
548 self.assertEqual(3, e.lineno)
d681d2c3cd8d * 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
549
54
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
550 def test_markup_noescape(self):
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
551 """
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
552 Verify that outputting context data that is a `Markup` instance is not
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
553 escaped.
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
554 """
61
448792ab1303 Use a different namespace than Kid uses.
cmlenz
parents: 54
diff changeset
555 tmpl = Template("""<div xmlns:py="http://markup.edgewall.org/">
54
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
556 $myvar
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
557 </div>""")
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
558 self.assertEqual("""<div>
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
559 <b>foo</b>
149
537f819c547b `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
560 </div>""", str(tmpl.generate(myvar=Markup('<b>foo</b>'))))
54
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
561
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
562 def test_text_noescape_quotes(self):
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
563 """
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
564 Verify that outputting context data in text nodes doesn't escape quotes.
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
565 """
61
448792ab1303 Use a different namespace than Kid uses.
cmlenz
parents: 54
diff changeset
566 tmpl = Template("""<div xmlns:py="http://markup.edgewall.org/">
54
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
567 $myvar
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
568 </div>""")
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
569 self.assertEqual("""<div>
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
570 "foo"
149
537f819c547b `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
571 </div>""", str(tmpl.generate(myvar='"foo"')))
54
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
572
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
573 def test_attr_escape_quotes(self):
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
574 """
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
575 Verify that outputting context data in attribtes escapes quotes.
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
576 """
61
448792ab1303 Use a different namespace than Kid uses.
cmlenz
parents: 54
diff changeset
577 tmpl = Template("""<div xmlns:py="http://markup.edgewall.org/">
54
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
578 <elem class="$myvar"/>
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
579 </div>""")
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
580 self.assertEqual("""<div>
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
581 <elem class="&#34;foo&#34;"/>
149
537f819c547b `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
582 </div>""", str(tmpl.generate(myvar='"foo"')))
54
1f3cd91325d9 Fix a number of escaping problems:
cmlenz
parents: 53
diff changeset
583
65
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
584 def test_directive_element(self):
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
585 tmpl = Template("""<div xmlns:py="http://markup.edgewall.org/">
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
586 <py:if test="myvar">bar</py:if>
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
587 </div>""")
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
588 self.assertEqual("""<div>
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
589 bar
149
537f819c547b `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
590 </div>""", str(tmpl.generate(myvar='"foo"')))
65
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
591
89
80386d62814f 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
592 def test_normal_comment(self):
80386d62814f 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
593 tmpl = Template("""<div xmlns:py="http://markup.edgewall.org/">
80386d62814f 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
594 <!-- foo bar -->
80386d62814f 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
595 </div>""")
80386d62814f 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
596 self.assertEqual("""<div>
80386d62814f 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
597 <!-- foo bar -->
80386d62814f 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
598 </div>""", str(tmpl.generate()))
80386d62814f 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
599
80386d62814f 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
600 def test_template_comment(self):
80386d62814f 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
601 tmpl = Template("""<div xmlns:py="http://markup.edgewall.org/">
80386d62814f 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
602 <!-- !foo -->
80386d62814f 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
603 <!--!bar-->
80386d62814f 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
604 </div>""")
80386d62814f 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
605 self.assertEqual("""<div>
80386d62814f 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
606 </div>""", str(tmpl.generate()))
80386d62814f 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
607
1
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
608
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
609 def suite():
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
610 suite = unittest.TestSuite()
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
611 suite.addTest(doctest.DocTestSuite(Template.__module__))
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
612 suite.addTest(unittest.makeSuite(TemplateTestCase, 'test'))
50
d3842cd76e92 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
613 suite.addTest(unittest.makeSuite(AttrsDirectiveTestCase, 'test'))
53
512eb72dbb19 * Add helper function to let directives apply any remaining directives, and use that helper consistently in every directive.
cmlenz
parents: 51
diff changeset
614 suite.addTest(unittest.makeSuite(ChooseDirectiveTestCase, 'test'))
50
d3842cd76e92 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
615 suite.addTest(unittest.makeSuite(DefDirectiveTestCase, 'test'))
51
b2383634ec04 Fix `py:for` directive when combined with other directives (such as `py:strip`).
cmlenz
parents: 50
diff changeset
616 suite.addTest(unittest.makeSuite(ForDirectiveTestCase, 'test'))
65
b3fdf93057ab Support the use of directives as elements to reduce the need for using `py:strip`.
cmlenz
parents: 61
diff changeset
617 suite.addTest(unittest.makeSuite(IfDirectiveTestCase, 'test'))
36
ed370ebfa794 Fix for #7: match templates no longer process their own output.
cmlenz
parents: 27
diff changeset
618 suite.addTest(unittest.makeSuite(MatchDirectiveTestCase, 'test'))
37
37557b8fb925 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
619 suite.addTest(unittest.makeSuite(StripDirectiveTestCase, 'test'))
104
f12e7987d7f4 Added `py:with` directive based on Jonas' patch in #17.
cmlenz
parents: 90
diff changeset
620 suite.addTest(unittest.makeSuite(WithDirectiveTestCase, 'test'))
1
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
621 return suite
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
622
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
623 if __name__ == '__main__':
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
624 unittest.main(defaultTest='suite')
Copyright (C) 2012-2017 Edgewall Software