Mercurial > genshi > mirror
annotate genshi/tests/output.py @ 932:18209925c54e trunk
Merge r1140 from py3k:
add support for python 3 to core genshi components (genshi.core, genshi.input and genshi.output):
* default input and output encodings changed from UTF-8 to None (i.e. unicode strings)
* Namespace and QName objects do not call stringrepr in __repr__ in Python 3 since repr() returns a unicode string there.
* track changes to expat parser in Python 3 (mostly it accepts bytes instead of strings)
author | hodgestar |
---|---|
date | Fri, 18 Mar 2011 09:08:12 +0000 |
parents | f4543bebe41b |
children | f15334b65cf8 |
rev | line source |
---|---|
1 | 1 # -*- coding: utf-8 -*- |
2 # | |
741 | 3 # Copyright (C) 2006-2008 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
06a25d0962af
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
0141f45c18e1
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 | |
729 | 26 def test_with_xml_decl(self): |
671
8a9a7a8e9478
Add a stream filter to insert the XML DOCTYPE in the correct location (ie.
athomas
parents:
524
diff
changeset
|
27 stream = Stream([(Stream.XML_DECL, ('1.0', None, -1), (None, -1, -1))]) |
862 | 28 output = stream.render(XMLSerializer, doctype='xhtml', encoding=None) |
671
8a9a7a8e9478
Add a stream filter to insert the XML DOCTYPE in the correct location (ie.
athomas
parents:
524
diff
changeset
|
29 self.assertEqual('<?xml version="1.0"?>\n' |
8a9a7a8e9478
Add a stream filter to insert the XML DOCTYPE in the correct location (ie.
athomas
parents:
524
diff
changeset
|
30 '<!DOCTYPE html PUBLIC ' |
8a9a7a8e9478
Add a stream filter to insert the XML DOCTYPE in the correct location (ie.
athomas
parents:
524
diff
changeset
|
31 '"-//W3C//DTD XHTML 1.0 Strict//EN" ' |
8a9a7a8e9478
Add a stream filter to insert the XML DOCTYPE in the correct location (ie.
athomas
parents:
524
diff
changeset
|
32 '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n', |
8a9a7a8e9478
Add a stream filter to insert the XML DOCTYPE in the correct location (ie.
athomas
parents:
524
diff
changeset
|
33 output) |
8a9a7a8e9478
Add a stream filter to insert the XML DOCTYPE in the correct location (ie.
athomas
parents:
524
diff
changeset
|
34 |
85 | 35 def test_doctype_in_stream(self): |
314
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
36 stream = Stream([(Stream.DOCTYPE, DocType.HTML_STRICT, (None, -1, -1))]) |
862 | 37 output = stream.render(XMLSerializer, encoding=None) |
85 | 38 self.assertEqual('<!DOCTYPE html PUBLIC ' |
39 '"-//W3C//DTD HTML 4.01//EN" ' | |
40 '"http://www.w3.org/TR/html4/strict.dtd">\n', | |
41 output) | |
42 | |
43 def test_doctype_in_stream_no_sysid(self): | |
44 stream = Stream([(Stream.DOCTYPE, | |
45 ('html', '-//W3C//DTD HTML 4.01//EN', None), | |
314
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
46 (None, -1, -1))]) |
862 | 47 output = stream.render(XMLSerializer, encoding=None) |
85 | 48 self.assertEqual('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">\n', |
49 output) | |
50 | |
51 def test_doctype_in_stream_no_pubid(self): | |
314
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
52 stream = Stream([ |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
53 (Stream.DOCTYPE, |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
54 ('html', None, 'http://www.w3.org/TR/html4/strict.dtd'), |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
55 (None, -1, -1)) |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
56 ]) |
862 | 57 output = stream.render(XMLSerializer, encoding=None) |
85 | 58 self.assertEqual('<!DOCTYPE html SYSTEM ' |
59 '"http://www.w3.org/TR/html4/strict.dtd">\n', | |
60 output) | |
61 | |
62 def test_doctype_in_stream_no_pubid_or_sysid(self): | |
63 stream = Stream([(Stream.DOCTYPE, ('html', None, None), | |
314
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
64 (None, -1, -1))]) |
862 | 65 output = stream.render(XMLSerializer, encoding=None) |
85 | 66 self.assertEqual('<!DOCTYPE html>\n', output) |
67 | |
68 def test_serializer_doctype(self): | |
69 stream = Stream([]) | |
862 | 70 output = stream.render(XMLSerializer, doctype=DocType.HTML_STRICT, |
71 encoding=None) | |
85 | 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 | |
77 def test_doctype_one_and_only(self): | |
314
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
78 stream = Stream([ |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
79 (Stream.DOCTYPE, ('html', None, None), (None, -1, -1)) |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
80 ]) |
862 | 81 output = stream.render(XMLSerializer, doctype=DocType.HTML_STRICT, |
82 encoding=None) | |
85 | 83 self.assertEqual('<!DOCTYPE html PUBLIC ' |
84 '"-//W3C//DTD HTML 4.01//EN" ' | |
85 '"http://www.w3.org/TR/html4/strict.dtd">\n', | |
86 output) | |
87 | |
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:
85
diff
changeset
|
88 def test_comment(self): |
314
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
89 stream = Stream([(Stream.COMMENT, 'foo bar', (None, -1, -1))]) |
862 | 90 output = stream.render(XMLSerializer, encoding=None) |
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:
85
diff
changeset
|
91 self.assertEqual('<!--foo bar-->', output) |
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:
85
diff
changeset
|
92 |
105
71f3db26eecb
Include processing instructions in serialized streams.
cmlenz
parents:
89
diff
changeset
|
93 def test_processing_instruction(self): |
314
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
94 stream = Stream([(Stream.PI, ('python', 'x = 2'), (None, -1, -1))]) |
862 | 95 output = stream.render(XMLSerializer, encoding=None) |
105
71f3db26eecb
Include processing instructions in serialized streams.
cmlenz
parents:
89
diff
changeset
|
96 self.assertEqual('<?python x = 2?>', output) |
71f3db26eecb
Include processing instructions in serialized streams.
cmlenz
parents:
89
diff
changeset
|
97 |
313
d72d842e1083
Handle expressions containing non-ASCII strings as arguments for `py:with`, `py:def`, and `py:for`.
cmlenz
parents:
280
diff
changeset
|
98 def test_nested_default_namespaces(self): |
314
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
99 stream = Stream([ |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
100 (Stream.START_NS, ('', 'http://example.org/'), (None, -1, -1)), |
402
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
101 (Stream.START, (QName('http://example.org/}div'), Attrs()), (None, -1, -1)), |
314
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
102 (Stream.TEXT, '\n ', (None, -1, -1)), |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
103 (Stream.START_NS, ('', 'http://example.org/'), (None, -1, -1)), |
402
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
104 (Stream.START, (QName('http://example.org/}p'), Attrs()), (None, -1, -1)), |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
105 (Stream.END, QName('http://example.org/}p'), (None, -1, -1)), |
314
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
106 (Stream.END_NS, '', (None, -1, -1)), |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
107 (Stream.TEXT, '\n ', (None, -1, -1)), |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
108 (Stream.START_NS, ('', 'http://example.org/'), (None, -1, -1)), |
402
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
109 (Stream.START, (QName('http://example.org/}p'), Attrs()), (None, -1, -1)), |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
110 (Stream.END, QName('http://example.org/}p'), (None, -1, -1)), |
314
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
111 (Stream.END_NS, '', (None, -1, -1)), |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
112 (Stream.TEXT, '\n ', (None, -1, -1)), |
402
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
113 (Stream.END, QName('http://example.org/}div'), (None, -1, -1)), |
314
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
114 (Stream.END_NS, '', (None, -1, -1)) |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
115 ]) |
862 | 116 output = stream.render(XMLSerializer, encoding=None) |
314
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
117 self.assertEqual("""<div xmlns="http://example.org/"> |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
118 <p/> |
313
d72d842e1083
Handle expressions containing non-ASCII strings as arguments for `py:with`, `py:def`, and `py:for`.
cmlenz
parents:
280
diff
changeset
|
119 <p/> |
d72d842e1083
Handle expressions containing non-ASCII strings as arguments for `py:with`, `py:def`, and `py:for`.
cmlenz
parents:
280
diff
changeset
|
120 </div>""", output) |
d72d842e1083
Handle expressions containing non-ASCII strings as arguments for `py:with`, `py:def`, and `py:for`.
cmlenz
parents:
280
diff
changeset
|
121 |
d72d842e1083
Handle expressions containing non-ASCII strings as arguments for `py:with`, `py:def`, and `py:for`.
cmlenz
parents:
280
diff
changeset
|
122 def test_nested_bound_namespaces(self): |
314
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
123 stream = Stream([ |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
124 (Stream.START_NS, ('x', 'http://example.org/'), (None, -1, -1)), |
402
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
125 (Stream.START, (QName('http://example.org/}div'), Attrs()), (None, -1, -1)), |
314
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
126 (Stream.TEXT, '\n ', (None, -1, -1)), |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
127 (Stream.START_NS, ('x', 'http://example.org/'), (None, -1, -1)), |
402
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
128 (Stream.START, (QName('http://example.org/}p'), Attrs()), (None, -1, -1)), |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
129 (Stream.END, QName('http://example.org/}p'), (None, -1, -1)), |
314
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
130 (Stream.END_NS, 'x', (None, -1, -1)), |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
131 (Stream.TEXT, '\n ', (None, -1, -1)), |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
132 (Stream.START_NS, ('x', 'http://example.org/'), (None, -1, -1)), |
402
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
133 (Stream.START, (QName('http://example.org/}p'), Attrs()), (None, -1, -1)), |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
134 (Stream.END, QName('http://example.org/}p'), (None, -1, -1)), |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
135 (Stream.END_NS, 'x', (None, -1, -1)), |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
136 (Stream.TEXT, '\n ', (None, -1, -1)), |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
137 (Stream.END, QName('http://example.org/}div'), (None, -1, -1)), |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
138 (Stream.END_NS, 'x', (None, -1, -1)) |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
139 ]) |
862 | 140 output = stream.render(XMLSerializer, encoding=None) |
402
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
141 self.assertEqual("""<x:div xmlns:x="http://example.org/"> |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
142 <x:p/> |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
143 <x:p/> |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
144 </x:div>""", output) |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
145 |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
146 def test_multiple_default_namespaces(self): |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
147 stream = Stream([ |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
148 (Stream.START, (QName('div'), Attrs()), (None, -1, -1)), |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
149 (Stream.TEXT, '\n ', (None, -1, -1)), |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
150 (Stream.START_NS, ('', 'http://example.org/'), (None, -1, -1)), |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
151 (Stream.START, (QName('http://example.org/}p'), Attrs()), (None, -1, -1)), |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
152 (Stream.END, QName('http://example.org/}p'), (None, -1, -1)), |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
153 (Stream.END_NS, '', (None, -1, -1)), |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
154 (Stream.TEXT, '\n ', (None, -1, -1)), |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
155 (Stream.START_NS, ('', 'http://example.org/'), (None, -1, -1)), |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
156 (Stream.START, (QName('http://example.org/}p'), Attrs()), (None, -1, -1)), |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
157 (Stream.END, QName('http://example.org/}p'), (None, -1, -1)), |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
158 (Stream.END_NS, '', (None, -1, -1)), |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
159 (Stream.TEXT, '\n ', (None, -1, -1)), |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
160 (Stream.END, QName('div'), (None, -1, -1)), |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
161 ]) |
862 | 162 output = stream.render(XMLSerializer, encoding=None) |
402
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
163 self.assertEqual("""<div> |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
164 <p xmlns="http://example.org/"/> |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
165 <p xmlns="http://example.org/"/> |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
166 </div>""", output) |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
167 |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
168 def test_multiple_bound_namespaces(self): |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
169 stream = Stream([ |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
170 (Stream.START, (QName('div'), Attrs()), (None, -1, -1)), |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
171 (Stream.TEXT, '\n ', (None, -1, -1)), |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
172 (Stream.START_NS, ('x', 'http://example.org/'), (None, -1, -1)), |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
173 (Stream.START, (QName('http://example.org/}p'), Attrs()), (None, -1, -1)), |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
174 (Stream.END, QName('http://example.org/}p'), (None, -1, -1)), |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
175 (Stream.END_NS, 'x', (None, -1, -1)), |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
176 (Stream.TEXT, '\n ', (None, -1, -1)), |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
177 (Stream.START_NS, ('x', 'http://example.org/'), (None, -1, -1)), |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
178 (Stream.START, (QName('http://example.org/}p'), Attrs()), (None, -1, -1)), |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
179 (Stream.END, QName('http://example.org/}p'), (None, -1, -1)), |
314
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
180 (Stream.END_NS, 'x', (None, -1, -1)), |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
181 (Stream.TEXT, '\n ', (None, -1, -1)), |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
182 (Stream.END, QName('div'), (None, -1, -1)), |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
183 ]) |
862 | 184 output = stream.render(XMLSerializer, encoding=None) |
402
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
185 self.assertEqual("""<div> |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
186 <x:p xmlns:x="http://example.org/"/> |
c199e9b95884
Fix output of namespace declarations for namespace URLs appearing more than once in a stream. Thanks to Jeff Cutsinger for reporting the problem.
cmlenz
parents:
346
diff
changeset
|
187 <x:p xmlns:x="http://example.org/"/> |
313
d72d842e1083
Handle expressions containing non-ASCII strings as arguments for `py:with`, `py:def`, and `py:for`.
cmlenz
parents:
280
diff
changeset
|
188 </div>""", output) |
d72d842e1083
Handle expressions containing non-ASCII strings as arguments for `py:with`, `py:def`, and `py:for`.
cmlenz
parents:
280
diff
changeset
|
189 |
410
d14d89995c29
Improve the handling of namespaces in serialization.
cmlenz
parents:
408
diff
changeset
|
190 def test_atom_with_xhtml(self): |
d14d89995c29
Improve the handling of namespaces in serialization.
cmlenz
parents:
408
diff
changeset
|
191 text = """<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"> |
d14d89995c29
Improve the handling of namespaces in serialization.
cmlenz
parents:
408
diff
changeset
|
192 <id>urn:uuid:c60843aa-0da8-4fa6-bbe5-98007bc6774e</id> |
d14d89995c29
Improve the handling of namespaces in serialization.
cmlenz
parents:
408
diff
changeset
|
193 <updated>2007-01-28T11:36:02.807108-06:00</updated> |
d14d89995c29
Improve the handling of namespaces in serialization.
cmlenz
parents:
408
diff
changeset
|
194 <title type="xhtml"> |
d14d89995c29
Improve the handling of namespaces in serialization.
cmlenz
parents:
408
diff
changeset
|
195 <div xmlns="http://www.w3.org/1999/xhtml">Example</div> |
d14d89995c29
Improve the handling of namespaces in serialization.
cmlenz
parents:
408
diff
changeset
|
196 </title> |
d14d89995c29
Improve the handling of namespaces in serialization.
cmlenz
parents:
408
diff
changeset
|
197 <subtitle type="xhtml"> |
d14d89995c29
Improve the handling of namespaces in serialization.
cmlenz
parents:
408
diff
changeset
|
198 <div xmlns="http://www.w3.org/1999/xhtml">Bla bla bla</div> |
d14d89995c29
Improve the handling of namespaces in serialization.
cmlenz
parents:
408
diff
changeset
|
199 </subtitle> |
d14d89995c29
Improve the handling of namespaces in serialization.
cmlenz
parents:
408
diff
changeset
|
200 <icon/> |
d14d89995c29
Improve the handling of namespaces in serialization.
cmlenz
parents:
408
diff
changeset
|
201 </feed>""" |
862 | 202 output = XML(text).render(XMLSerializer, encoding=None) |
410
d14d89995c29
Improve the handling of namespaces in serialization.
cmlenz
parents:
408
diff
changeset
|
203 self.assertEqual(text, output) |
d14d89995c29
Improve the handling of namespaces in serialization.
cmlenz
parents:
408
diff
changeset
|
204 |
1 | 205 |
123
10279d2eeec9
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
206 class XHTMLSerializerTestCase(unittest.TestCase): |
10279d2eeec9
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
207 |
729 | 208 def test_xml_decl_dropped(self): |
209 stream = Stream([(Stream.XML_DECL, ('1.0', None, -1), (None, -1, -1))]) | |
862 | 210 output = stream.render(XHTMLSerializer, doctype='xhtml', encoding=None) |
729 | 211 self.assertEqual('<!DOCTYPE html PUBLIC ' |
212 '"-//W3C//DTD XHTML 1.0 Strict//EN" ' | |
213 '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n', | |
214 output) | |
215 | |
216 def test_xml_decl_included(self): | |
217 stream = Stream([(Stream.XML_DECL, ('1.0', None, -1), (None, -1, -1))]) | |
218 output = stream.render(XHTMLSerializer, doctype='xhtml', | |
862 | 219 drop_xml_decl=False, encoding=None) |
729 | 220 self.assertEqual('<?xml version="1.0"?>\n' |
221 '<!DOCTYPE html PUBLIC ' | |
222 '"-//W3C//DTD XHTML 1.0 Strict//EN" ' | |
223 '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n', | |
224 output) | |
225 | |
524
7553760b58af
Add special handling for `xml:lang` to HTML/XHTML serialization.
cmlenz
parents:
448
diff
changeset
|
226 def test_xml_lang(self): |
7553760b58af
Add special handling for `xml:lang` to HTML/XHTML serialization.
cmlenz
parents:
448
diff
changeset
|
227 text = '<p xml:lang="en">English text</p>' |
862 | 228 output = XML(text).render(XHTMLSerializer, encoding=None) |
524
7553760b58af
Add special handling for `xml:lang` to HTML/XHTML serialization.
cmlenz
parents:
448
diff
changeset
|
229 self.assertEqual('<p lang="en" xml:lang="en">English text</p>', output) |
7553760b58af
Add special handling for `xml:lang` to HTML/XHTML serialization.
cmlenz
parents:
448
diff
changeset
|
230 |
7553760b58af
Add special handling for `xml:lang` to HTML/XHTML serialization.
cmlenz
parents:
448
diff
changeset
|
231 def test_xml_lang_nodup(self): |
7553760b58af
Add special handling for `xml:lang` to HTML/XHTML serialization.
cmlenz
parents:
448
diff
changeset
|
232 text = '<p xml:lang="en" lang="en">English text</p>' |
862 | 233 output = XML(text).render(XHTMLSerializer, encoding=None) |
524
7553760b58af
Add special handling for `xml:lang` to HTML/XHTML serialization.
cmlenz
parents:
448
diff
changeset
|
234 self.assertEqual('<p xml:lang="en" lang="en">English text</p>', output) |
7553760b58af
Add special handling for `xml:lang` to HTML/XHTML serialization.
cmlenz
parents:
448
diff
changeset
|
235 |
123
10279d2eeec9
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
236 def test_textarea_whitespace(self): |
10279d2eeec9
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
237 content = '\nHey there. \n\n I am indented.\n' |
141
520a5b7dd6d2
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
238 stream = XML('<textarea name="foo">%s</textarea>' % content) |
862 | 239 output = stream.render(XHTMLSerializer, encoding=None) |
123
10279d2eeec9
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
240 self.assertEqual('<textarea name="foo">%s</textarea>' % content, output) |
10279d2eeec9
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
241 |
346
96882a191686
Whitespace was not getting preserved in HTML `<pre>` elements that contained other HTML elements.
cmlenz
parents:
314
diff
changeset
|
242 def test_pre_whitespace(self): |
96882a191686
Whitespace was not getting preserved in HTML `<pre>` elements that contained other HTML elements.
cmlenz
parents:
314
diff
changeset
|
243 content = '\nHey <em>there</em>. \n\n I am indented.\n' |
96882a191686
Whitespace was not getting preserved in HTML `<pre>` elements that contained other HTML elements.
cmlenz
parents:
314
diff
changeset
|
244 stream = XML('<pre>%s</pre>' % content) |
862 | 245 output = stream.render(XHTMLSerializer, encoding=None) |
346
96882a191686
Whitespace was not getting preserved in HTML `<pre>` elements that contained other HTML elements.
cmlenz
parents:
314
diff
changeset
|
246 self.assertEqual('<pre>%s</pre>' % content, output) |
96882a191686
Whitespace was not getting preserved in HTML `<pre>` elements that contained other HTML elements.
cmlenz
parents:
314
diff
changeset
|
247 |
123
10279d2eeec9
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
248 def test_xml_space(self): |
10279d2eeec9
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
249 text = '<foo xml:space="preserve"> Do not mess \n\n with me </foo>' |
862 | 250 output = XML(text).render(XHTMLSerializer, encoding=None) |
689
3881a602048a
The XHTML serializer now strips `xml:space` attributes as they are only allowed on very few tags.
cmlenz
parents:
671
diff
changeset
|
251 self.assertEqual('<foo> Do not mess \n\n with me </foo>', output) |
123
10279d2eeec9
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
252 |
177
553866249cb0
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
253 def test_empty_script(self): |
178
ba7556e3a835
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
|
254 text = """<html xmlns="http://www.w3.org/1999/xhtml"> |
ba7556e3a835
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
|
255 <script src="foo.js" /> |
ba7556e3a835
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
|
256 </html>""" |
862 | 257 output = XML(text).render(XHTMLSerializer, encoding=None) |
178
ba7556e3a835
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
|
258 self.assertEqual("""<html xmlns="http://www.w3.org/1999/xhtml"> |
ba7556e3a835
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
|
259 <script src="foo.js"></script> |
ba7556e3a835
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
|
260 </html>""", output) |
177
553866249cb0
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
261 |
141
520a5b7dd6d2
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
262 def test_script_escaping(self): |
143
3d4c214c979a
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
|
263 text = """<script>/*<![CDATA[*/ |
3d4c214c979a
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
|
264 if (1 < 2) { alert("Doh"); } |
3d4c214c979a
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
|
265 /*]]>*/</script>""" |
862 | 266 output = XML(text).render(XHTMLSerializer, encoding=None) |
143
3d4c214c979a
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
|
267 self.assertEqual(text, output) |
141
520a5b7dd6d2
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
268 |
280
ce848f7c41f1
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
|
269 def test_script_escaping_with_namespace(self): |
ce848f7c41f1
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
|
270 text = """<script xmlns="http://www.w3.org/1999/xhtml">/*<![CDATA[*/ |
ce848f7c41f1
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
|
271 if (1 < 2) { alert("Doh"); } |
ce848f7c41f1
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
|
272 /*]]>*/</script>""" |
862 | 273 output = XML(text).render(XHTMLSerializer, encoding=None) |
280
ce848f7c41f1
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
|
274 self.assertEqual(text, output) |
ce848f7c41f1
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
|
275 |
141
520a5b7dd6d2
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
276 def test_style_escaping(self): |
143
3d4c214c979a
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
|
277 text = """<style>/*<![CDATA[*/ |
3d4c214c979a
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
|
278 html > body { display: none; } |
3d4c214c979a
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
|
279 /*]]>*/</style>""" |
862 | 280 output = XML(text).render(XHTMLSerializer, encoding=None) |
143
3d4c214c979a
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
|
281 self.assertEqual(text, output) |
141
520a5b7dd6d2
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
282 |
280
ce848f7c41f1
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
|
283 def test_style_escaping_with_namespace(self): |
ce848f7c41f1
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
|
284 text = """<style xmlns="http://www.w3.org/1999/xhtml">/*<![CDATA[*/ |
ce848f7c41f1
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
|
285 html > body { display: none; } |
ce848f7c41f1
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
|
286 /*]]>*/</style>""" |
862 | 287 output = XML(text).render(XHTMLSerializer, encoding=None) |
280
ce848f7c41f1
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
|
288 self.assertEqual(text, output) |
ce848f7c41f1
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
|
289 |
158
3f23fafeef99
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
290 def test_embedded_svg(self): |
3f23fafeef99
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
291 text = """<html xmlns="http://www.w3.org/1999/xhtml" xmlns:svg="http://www.w3.org/2000/svg"> |
3f23fafeef99
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
292 <body> |
3f23fafeef99
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
293 <button> |
3f23fafeef99
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
294 <svg:svg width="600px" height="400px"> |
410
d14d89995c29
Improve the handling of namespaces in serialization.
cmlenz
parents:
408
diff
changeset
|
295 <svg:polygon id="triangle" points="50,50 50,300 300,300"></svg:polygon> |
158
3f23fafeef99
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
296 </svg:svg> |
3f23fafeef99
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
297 </button> |
3f23fafeef99
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
298 </body> |
3f23fafeef99
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
299 </html>""" |
862 | 300 output = XML(text).render(XHTMLSerializer, encoding=None) |
158
3f23fafeef99
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
301 self.assertEqual(text, output) |
3f23fafeef99
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
302 |
177
553866249cb0
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
303 def test_xhtml_namespace_prefix(self): |
410
d14d89995c29
Improve the handling of namespaces in serialization.
cmlenz
parents:
408
diff
changeset
|
304 text = """<div xmlns="http://www.w3.org/1999/xhtml"> |
d14d89995c29
Improve the handling of namespaces in serialization.
cmlenz
parents:
408
diff
changeset
|
305 <strong>Hello</strong> |
d14d89995c29
Improve the handling of namespaces in serialization.
cmlenz
parents:
408
diff
changeset
|
306 </div>""" |
862 | 307 output = XML(text).render(XHTMLSerializer, encoding=None) |
177
553866249cb0
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
308 self.assertEqual(text, output) |
553866249cb0
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
309 |
313
d72d842e1083
Handle expressions containing non-ASCII strings as arguments for `py:with`, `py:def`, and `py:for`.
cmlenz
parents:
280
diff
changeset
|
310 def test_nested_default_namespaces(self): |
314
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
311 stream = Stream([ |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
312 (Stream.START_NS, ('', 'http://example.org/'), (None, -1, -1)), |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
313 (Stream.START, (QName('div'), Attrs()), (None, -1, -1)), |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
314 (Stream.TEXT, '\n ', (None, -1, -1)), |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
315 (Stream.START_NS, ('', 'http://example.org/'), (None, -1, -1)), |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
316 (Stream.START, (QName('p'), Attrs()), (None, -1, -1)), |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
317 (Stream.END, QName('p'), (None, -1, -1)), |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
318 (Stream.END_NS, '', (None, -1, -1)), |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
319 (Stream.TEXT, '\n ', (None, -1, -1)), |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
320 (Stream.START_NS, ('', 'http://example.org/'), (None, -1, -1)), |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
321 (Stream.START, (QName('p'), Attrs()), (None, -1, -1)), |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
322 (Stream.END, QName('p'), (None, -1, -1)), |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
323 (Stream.END_NS, '', (None, -1, -1)), |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
324 (Stream.TEXT, '\n ', (None, -1, -1)), |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
325 (Stream.END, QName('div'), (None, -1, -1)), |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
326 (Stream.END_NS, '', (None, -1, -1)) |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
327 ]) |
862 | 328 output = stream.render(XHTMLSerializer, encoding=None) |
314
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
329 self.assertEqual("""<div xmlns="http://example.org/"> |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
330 <p></p> |
313
d72d842e1083
Handle expressions containing non-ASCII strings as arguments for `py:with`, `py:def`, and `py:for`.
cmlenz
parents:
280
diff
changeset
|
331 <p></p> |
d72d842e1083
Handle expressions containing non-ASCII strings as arguments for `py:with`, `py:def`, and `py:for`.
cmlenz
parents:
280
diff
changeset
|
332 </div>""", output) |
d72d842e1083
Handle expressions containing non-ASCII strings as arguments for `py:with`, `py:def`, and `py:for`.
cmlenz
parents:
280
diff
changeset
|
333 |
d72d842e1083
Handle expressions containing non-ASCII strings as arguments for `py:with`, `py:def`, and `py:for`.
cmlenz
parents:
280
diff
changeset
|
334 def test_nested_bound_namespaces(self): |
314
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
335 stream = Stream([ |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
336 (Stream.START_NS, ('x', 'http://example.org/'), (None, -1, -1)), |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
337 (Stream.START, (QName('div'), Attrs()), (None, -1, -1)), |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
338 (Stream.TEXT, '\n ', (None, -1, -1)), |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
339 (Stream.START_NS, ('x', 'http://example.org/'), (None, -1, -1)), |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
340 (Stream.START, (QName('p'), Attrs()), (None, -1, -1)), |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
341 (Stream.END, QName('p'), (None, -1, -1)), |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
342 (Stream.END_NS, 'x', (None, -1, -1)), |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
343 (Stream.TEXT, '\n ', (None, -1, -1)), |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
344 (Stream.START_NS, ('x', 'http://example.org/'), (None, -1, -1)), |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
345 (Stream.START, (QName('p'), Attrs()), (None, -1, -1)), |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
346 (Stream.END, QName('p'), (None, -1, -1)), |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
347 (Stream.END_NS, 'x', (None, -1, -1)), |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
348 (Stream.TEXT, '\n ', (None, -1, -1)), |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
349 (Stream.END, QName('div'), (None, -1, -1)), |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
350 (Stream.END_NS, 'x', (None, -1, -1)) |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
351 ]) |
862 | 352 output = stream.render(XHTMLSerializer, encoding=None) |
313
d72d842e1083
Handle expressions containing non-ASCII strings as arguments for `py:with`, `py:def`, and `py:for`.
cmlenz
parents:
280
diff
changeset
|
353 self.assertEqual("""<div xmlns:x="http://example.org/"> |
314
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
354 <p></p> |
06a25d0962af
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
355 <p></p> |
313
d72d842e1083
Handle expressions containing non-ASCII strings as arguments for `py:with`, `py:def`, and `py:for`.
cmlenz
parents:
280
diff
changeset
|
356 </div>""", output) |
d72d842e1083
Handle expressions containing non-ASCII strings as arguments for `py:with`, `py:def`, and `py:for`.
cmlenz
parents:
280
diff
changeset
|
357 |
448 | 358 def test_html5_doctype(self): |
932 | 359 stream = HTML(u'<html></html>') |
862 | 360 output = stream.render(XHTMLSerializer, doctype=DocType.HTML5, |
361 encoding=None) | |
448 | 362 self.assertEqual('<!DOCTYPE html>\n<html></html>', output) |
363 | |
123
10279d2eeec9
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
364 |
10279d2eeec9
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
365 class HTMLSerializerTestCase(unittest.TestCase): |
10279d2eeec9
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
366 |
524
7553760b58af
Add special handling for `xml:lang` to HTML/XHTML serialization.
cmlenz
parents:
448
diff
changeset
|
367 def test_xml_lang(self): |
7553760b58af
Add special handling for `xml:lang` to HTML/XHTML serialization.
cmlenz
parents:
448
diff
changeset
|
368 text = '<p xml:lang="en">English text</p>' |
862 | 369 output = XML(text).render(HTMLSerializer, encoding=None) |
524
7553760b58af
Add special handling for `xml:lang` to HTML/XHTML serialization.
cmlenz
parents:
448
diff
changeset
|
370 self.assertEqual('<p lang="en">English text</p>', output) |
7553760b58af
Add special handling for `xml:lang` to HTML/XHTML serialization.
cmlenz
parents:
448
diff
changeset
|
371 |
7553760b58af
Add special handling for `xml:lang` to HTML/XHTML serialization.
cmlenz
parents:
448
diff
changeset
|
372 def test_xml_lang_nodup(self): |
7553760b58af
Add special handling for `xml:lang` to HTML/XHTML serialization.
cmlenz
parents:
448
diff
changeset
|
373 text = '<p lang="en" xml:lang="en">English text</p>' |
862 | 374 output = XML(text).render(HTMLSerializer, encoding=None) |
524
7553760b58af
Add special handling for `xml:lang` to HTML/XHTML serialization.
cmlenz
parents:
448
diff
changeset
|
375 self.assertEqual('<p lang="en">English text</p>', output) |
7553760b58af
Add special handling for `xml:lang` to HTML/XHTML serialization.
cmlenz
parents:
448
diff
changeset
|
376 |
346
96882a191686
Whitespace was not getting preserved in HTML `<pre>` elements that contained other HTML elements.
cmlenz
parents:
314
diff
changeset
|
377 def test_textarea_whitespace(self): |
96882a191686
Whitespace was not getting preserved in HTML `<pre>` elements that contained other HTML elements.
cmlenz
parents:
314
diff
changeset
|
378 content = '\nHey there. \n\n I am indented.\n' |
96882a191686
Whitespace was not getting preserved in HTML `<pre>` elements that contained other HTML elements.
cmlenz
parents:
314
diff
changeset
|
379 stream = XML('<textarea name="foo">%s</textarea>' % content) |
862 | 380 output = stream.render(HTMLSerializer, encoding=None) |
346
96882a191686
Whitespace was not getting preserved in HTML `<pre>` elements that contained other HTML elements.
cmlenz
parents:
314
diff
changeset
|
381 self.assertEqual('<textarea name="foo">%s</textarea>' % content, output) |
96882a191686
Whitespace was not getting preserved in HTML `<pre>` elements that contained other HTML elements.
cmlenz
parents:
314
diff
changeset
|
382 |
96882a191686
Whitespace was not getting preserved in HTML `<pre>` elements that contained other HTML elements.
cmlenz
parents:
314
diff
changeset
|
383 def test_pre_whitespace(self): |
96882a191686
Whitespace was not getting preserved in HTML `<pre>` elements that contained other HTML elements.
cmlenz
parents:
314
diff
changeset
|
384 content = '\nHey <em>there</em>. \n\n I am indented.\n' |
96882a191686
Whitespace was not getting preserved in HTML `<pre>` elements that contained other HTML elements.
cmlenz
parents:
314
diff
changeset
|
385 stream = XML('<pre>%s</pre>' % content) |
862 | 386 output = stream.render(HTMLSerializer, encoding=None) |
346
96882a191686
Whitespace was not getting preserved in HTML `<pre>` elements that contained other HTML elements.
cmlenz
parents:
314
diff
changeset
|
387 self.assertEqual('<pre>%s</pre>' % content, output) |
96882a191686
Whitespace was not getting preserved in HTML `<pre>` elements that contained other HTML elements.
cmlenz
parents:
314
diff
changeset
|
388 |
123
10279d2eeec9
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
389 def test_xml_space(self): |
10279d2eeec9
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
390 text = '<foo xml:space="preserve"> Do not mess \n\n with me </foo>' |
862 | 391 output = XML(text).render(HTMLSerializer, encoding=None) |
123
10279d2eeec9
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
392 self.assertEqual('<foo> Do not mess \n\n with me </foo>', output) |
10279d2eeec9
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
393 |
177
553866249cb0
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
394 def test_empty_script(self): |
553866249cb0
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
395 text = '<script src="foo.js" />' |
862 | 396 output = XML(text).render(HTMLSerializer, encoding=None) |
177
553866249cb0
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
397 self.assertEqual('<script src="foo.js"></script>', output) |
553866249cb0
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
398 |
141
520a5b7dd6d2
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
399 def test_script_escaping(self): |
520a5b7dd6d2
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
400 text = '<script>if (1 < 2) { alert("Doh"); }</script>' |
862 | 401 output = XML(text).render(HTMLSerializer, encoding=None) |
141
520a5b7dd6d2
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
402 self.assertEqual('<script>if (1 < 2) { alert("Doh"); }</script>', |
520a5b7dd6d2
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
403 output) |
520a5b7dd6d2
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
404 |
280
ce848f7c41f1
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
|
405 def test_script_escaping_with_namespace(self): |
ce848f7c41f1
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
|
406 text = """<script xmlns="http://www.w3.org/1999/xhtml"> |
ce848f7c41f1
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
|
407 if (1 < 2) { alert("Doh"); } |
ce848f7c41f1
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
|
408 </script>""" |
862 | 409 output = XML(text).render(HTMLSerializer, encoding=None) |
280
ce848f7c41f1
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
|
410 self.assertEqual("""<script> |
ce848f7c41f1
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
|
411 if (1 < 2) { alert("Doh"); } |
ce848f7c41f1
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
|
412 </script>""", output) |
ce848f7c41f1
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
|
413 |
141
520a5b7dd6d2
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
414 def test_style_escaping(self): |
520a5b7dd6d2
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
415 text = '<style>html > body { display: none; }</style>' |
862 | 416 output = XML(text).render(HTMLSerializer, encoding=None) |
141
520a5b7dd6d2
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
417 self.assertEqual('<style>html > body { display: none; }</style>', |
520a5b7dd6d2
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
418 output) |
520a5b7dd6d2
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
419 |
280
ce848f7c41f1
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
|
420 def test_style_escaping_with_namespace(self): |
ce848f7c41f1
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
|
421 text = """<style xmlns="http://www.w3.org/1999/xhtml"> |
ce848f7c41f1
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
|
422 html > body { display: none; } |
ce848f7c41f1
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
|
423 </style>""" |
862 | 424 output = XML(text).render(HTMLSerializer, encoding=None) |
280
ce848f7c41f1
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
|
425 self.assertEqual("""<style> |
ce848f7c41f1
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
|
426 html > body { display: none; } |
ce848f7c41f1
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
|
427 </style>""", output) |
ce848f7c41f1
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
|
428 |
448 | 429 def test_html5_doctype(self): |
932 | 430 stream = HTML(u'<html></html>') |
862 | 431 output = stream.render(HTMLSerializer, doctype=DocType.HTML5, |
432 encoding=None) | |
448 | 433 self.assertEqual('<!DOCTYPE html>\n<html></html>', output) |
434 | |
123
10279d2eeec9
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
435 |
212
0141f45c18e1
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
|
436 class EmptyTagFilterTestCase(unittest.TestCase): |
0141f45c18e1
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
|
437 |
0141f45c18e1
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
|
438 def test_empty(self): |
0141f45c18e1
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
|
439 stream = XML('<elem></elem>') | EmptyTagFilter() |
0141f45c18e1
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
|
440 self.assertEqual([EmptyTagFilter.EMPTY], [ev[0] for ev in stream]) |
0141f45c18e1
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
|
441 |
0141f45c18e1
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
|
442 def test_text_content(self): |
0141f45c18e1
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
|
443 stream = XML('<elem>foo</elem>') | EmptyTagFilter() |
0141f45c18e1
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
|
444 self.assertEqual([Stream.START, Stream.TEXT, Stream.END], |
0141f45c18e1
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
|
445 [ev[0] for ev in stream]) |
0141f45c18e1
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
|
446 |
0141f45c18e1
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
|
447 def test_elem_content(self): |
0141f45c18e1
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
|
448 stream = XML('<elem><sub /><sub /></elem>') | EmptyTagFilter() |
0141f45c18e1
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
|
449 self.assertEqual([Stream.START, EmptyTagFilter.EMPTY, |
0141f45c18e1
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
|
450 EmptyTagFilter.EMPTY, Stream.END], |
0141f45c18e1
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
|
451 [ev[0] for ev in stream]) |
0141f45c18e1
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
|
452 |
0141f45c18e1
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
|
453 |
1 | 454 def suite(): |
455 suite = unittest.TestSuite() | |
85 | 456 suite.addTest(unittest.makeSuite(XMLSerializerTestCase, 'test')) |
123
10279d2eeec9
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
457 suite.addTest(unittest.makeSuite(XHTMLSerializerTestCase, 'test')) |
10279d2eeec9
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
458 suite.addTest(unittest.makeSuite(HTMLSerializerTestCase, 'test')) |
212
0141f45c18e1
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
|
459 suite.addTest(unittest.makeSuite(EmptyTagFilterTestCase, 'test')) |
85 | 460 suite.addTest(doctest.DocTestSuite(XMLSerializer.__module__)) |
1 | 461 return suite |
462 | |
463 if __name__ == '__main__': | |
464 unittest.main(defaultTest='suite') |