Mercurial > genshi > genshi-test
annotate genshi/tests/output.py @ 500:0742f421caba experimental-inline
Merged revisions 487-603 via svnmerge from
http://svn.edgewall.org/repos/genshi/trunk
author | cmlenz |
---|---|
date | Fri, 01 Jun 2007 17:21:47 +0000 |
parents | c0a4114786cc |
children | 1837f39efd6f |
rev | line source |
---|---|
1 | 1 # -*- coding: utf-8 -*- |
2 # | |
500 | 3 # Copyright (C) 2006-2007 Edgewall Software |
1 | 4 # All rights reserved. |
5 # | |
6 # This software is licensed as described in the file COPYING, which | |
7 # you should have received as part of this distribution. The terms | |
230 | 8 # are also available at http://genshi.edgewall.org/wiki/License. |
1 | 9 # |
10 # This software consists of voluntary contributions made by many | |
11 # individuals. For the exact contribution history, see the revision | |
230 | 12 # history and logs, available at http://genshi.edgewall.org/log/. |
1 | 13 |
14 import doctest | |
15 import unittest | |
16 import sys | |
17 | |
314
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
18 from genshi.core import Attrs, Stream, QName |
230 | 19 from genshi.input import HTML, XML |
20 from genshi.output import DocType, XMLSerializer, XHTMLSerializer, \ | |
212
e8c43127d9a9
Refactored the handling of empty tags in the serializer: use an `EmptyTagFilter` that combines adjacent start/end events, instead of the generic pushback-iterator.
cmlenz
parents:
178
diff
changeset
|
21 HTMLSerializer, EmptyTagFilter |
85 | 22 |
23 | |
24 class XMLSerializerTestCase(unittest.TestCase): | |
25 | |
26 def test_doctype_in_stream(self): | |
314
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
27 stream = Stream([(Stream.DOCTYPE, DocType.HTML_STRICT, (None, -1, -1))]) |
85 | 28 output = stream.render(XMLSerializer) |
29 self.assertEqual('<!DOCTYPE html PUBLIC ' | |
30 '"-//W3C//DTD HTML 4.01//EN" ' | |
31 '"http://www.w3.org/TR/html4/strict.dtd">\n', | |
32 output) | |
33 | |
34 def test_doctype_in_stream_no_sysid(self): | |
35 stream = Stream([(Stream.DOCTYPE, | |
36 ('html', '-//W3C//DTD HTML 4.01//EN', None), | |
314
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
37 (None, -1, -1))]) |
85 | 38 output = stream.render(XMLSerializer) |
39 self.assertEqual('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">\n', | |
40 output) | |
41 | |
42 def test_doctype_in_stream_no_pubid(self): | |
314
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
43 stream = Stream([ |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
44 (Stream.DOCTYPE, |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
45 ('html', None, 'http://www.w3.org/TR/html4/strict.dtd'), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
46 (None, -1, -1)) |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
47 ]) |
85 | 48 output = stream.render(XMLSerializer) |
49 self.assertEqual('<!DOCTYPE html SYSTEM ' | |
50 '"http://www.w3.org/TR/html4/strict.dtd">\n', | |
51 output) | |
52 | |
53 def test_doctype_in_stream_no_pubid_or_sysid(self): | |
54 stream = Stream([(Stream.DOCTYPE, ('html', None, None), | |
314
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
55 (None, -1, -1))]) |
85 | 56 output = stream.render(XMLSerializer) |
57 self.assertEqual('<!DOCTYPE html>\n', output) | |
58 | |
59 def test_serializer_doctype(self): | |
60 stream = Stream([]) | |
61 output = stream.render(XMLSerializer, doctype=DocType.HTML_STRICT) | |
62 self.assertEqual('<!DOCTYPE html PUBLIC ' | |
63 '"-//W3C//DTD HTML 4.01//EN" ' | |
64 '"http://www.w3.org/TR/html4/strict.dtd">\n', | |
65 output) | |
66 | |
67 def test_doctype_one_and_only(self): | |
314
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
68 stream = Stream([ |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
69 (Stream.DOCTYPE, ('html', None, None), (None, -1, -1)) |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
70 ]) |
85 | 71 output = stream.render(XMLSerializer, doctype=DocType.HTML_STRICT) |
72 self.assertEqual('<!DOCTYPE html PUBLIC ' | |
73 '"-//W3C//DTD HTML 4.01//EN" ' | |
74 '"http://www.w3.org/TR/html4/strict.dtd">\n', | |
75 output) | |
76 | |
89
d4c7617900e3
Support comments in templates that are not included in the output, in the same way Kid does: if the comment text starts with a `!` character, it is stripped from the output.
cmlenz
parents:
85
diff
changeset
|
77 def test_comment(self): |
314
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
78 stream = Stream([(Stream.COMMENT, 'foo bar', (None, -1, -1))]) |
89
d4c7617900e3
Support comments in templates that are not included in the output, in the same way Kid does: if the comment text starts with a `!` character, it is stripped from the output.
cmlenz
parents:
85
diff
changeset
|
79 output = stream.render(XMLSerializer) |
d4c7617900e3
Support comments in templates that are not included in the output, in the same way Kid does: if the comment text starts with a `!` character, it is stripped from the output.
cmlenz
parents:
85
diff
changeset
|
80 self.assertEqual('<!--foo bar-->', output) |
d4c7617900e3
Support comments in templates that are not included in the output, in the same way Kid does: if the comment text starts with a `!` character, it is stripped from the output.
cmlenz
parents:
85
diff
changeset
|
81 |
105
334a338847af
Include processing instructions in serialized streams.
cmlenz
parents:
89
diff
changeset
|
82 def test_processing_instruction(self): |
314
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
83 stream = Stream([(Stream.PI, ('python', 'x = 2'), (None, -1, -1))]) |
105
334a338847af
Include processing instructions in serialized streams.
cmlenz
parents:
89
diff
changeset
|
84 output = stream.render(XMLSerializer) |
334a338847af
Include processing instructions in serialized streams.
cmlenz
parents:
89
diff
changeset
|
85 self.assertEqual('<?python x = 2?>', output) |
334a338847af
Include processing instructions in serialized streams.
cmlenz
parents:
89
diff
changeset
|
86 |
313
caafc67d2d0f
Handle expressions containing non-ASCII strings as arguments for `py:with`, `py:def`, and `py:for`.
cmlenz
parents:
280
diff
changeset
|
87 def test_nested_default_namespaces(self): |
314
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
88 stream = Stream([ |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
89 (Stream.START_NS, ('', 'http://example.org/'), (None, -1, -1)), |
500 | 90 (Stream.START, (QName('http://example.org/}div'), Attrs()), (None, -1, -1)), |
314
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
91 (Stream.TEXT, '\n ', (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
92 (Stream.START_NS, ('', 'http://example.org/'), (None, -1, -1)), |
500 | 93 (Stream.START, (QName('http://example.org/}p'), Attrs()), (None, -1, -1)), |
94 (Stream.END, QName('http://example.org/}p'), (None, -1, -1)), | |
314
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
95 (Stream.END_NS, '', (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
96 (Stream.TEXT, '\n ', (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
97 (Stream.START_NS, ('', 'http://example.org/'), (None, -1, -1)), |
500 | 98 (Stream.START, (QName('http://example.org/}p'), Attrs()), (None, -1, -1)), |
99 (Stream.END, QName('http://example.org/}p'), (None, -1, -1)), | |
314
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
100 (Stream.END_NS, '', (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
101 (Stream.TEXT, '\n ', (None, -1, -1)), |
500 | 102 (Stream.END, QName('http://example.org/}div'), (None, -1, -1)), |
314
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
103 (Stream.END_NS, '', (None, -1, -1)) |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
104 ]) |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
105 output = stream.render(XMLSerializer) |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
106 self.assertEqual("""<div xmlns="http://example.org/"> |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
107 <p/> |
313
caafc67d2d0f
Handle expressions containing non-ASCII strings as arguments for `py:with`, `py:def`, and `py:for`.
cmlenz
parents:
280
diff
changeset
|
108 <p/> |
caafc67d2d0f
Handle expressions containing non-ASCII strings as arguments for `py:with`, `py:def`, and `py:for`.
cmlenz
parents:
280
diff
changeset
|
109 </div>""", output) |
caafc67d2d0f
Handle expressions containing non-ASCII strings as arguments for `py:with`, `py:def`, and `py:for`.
cmlenz
parents:
280
diff
changeset
|
110 |
caafc67d2d0f
Handle expressions containing non-ASCII strings as arguments for `py:with`, `py:def`, and `py:for`.
cmlenz
parents:
280
diff
changeset
|
111 def test_nested_bound_namespaces(self): |
314
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
112 stream = Stream([ |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
113 (Stream.START_NS, ('x', 'http://example.org/'), (None, -1, -1)), |
500 | 114 (Stream.START, (QName('http://example.org/}div'), Attrs()), (None, -1, -1)), |
314
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
115 (Stream.TEXT, '\n ', (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
116 (Stream.START_NS, ('x', 'http://example.org/'), (None, -1, -1)), |
500 | 117 (Stream.START, (QName('http://example.org/}p'), Attrs()), (None, -1, -1)), |
118 (Stream.END, QName('http://example.org/}p'), (None, -1, -1)), | |
314
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
119 (Stream.END_NS, 'x', (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
120 (Stream.TEXT, '\n ', (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
121 (Stream.START_NS, ('x', 'http://example.org/'), (None, -1, -1)), |
500 | 122 (Stream.START, (QName('http://example.org/}p'), Attrs()), (None, -1, -1)), |
123 (Stream.END, QName('http://example.org/}p'), (None, -1, -1)), | |
124 (Stream.END_NS, 'x', (None, -1, -1)), | |
125 (Stream.TEXT, '\n ', (None, -1, -1)), | |
126 (Stream.END, QName('http://example.org/}div'), (None, -1, -1)), | |
127 (Stream.END_NS, 'x', (None, -1, -1)) | |
128 ]) | |
129 output = stream.render(XMLSerializer) | |
130 self.assertEqual("""<x:div xmlns:x="http://example.org/"> | |
131 <x:p/> | |
132 <x:p/> | |
133 </x:div>""", output) | |
134 | |
135 def test_multiple_default_namespaces(self): | |
136 stream = Stream([ | |
137 (Stream.START, (QName('div'), Attrs()), (None, -1, -1)), | |
138 (Stream.TEXT, '\n ', (None, -1, -1)), | |
139 (Stream.START_NS, ('', 'http://example.org/'), (None, -1, -1)), | |
140 (Stream.START, (QName('http://example.org/}p'), Attrs()), (None, -1, -1)), | |
141 (Stream.END, QName('http://example.org/}p'), (None, -1, -1)), | |
142 (Stream.END_NS, '', (None, -1, -1)), | |
143 (Stream.TEXT, '\n ', (None, -1, -1)), | |
144 (Stream.START_NS, ('', 'http://example.org/'), (None, -1, -1)), | |
145 (Stream.START, (QName('http://example.org/}p'), Attrs()), (None, -1, -1)), | |
146 (Stream.END, QName('http://example.org/}p'), (None, -1, -1)), | |
147 (Stream.END_NS, '', (None, -1, -1)), | |
148 (Stream.TEXT, '\n ', (None, -1, -1)), | |
149 (Stream.END, QName('div'), (None, -1, -1)), | |
150 ]) | |
151 output = stream.render(XMLSerializer) | |
152 self.assertEqual("""<div> | |
153 <p xmlns="http://example.org/"/> | |
154 <p xmlns="http://example.org/"/> | |
155 </div>""", output) | |
156 | |
157 def test_multiple_bound_namespaces(self): | |
158 stream = Stream([ | |
159 (Stream.START, (QName('div'), Attrs()), (None, -1, -1)), | |
160 (Stream.TEXT, '\n ', (None, -1, -1)), | |
161 (Stream.START_NS, ('x', 'http://example.org/'), (None, -1, -1)), | |
162 (Stream.START, (QName('http://example.org/}p'), Attrs()), (None, -1, -1)), | |
163 (Stream.END, QName('http://example.org/}p'), (None, -1, -1)), | |
164 (Stream.END_NS, 'x', (None, -1, -1)), | |
165 (Stream.TEXT, '\n ', (None, -1, -1)), | |
166 (Stream.START_NS, ('x', 'http://example.org/'), (None, -1, -1)), | |
167 (Stream.START, (QName('http://example.org/}p'), Attrs()), (None, -1, -1)), | |
168 (Stream.END, QName('http://example.org/}p'), (None, -1, -1)), | |
314
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
169 (Stream.END_NS, 'x', (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
170 (Stream.TEXT, '\n ', (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
171 (Stream.END, QName('div'), (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
172 ]) |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
173 output = stream.render(XMLSerializer) |
500 | 174 self.assertEqual("""<div> |
175 <x:p xmlns:x="http://example.org/"/> | |
176 <x:p xmlns:x="http://example.org/"/> | |
313
caafc67d2d0f
Handle expressions containing non-ASCII strings as arguments for `py:with`, `py:def`, and `py:for`.
cmlenz
parents:
280
diff
changeset
|
177 </div>""", output) |
caafc67d2d0f
Handle expressions containing non-ASCII strings as arguments for `py:with`, `py:def`, and `py:for`.
cmlenz
parents:
280
diff
changeset
|
178 |
500 | 179 def test_atom_with_xhtml(self): |
180 text = """<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"> | |
181 <id>urn:uuid:c60843aa-0da8-4fa6-bbe5-98007bc6774e</id> | |
182 <updated>2007-01-28T11:36:02.807108-06:00</updated> | |
183 <title type="xhtml"> | |
184 <div xmlns="http://www.w3.org/1999/xhtml">Example</div> | |
185 </title> | |
186 <subtitle type="xhtml"> | |
187 <div xmlns="http://www.w3.org/1999/xhtml">Bla bla bla</div> | |
188 </subtitle> | |
189 <icon/> | |
190 </feed>""" | |
191 output = XML(text).render(XMLSerializer) | |
192 self.assertEqual(text, output) | |
193 | |
1 | 194 |
123
93bbdcf9428b
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
195 class XHTMLSerializerTestCase(unittest.TestCase): |
93bbdcf9428b
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
196 |
93bbdcf9428b
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
197 def test_textarea_whitespace(self): |
93bbdcf9428b
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
198 content = '\nHey there. \n\n I am indented.\n' |
141
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
199 stream = XML('<textarea name="foo">%s</textarea>' % content) |
123
93bbdcf9428b
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
200 output = stream.render(XHTMLSerializer) |
93bbdcf9428b
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
201 self.assertEqual('<textarea name="foo">%s</textarea>' % content, output) |
93bbdcf9428b
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
202 |
347 | 203 def test_pre_whitespace(self): |
204 content = '\nHey <em>there</em>. \n\n I am indented.\n' | |
205 stream = XML('<pre>%s</pre>' % content) | |
206 output = stream.render(XHTMLSerializer) | |
207 self.assertEqual('<pre>%s</pre>' % content, output) | |
208 | |
123
93bbdcf9428b
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
209 def test_xml_space(self): |
93bbdcf9428b
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
210 text = '<foo xml:space="preserve"> Do not mess \n\n with me </foo>' |
141
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
211 output = XML(text).render(XHTMLSerializer) |
123
93bbdcf9428b
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
212 self.assertEqual(text, output) |
93bbdcf9428b
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
213 |
177
dbae9efe5704
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
214 def test_empty_script(self): |
178
8fb7df2e1281
Fix bug in XHTML serialization: all elements were allowed to be written out as empty if the namespace was set.
cmlenz
parents:
177
diff
changeset
|
215 text = """<html xmlns="http://www.w3.org/1999/xhtml"> |
8fb7df2e1281
Fix bug in XHTML serialization: all elements were allowed to be written out as empty if the namespace was set.
cmlenz
parents:
177
diff
changeset
|
216 <script src="foo.js" /> |
8fb7df2e1281
Fix bug in XHTML serialization: all elements were allowed to be written out as empty if the namespace was set.
cmlenz
parents:
177
diff
changeset
|
217 </html>""" |
177
dbae9efe5704
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
218 output = XML(text).render(XHTMLSerializer) |
178
8fb7df2e1281
Fix bug in XHTML serialization: all elements were allowed to be written out as empty if the namespace was set.
cmlenz
parents:
177
diff
changeset
|
219 self.assertEqual("""<html xmlns="http://www.w3.org/1999/xhtml"> |
8fb7df2e1281
Fix bug in XHTML serialization: all elements were allowed to be written out as empty if the namespace was set.
cmlenz
parents:
177
diff
changeset
|
220 <script src="foo.js"></script> |
8fb7df2e1281
Fix bug in XHTML serialization: all elements were allowed to be written out as empty if the namespace was set.
cmlenz
parents:
177
diff
changeset
|
221 </html>""", output) |
177
dbae9efe5704
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
222 |
141
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
223 def test_script_escaping(self): |
143
ef761afcedff
CDATA sections in XML input now appear as CDATA sections in the output. This should address the problem with escaping the contents of `<style>` and `<script>` elements, which would only get interpreted correctly if the output was served as `application/xhtml+xml`. Closes #24.
cmlenz
parents:
141
diff
changeset
|
224 text = """<script>/*<![CDATA[*/ |
ef761afcedff
CDATA sections in XML input now appear as CDATA sections in the output. This should address the problem with escaping the contents of `<style>` and `<script>` elements, which would only get interpreted correctly if the output was served as `application/xhtml+xml`. Closes #24.
cmlenz
parents:
141
diff
changeset
|
225 if (1 < 2) { alert("Doh"); } |
ef761afcedff
CDATA sections in XML input now appear as CDATA sections in the output. This should address the problem with escaping the contents of `<style>` and `<script>` elements, which would only get interpreted correctly if the output was served as `application/xhtml+xml`. Closes #24.
cmlenz
parents:
141
diff
changeset
|
226 /*]]>*/</script>""" |
141
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
227 output = XML(text).render(XHTMLSerializer) |
143
ef761afcedff
CDATA sections in XML input now appear as CDATA sections in the output. This should address the problem with escaping the contents of `<style>` and `<script>` elements, which would only get interpreted correctly if the output was served as `application/xhtml+xml`. Closes #24.
cmlenz
parents:
141
diff
changeset
|
228 self.assertEqual(text, output) |
141
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
229 |
280
e68705cb462e
The content of `<script>` and `<style>` elements is no longer escaped when serializing to HTML but declaring the XHTML namespace in the template.
cmlenz
parents:
230
diff
changeset
|
230 def test_script_escaping_with_namespace(self): |
e68705cb462e
The content of `<script>` and `<style>` elements is no longer escaped when serializing to HTML but declaring the XHTML namespace in the template.
cmlenz
parents:
230
diff
changeset
|
231 text = """<script xmlns="http://www.w3.org/1999/xhtml">/*<![CDATA[*/ |
e68705cb462e
The content of `<script>` and `<style>` elements is no longer escaped when serializing to HTML but declaring the XHTML namespace in the template.
cmlenz
parents:
230
diff
changeset
|
232 if (1 < 2) { alert("Doh"); } |
e68705cb462e
The content of `<script>` and `<style>` elements is no longer escaped when serializing to HTML but declaring the XHTML namespace in the template.
cmlenz
parents:
230
diff
changeset
|
233 /*]]>*/</script>""" |
e68705cb462e
The content of `<script>` and `<style>` elements is no longer escaped when serializing to HTML but declaring the XHTML namespace in the template.
cmlenz
parents:
230
diff
changeset
|
234 output = XML(text).render(XHTMLSerializer) |
e68705cb462e
The content of `<script>` and `<style>` elements is no longer escaped when serializing to HTML but declaring the XHTML namespace in the template.
cmlenz
parents:
230
diff
changeset
|
235 self.assertEqual(text, output) |
e68705cb462e
The content of `<script>` and `<style>` elements is no longer escaped when serializing to HTML but declaring the XHTML namespace in the template.
cmlenz
parents:
230
diff
changeset
|
236 |
141
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
237 def test_style_escaping(self): |
143
ef761afcedff
CDATA sections in XML input now appear as CDATA sections in the output. This should address the problem with escaping the contents of `<style>` and `<script>` elements, which would only get interpreted correctly if the output was served as `application/xhtml+xml`. Closes #24.
cmlenz
parents:
141
diff
changeset
|
238 text = """<style>/*<![CDATA[*/ |
ef761afcedff
CDATA sections in XML input now appear as CDATA sections in the output. This should address the problem with escaping the contents of `<style>` and `<script>` elements, which would only get interpreted correctly if the output was served as `application/xhtml+xml`. Closes #24.
cmlenz
parents:
141
diff
changeset
|
239 html > body { display: none; } |
ef761afcedff
CDATA sections in XML input now appear as CDATA sections in the output. This should address the problem with escaping the contents of `<style>` and `<script>` elements, which would only get interpreted correctly if the output was served as `application/xhtml+xml`. Closes #24.
cmlenz
parents:
141
diff
changeset
|
240 /*]]>*/</style>""" |
141
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
241 output = XML(text).render(XHTMLSerializer) |
143
ef761afcedff
CDATA sections in XML input now appear as CDATA sections in the output. This should address the problem with escaping the contents of `<style>` and `<script>` elements, which would only get interpreted correctly if the output was served as `application/xhtml+xml`. Closes #24.
cmlenz
parents:
141
diff
changeset
|
242 self.assertEqual(text, output) |
141
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
243 |
280
e68705cb462e
The content of `<script>` and `<style>` elements is no longer escaped when serializing to HTML but declaring the XHTML namespace in the template.
cmlenz
parents:
230
diff
changeset
|
244 def test_style_escaping_with_namespace(self): |
e68705cb462e
The content of `<script>` and `<style>` elements is no longer escaped when serializing to HTML but declaring the XHTML namespace in the template.
cmlenz
parents:
230
diff
changeset
|
245 text = """<style xmlns="http://www.w3.org/1999/xhtml">/*<![CDATA[*/ |
e68705cb462e
The content of `<script>` and `<style>` elements is no longer escaped when serializing to HTML but declaring the XHTML namespace in the template.
cmlenz
parents:
230
diff
changeset
|
246 html > body { display: none; } |
e68705cb462e
The content of `<script>` and `<style>` elements is no longer escaped when serializing to HTML but declaring the XHTML namespace in the template.
cmlenz
parents:
230
diff
changeset
|
247 /*]]>*/</style>""" |
e68705cb462e
The content of `<script>` and `<style>` elements is no longer escaped when serializing to HTML but declaring the XHTML namespace in the template.
cmlenz
parents:
230
diff
changeset
|
248 output = XML(text).render(XHTMLSerializer) |
e68705cb462e
The content of `<script>` and `<style>` elements is no longer escaped when serializing to HTML but declaring the XHTML namespace in the template.
cmlenz
parents:
230
diff
changeset
|
249 self.assertEqual(text, output) |
e68705cb462e
The content of `<script>` and `<style>` elements is no longer escaped when serializing to HTML but declaring the XHTML namespace in the template.
cmlenz
parents:
230
diff
changeset
|
250 |
158
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
251 def test_embedded_svg(self): |
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
252 text = """<html xmlns="http://www.w3.org/1999/xhtml" xmlns:svg="http://www.w3.org/2000/svg"> |
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
253 <body> |
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
254 <button> |
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
255 <svg:svg width="600px" height="400px"> |
500 | 256 <svg:polygon id="triangle" points="50,50 50,300 300,300"></svg:polygon> |
158
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
257 </svg:svg> |
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
258 </button> |
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
259 </body> |
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
260 </html>""" |
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
261 output = XML(text).render(XHTMLSerializer) |
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
262 self.assertEqual(text, output) |
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
263 |
177
dbae9efe5704
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
264 def test_xhtml_namespace_prefix(self): |
500 | 265 text = """<div xmlns="http://www.w3.org/1999/xhtml"> |
266 <strong>Hello</strong> | |
267 </div>""" | |
177
dbae9efe5704
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
268 output = XML(text).render(XHTMLSerializer) |
dbae9efe5704
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
269 self.assertEqual(text, output) |
dbae9efe5704
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
270 |
313
caafc67d2d0f
Handle expressions containing non-ASCII strings as arguments for `py:with`, `py:def`, and `py:for`.
cmlenz
parents:
280
diff
changeset
|
271 def test_nested_default_namespaces(self): |
314
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
272 stream = Stream([ |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
273 (Stream.START_NS, ('', 'http://example.org/'), (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
274 (Stream.START, (QName('div'), Attrs()), (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
275 (Stream.TEXT, '\n ', (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
276 (Stream.START_NS, ('', 'http://example.org/'), (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
277 (Stream.START, (QName('p'), Attrs()), (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
278 (Stream.END, QName('p'), (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
279 (Stream.END_NS, '', (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
280 (Stream.TEXT, '\n ', (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
281 (Stream.START_NS, ('', 'http://example.org/'), (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
282 (Stream.START, (QName('p'), Attrs()), (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
283 (Stream.END, QName('p'), (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
284 (Stream.END_NS, '', (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
285 (Stream.TEXT, '\n ', (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
286 (Stream.END, QName('div'), (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
287 (Stream.END_NS, '', (None, -1, -1)) |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
288 ]) |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
289 output = stream.render(XHTMLSerializer) |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
290 self.assertEqual("""<div xmlns="http://example.org/"> |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
291 <p></p> |
313
caafc67d2d0f
Handle expressions containing non-ASCII strings as arguments for `py:with`, `py:def`, and `py:for`.
cmlenz
parents:
280
diff
changeset
|
292 <p></p> |
caafc67d2d0f
Handle expressions containing non-ASCII strings as arguments for `py:with`, `py:def`, and `py:for`.
cmlenz
parents:
280
diff
changeset
|
293 </div>""", output) |
caafc67d2d0f
Handle expressions containing non-ASCII strings as arguments for `py:with`, `py:def`, and `py:for`.
cmlenz
parents:
280
diff
changeset
|
294 |
caafc67d2d0f
Handle expressions containing non-ASCII strings as arguments for `py:with`, `py:def`, and `py:for`.
cmlenz
parents:
280
diff
changeset
|
295 def test_nested_bound_namespaces(self): |
314
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
296 stream = Stream([ |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
297 (Stream.START_NS, ('x', 'http://example.org/'), (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
298 (Stream.START, (QName('div'), Attrs()), (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
299 (Stream.TEXT, '\n ', (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
300 (Stream.START_NS, ('x', 'http://example.org/'), (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
301 (Stream.START, (QName('p'), Attrs()), (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
302 (Stream.END, QName('p'), (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
303 (Stream.END_NS, 'x', (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
304 (Stream.TEXT, '\n ', (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
305 (Stream.START_NS, ('x', 'http://example.org/'), (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
306 (Stream.START, (QName('p'), Attrs()), (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
307 (Stream.END, QName('p'), (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
308 (Stream.END_NS, 'x', (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
309 (Stream.TEXT, '\n ', (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
310 (Stream.END, QName('div'), (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
311 (Stream.END_NS, 'x', (None, -1, -1)) |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
312 ]) |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
313 output = stream.render(XHTMLSerializer) |
313
caafc67d2d0f
Handle expressions containing non-ASCII strings as arguments for `py:with`, `py:def`, and `py:for`.
cmlenz
parents:
280
diff
changeset
|
314 self.assertEqual("""<div xmlns:x="http://example.org/"> |
314
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
315 <p></p> |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
316 <p></p> |
313
caafc67d2d0f
Handle expressions containing non-ASCII strings as arguments for `py:with`, `py:def`, and `py:for`.
cmlenz
parents:
280
diff
changeset
|
317 </div>""", output) |
caafc67d2d0f
Handle expressions containing non-ASCII strings as arguments for `py:with`, `py:def`, and `py:for`.
cmlenz
parents:
280
diff
changeset
|
318 |
500 | 319 def test_html5_doctype(self): |
320 stream = HTML('<html></html>') | |
321 output = stream.render(XHTMLSerializer, doctype=DocType.HTML5) | |
322 self.assertEqual('<!DOCTYPE html>\n<html></html>', output) | |
323 | |
123
93bbdcf9428b
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
324 |
93bbdcf9428b
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
325 class HTMLSerializerTestCase(unittest.TestCase): |
93bbdcf9428b
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
326 |
347 | 327 def test_textarea_whitespace(self): |
328 content = '\nHey there. \n\n I am indented.\n' | |
329 stream = XML('<textarea name="foo">%s</textarea>' % content) | |
330 output = stream.render(HTMLSerializer) | |
331 self.assertEqual('<textarea name="foo">%s</textarea>' % content, output) | |
332 | |
333 def test_pre_whitespace(self): | |
334 content = '\nHey <em>there</em>. \n\n I am indented.\n' | |
335 stream = XML('<pre>%s</pre>' % content) | |
336 output = stream.render(HTMLSerializer) | |
337 self.assertEqual('<pre>%s</pre>' % content, output) | |
338 | |
123
93bbdcf9428b
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
339 def test_xml_space(self): |
93bbdcf9428b
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
340 text = '<foo xml:space="preserve"> Do not mess \n\n with me </foo>' |
141
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
341 output = XML(text).render(HTMLSerializer) |
123
93bbdcf9428b
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
342 self.assertEqual('<foo> Do not mess \n\n with me </foo>', output) |
93bbdcf9428b
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
343 |
177
dbae9efe5704
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
344 def test_empty_script(self): |
dbae9efe5704
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
345 text = '<script src="foo.js" />' |
dbae9efe5704
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
346 output = XML(text).render(XHTMLSerializer) |
dbae9efe5704
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
347 self.assertEqual('<script src="foo.js"></script>', output) |
dbae9efe5704
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
348 |
141
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
349 def test_script_escaping(self): |
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
350 text = '<script>if (1 < 2) { alert("Doh"); }</script>' |
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
351 output = XML(text).render(HTMLSerializer) |
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
352 self.assertEqual('<script>if (1 < 2) { alert("Doh"); }</script>', |
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
353 output) |
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
354 |
280
e68705cb462e
The content of `<script>` and `<style>` elements is no longer escaped when serializing to HTML but declaring the XHTML namespace in the template.
cmlenz
parents:
230
diff
changeset
|
355 def test_script_escaping_with_namespace(self): |
e68705cb462e
The content of `<script>` and `<style>` elements is no longer escaped when serializing to HTML but declaring the XHTML namespace in the template.
cmlenz
parents:
230
diff
changeset
|
356 text = """<script xmlns="http://www.w3.org/1999/xhtml"> |
e68705cb462e
The content of `<script>` and `<style>` elements is no longer escaped when serializing to HTML but declaring the XHTML namespace in the template.
cmlenz
parents:
230
diff
changeset
|
357 if (1 < 2) { alert("Doh"); } |
e68705cb462e
The content of `<script>` and `<style>` elements is no longer escaped when serializing to HTML but declaring the XHTML namespace in the template.
cmlenz
parents:
230
diff
changeset
|
358 </script>""" |
e68705cb462e
The content of `<script>` and `<style>` elements is no longer escaped when serializing to HTML but declaring the XHTML namespace in the template.
cmlenz
parents:
230
diff
changeset
|
359 output = XML(text).render(HTMLSerializer) |
e68705cb462e
The content of `<script>` and `<style>` elements is no longer escaped when serializing to HTML but declaring the XHTML namespace in the template.
cmlenz
parents:
230
diff
changeset
|
360 self.assertEqual("""<script> |
e68705cb462e
The content of `<script>` and `<style>` elements is no longer escaped when serializing to HTML but declaring the XHTML namespace in the template.
cmlenz
parents:
230
diff
changeset
|
361 if (1 < 2) { alert("Doh"); } |
e68705cb462e
The content of `<script>` and `<style>` elements is no longer escaped when serializing to HTML but declaring the XHTML namespace in the template.
cmlenz
parents:
230
diff
changeset
|
362 </script>""", output) |
e68705cb462e
The content of `<script>` and `<style>` elements is no longer escaped when serializing to HTML but declaring the XHTML namespace in the template.
cmlenz
parents:
230
diff
changeset
|
363 |
141
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
364 def test_style_escaping(self): |
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
365 text = '<style>html > body { display: none; }</style>' |
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
366 output = XML(text).render(HTMLSerializer) |
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
367 self.assertEqual('<style>html > body { display: none; }</style>', |
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
368 output) |
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
369 |
280
e68705cb462e
The content of `<script>` and `<style>` elements is no longer escaped when serializing to HTML but declaring the XHTML namespace in the template.
cmlenz
parents:
230
diff
changeset
|
370 def test_style_escaping_with_namespace(self): |
e68705cb462e
The content of `<script>` and `<style>` elements is no longer escaped when serializing to HTML but declaring the XHTML namespace in the template.
cmlenz
parents:
230
diff
changeset
|
371 text = """<style xmlns="http://www.w3.org/1999/xhtml"> |
e68705cb462e
The content of `<script>` and `<style>` elements is no longer escaped when serializing to HTML but declaring the XHTML namespace in the template.
cmlenz
parents:
230
diff
changeset
|
372 html > body { display: none; } |
e68705cb462e
The content of `<script>` and `<style>` elements is no longer escaped when serializing to HTML but declaring the XHTML namespace in the template.
cmlenz
parents:
230
diff
changeset
|
373 </style>""" |
e68705cb462e
The content of `<script>` and `<style>` elements is no longer escaped when serializing to HTML but declaring the XHTML namespace in the template.
cmlenz
parents:
230
diff
changeset
|
374 output = XML(text).render(HTMLSerializer) |
e68705cb462e
The content of `<script>` and `<style>` elements is no longer escaped when serializing to HTML but declaring the XHTML namespace in the template.
cmlenz
parents:
230
diff
changeset
|
375 self.assertEqual("""<style> |
e68705cb462e
The content of `<script>` and `<style>` elements is no longer escaped when serializing to HTML but declaring the XHTML namespace in the template.
cmlenz
parents:
230
diff
changeset
|
376 html > body { display: none; } |
e68705cb462e
The content of `<script>` and `<style>` elements is no longer escaped when serializing to HTML but declaring the XHTML namespace in the template.
cmlenz
parents:
230
diff
changeset
|
377 </style>""", output) |
e68705cb462e
The content of `<script>` and `<style>` elements is no longer escaped when serializing to HTML but declaring the XHTML namespace in the template.
cmlenz
parents:
230
diff
changeset
|
378 |
500 | 379 def test_html5_doctype(self): |
380 stream = HTML('<html></html>') | |
381 output = stream.render(HTMLSerializer, doctype=DocType.HTML5) | |
382 self.assertEqual('<!DOCTYPE html>\n<html></html>', output) | |
383 | |
123
93bbdcf9428b
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
384 |
212
e8c43127d9a9
Refactored the handling of empty tags in the serializer: use an `EmptyTagFilter` that combines adjacent start/end events, instead of the generic pushback-iterator.
cmlenz
parents:
178
diff
changeset
|
385 class EmptyTagFilterTestCase(unittest.TestCase): |
e8c43127d9a9
Refactored the handling of empty tags in the serializer: use an `EmptyTagFilter` that combines adjacent start/end events, instead of the generic pushback-iterator.
cmlenz
parents:
178
diff
changeset
|
386 |
e8c43127d9a9
Refactored the handling of empty tags in the serializer: use an `EmptyTagFilter` that combines adjacent start/end events, instead of the generic pushback-iterator.
cmlenz
parents:
178
diff
changeset
|
387 def test_empty(self): |
e8c43127d9a9
Refactored the handling of empty tags in the serializer: use an `EmptyTagFilter` that combines adjacent start/end events, instead of the generic pushback-iterator.
cmlenz
parents:
178
diff
changeset
|
388 stream = XML('<elem></elem>') | EmptyTagFilter() |
e8c43127d9a9
Refactored the handling of empty tags in the serializer: use an `EmptyTagFilter` that combines adjacent start/end events, instead of the generic pushback-iterator.
cmlenz
parents:
178
diff
changeset
|
389 self.assertEqual([EmptyTagFilter.EMPTY], [ev[0] for ev in stream]) |
e8c43127d9a9
Refactored the handling of empty tags in the serializer: use an `EmptyTagFilter` that combines adjacent start/end events, instead of the generic pushback-iterator.
cmlenz
parents:
178
diff
changeset
|
390 |
e8c43127d9a9
Refactored the handling of empty tags in the serializer: use an `EmptyTagFilter` that combines adjacent start/end events, instead of the generic pushback-iterator.
cmlenz
parents:
178
diff
changeset
|
391 def test_text_content(self): |
e8c43127d9a9
Refactored the handling of empty tags in the serializer: use an `EmptyTagFilter` that combines adjacent start/end events, instead of the generic pushback-iterator.
cmlenz
parents:
178
diff
changeset
|
392 stream = XML('<elem>foo</elem>') | EmptyTagFilter() |
e8c43127d9a9
Refactored the handling of empty tags in the serializer: use an `EmptyTagFilter` that combines adjacent start/end events, instead of the generic pushback-iterator.
cmlenz
parents:
178
diff
changeset
|
393 self.assertEqual([Stream.START, Stream.TEXT, Stream.END], |
e8c43127d9a9
Refactored the handling of empty tags in the serializer: use an `EmptyTagFilter` that combines adjacent start/end events, instead of the generic pushback-iterator.
cmlenz
parents:
178
diff
changeset
|
394 [ev[0] for ev in stream]) |
e8c43127d9a9
Refactored the handling of empty tags in the serializer: use an `EmptyTagFilter` that combines adjacent start/end events, instead of the generic pushback-iterator.
cmlenz
parents:
178
diff
changeset
|
395 |
e8c43127d9a9
Refactored the handling of empty tags in the serializer: use an `EmptyTagFilter` that combines adjacent start/end events, instead of the generic pushback-iterator.
cmlenz
parents:
178
diff
changeset
|
396 def test_elem_content(self): |
e8c43127d9a9
Refactored the handling of empty tags in the serializer: use an `EmptyTagFilter` that combines adjacent start/end events, instead of the generic pushback-iterator.
cmlenz
parents:
178
diff
changeset
|
397 stream = XML('<elem><sub /><sub /></elem>') | EmptyTagFilter() |
e8c43127d9a9
Refactored the handling of empty tags in the serializer: use an `EmptyTagFilter` that combines adjacent start/end events, instead of the generic pushback-iterator.
cmlenz
parents:
178
diff
changeset
|
398 self.assertEqual([Stream.START, EmptyTagFilter.EMPTY, |
e8c43127d9a9
Refactored the handling of empty tags in the serializer: use an `EmptyTagFilter` that combines adjacent start/end events, instead of the generic pushback-iterator.
cmlenz
parents:
178
diff
changeset
|
399 EmptyTagFilter.EMPTY, Stream.END], |
e8c43127d9a9
Refactored the handling of empty tags in the serializer: use an `EmptyTagFilter` that combines adjacent start/end events, instead of the generic pushback-iterator.
cmlenz
parents:
178
diff
changeset
|
400 [ev[0] for ev in stream]) |
e8c43127d9a9
Refactored the handling of empty tags in the serializer: use an `EmptyTagFilter` that combines adjacent start/end events, instead of the generic pushback-iterator.
cmlenz
parents:
178
diff
changeset
|
401 |
e8c43127d9a9
Refactored the handling of empty tags in the serializer: use an `EmptyTagFilter` that combines adjacent start/end events, instead of the generic pushback-iterator.
cmlenz
parents:
178
diff
changeset
|
402 |
1 | 403 def suite(): |
404 suite = unittest.TestSuite() | |
85 | 405 suite.addTest(unittest.makeSuite(XMLSerializerTestCase, 'test')) |
123
93bbdcf9428b
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
406 suite.addTest(unittest.makeSuite(XHTMLSerializerTestCase, 'test')) |
93bbdcf9428b
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
407 suite.addTest(unittest.makeSuite(HTMLSerializerTestCase, 'test')) |
212
e8c43127d9a9
Refactored the handling of empty tags in the serializer: use an `EmptyTagFilter` that combines adjacent start/end events, instead of the generic pushback-iterator.
cmlenz
parents:
178
diff
changeset
|
408 suite.addTest(unittest.makeSuite(EmptyTagFilterTestCase, 'test')) |
85 | 409 suite.addTest(doctest.DocTestSuite(XMLSerializer.__module__)) |
1 | 410 return suite |
411 | |
412 if __name__ == '__main__': | |
413 unittest.main(defaultTest='suite') |