Mercurial > genshi > genshi-test
annotate genshi/tests/output.py @ 703:3a4f2fd6f5e2 experimental-match-fastpaths
merge in trunk up through r818 - fundamentally changed the way MatchSet works, but actually is more consistent now
author | aflett |
---|---|
date | Mon, 31 Mar 2008 22:47:50 +0000 |
parents | f2090347ba6c |
children | 387acffea27d 67d324a62cc0 |
rev | line source |
---|---|
1 | 1 # -*- coding: utf-8 -*- |
2 # | |
408 | 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 | |
671
f2090347ba6c
Add a stream filter to insert the XML DOCTYPE in the correct location (ie.
athomas
parents:
524
diff
changeset
|
26 def test_xml_serialiser_with_decl(self): |
f2090347ba6c
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))]) |
f2090347ba6c
Add a stream filter to insert the XML DOCTYPE in the correct location (ie.
athomas
parents:
524
diff
changeset
|
28 output = stream.render(XMLSerializer, doctype='xhtml') |
f2090347ba6c
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' |
f2090347ba6c
Add a stream filter to insert the XML DOCTYPE in the correct location (ie.
athomas
parents:
524
diff
changeset
|
30 '<!DOCTYPE html PUBLIC ' |
f2090347ba6c
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" ' |
f2090347ba6c
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', |
f2090347ba6c
Add a stream filter to insert the XML DOCTYPE in the correct location (ie.
athomas
parents:
524
diff
changeset
|
33 output) |
f2090347ba6c
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
b592333efe1b
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))]) |
85 | 37 output = stream.render(XMLSerializer) |
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
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
46 (None, -1, -1))]) |
85 | 47 output = stream.render(XMLSerializer) |
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
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
52 stream = Stream([ |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
53 (Stream.DOCTYPE, |
b592333efe1b
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'), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
55 (None, -1, -1)) |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
56 ]) |
85 | 57 output = stream.render(XMLSerializer) |
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
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
64 (None, -1, -1))]) |
85 | 65 output = stream.render(XMLSerializer) |
66 self.assertEqual('<!DOCTYPE html>\n', output) | |
67 | |
68 def test_serializer_doctype(self): | |
69 stream = Stream([]) | |
70 output = stream.render(XMLSerializer, doctype=DocType.HTML_STRICT) | |
71 self.assertEqual('<!DOCTYPE html PUBLIC ' | |
72 '"-//W3C//DTD HTML 4.01//EN" ' | |
73 '"http://www.w3.org/TR/html4/strict.dtd">\n', | |
74 output) | |
75 | |
76 def test_doctype_one_and_only(self): | |
314
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
77 stream = Stream([ |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
78 (Stream.DOCTYPE, ('html', None, None), (None, -1, -1)) |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
79 ]) |
85 | 80 output = stream.render(XMLSerializer, doctype=DocType.HTML_STRICT) |
81 self.assertEqual('<!DOCTYPE html PUBLIC ' | |
82 '"-//W3C//DTD HTML 4.01//EN" ' | |
83 '"http://www.w3.org/TR/html4/strict.dtd">\n', | |
84 output) | |
85 | |
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
|
86 def test_comment(self): |
314
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
87 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
|
88 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
|
89 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
|
90 |
105
334a338847af
Include processing instructions in serialized streams.
cmlenz
parents:
89
diff
changeset
|
91 def test_processing_instruction(self): |
314
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
92 stream = Stream([(Stream.PI, ('python', 'x = 2'), (None, -1, -1))]) |
105
334a338847af
Include processing instructions in serialized streams.
cmlenz
parents:
89
diff
changeset
|
93 output = stream.render(XMLSerializer) |
334a338847af
Include processing instructions in serialized streams.
cmlenz
parents:
89
diff
changeset
|
94 self.assertEqual('<?python x = 2?>', output) |
334a338847af
Include processing instructions in serialized streams.
cmlenz
parents:
89
diff
changeset
|
95 |
313
caafc67d2d0f
Handle expressions containing non-ASCII strings as arguments for `py:with`, `py:def`, and `py:for`.
cmlenz
parents:
280
diff
changeset
|
96 def test_nested_default_namespaces(self): |
314
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
97 stream = Stream([ |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
98 (Stream.START_NS, ('', 'http://example.org/'), (None, -1, -1)), |
402
cc7f5b3fbbed
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
|
99 (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
|
100 (Stream.TEXT, '\n ', (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
101 (Stream.START_NS, ('', 'http://example.org/'), (None, -1, -1)), |
402
cc7f5b3fbbed
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
|
102 (Stream.START, (QName('http://example.org/}p'), Attrs()), (None, -1, -1)), |
cc7f5b3fbbed
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
|
103 (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
|
104 (Stream.END_NS, '', (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
105 (Stream.TEXT, '\n ', (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
106 (Stream.START_NS, ('', 'http://example.org/'), (None, -1, -1)), |
402
cc7f5b3fbbed
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
|
107 (Stream.START, (QName('http://example.org/}p'), Attrs()), (None, -1, -1)), |
cc7f5b3fbbed
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
|
108 (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
|
109 (Stream.END_NS, '', (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
110 (Stream.TEXT, '\n ', (None, -1, -1)), |
402
cc7f5b3fbbed
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
|
111 (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
|
112 (Stream.END_NS, '', (None, -1, -1)) |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
113 ]) |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
114 output = stream.render(XMLSerializer) |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
115 self.assertEqual("""<div xmlns="http://example.org/"> |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
116 <p/> |
313
caafc67d2d0f
Handle expressions containing non-ASCII strings as arguments for `py:with`, `py:def`, and `py:for`.
cmlenz
parents:
280
diff
changeset
|
117 <p/> |
caafc67d2d0f
Handle expressions containing non-ASCII strings as arguments for `py:with`, `py:def`, and `py:for`.
cmlenz
parents:
280
diff
changeset
|
118 </div>""", output) |
caafc67d2d0f
Handle expressions containing non-ASCII strings as arguments for `py:with`, `py:def`, and `py:for`.
cmlenz
parents:
280
diff
changeset
|
119 |
caafc67d2d0f
Handle expressions containing non-ASCII strings as arguments for `py:with`, `py:def`, and `py:for`.
cmlenz
parents:
280
diff
changeset
|
120 def test_nested_bound_namespaces(self): |
314
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
121 stream = Stream([ |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
122 (Stream.START_NS, ('x', 'http://example.org/'), (None, -1, -1)), |
402
cc7f5b3fbbed
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
|
123 (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
|
124 (Stream.TEXT, '\n ', (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
125 (Stream.START_NS, ('x', 'http://example.org/'), (None, -1, -1)), |
402
cc7f5b3fbbed
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
|
126 (Stream.START, (QName('http://example.org/}p'), Attrs()), (None, -1, -1)), |
cc7f5b3fbbed
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
|
127 (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
|
128 (Stream.END_NS, 'x', (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
129 (Stream.TEXT, '\n ', (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
130 (Stream.START_NS, ('x', 'http://example.org/'), (None, -1, -1)), |
402
cc7f5b3fbbed
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
|
131 (Stream.START, (QName('http://example.org/}p'), Attrs()), (None, -1, -1)), |
cc7f5b3fbbed
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
|
132 (Stream.END, QName('http://example.org/}p'), (None, -1, -1)), |
cc7f5b3fbbed
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.END_NS, 'x', (None, -1, -1)), |
cc7f5b3fbbed
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.TEXT, '\n ', (None, -1, -1)), |
cc7f5b3fbbed
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, QName('http://example.org/}div'), (None, -1, -1)), |
cc7f5b3fbbed
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.END_NS, 'x', (None, -1, -1)) |
cc7f5b3fbbed
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 ]) |
cc7f5b3fbbed
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 output = stream.render(XMLSerializer) |
cc7f5b3fbbed
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 self.assertEqual("""<x:div xmlns:x="http://example.org/"> |
cc7f5b3fbbed
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
|
140 <x:p/> |
cc7f5b3fbbed
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 <x:p/> |
cc7f5b3fbbed
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:div>""", output) |
cc7f5b3fbbed
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 |
cc7f5b3fbbed
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 def test_multiple_default_namespaces(self): |
cc7f5b3fbbed
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 stream = Stream([ |
cc7f5b3fbbed
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 (Stream.START, (QName('div'), Attrs()), (None, -1, -1)), |
cc7f5b3fbbed
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.TEXT, '\n ', (None, -1, -1)), |
cc7f5b3fbbed
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_NS, ('', 'http://example.org/'), (None, -1, -1)), |
cc7f5b3fbbed
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.START, (QName('http://example.org/}p'), Attrs()), (None, -1, -1)), |
cc7f5b3fbbed
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.END, QName('http://example.org/}p'), (None, -1, -1)), |
cc7f5b3fbbed
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.END_NS, '', (None, -1, -1)), |
cc7f5b3fbbed
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.TEXT, '\n ', (None, -1, -1)), |
cc7f5b3fbbed
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.START_NS, ('', 'http://example.org/'), (None, -1, -1)), |
cc7f5b3fbbed
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.START, (QName('http://example.org/}p'), Attrs()), (None, -1, -1)), |
cc7f5b3fbbed
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.END, QName('http://example.org/}p'), (None, -1, -1)), |
cc7f5b3fbbed
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.END_NS, '', (None, -1, -1)), |
cc7f5b3fbbed
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.TEXT, '\n ', (None, -1, -1)), |
cc7f5b3fbbed
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, QName('div'), (None, -1, -1)), |
cc7f5b3fbbed
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 ]) |
cc7f5b3fbbed
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 output = stream.render(XMLSerializer) |
cc7f5b3fbbed
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 self.assertEqual("""<div> |
cc7f5b3fbbed
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
|
162 <p xmlns="http://example.org/"/> |
cc7f5b3fbbed
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 <p xmlns="http://example.org/"/> |
cc7f5b3fbbed
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 </div>""", output) |
cc7f5b3fbbed
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 |
cc7f5b3fbbed
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 def test_multiple_bound_namespaces(self): |
cc7f5b3fbbed
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 stream = Stream([ |
cc7f5b3fbbed
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 (Stream.START, (QName('div'), Attrs()), (None, -1, -1)), |
cc7f5b3fbbed
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.TEXT, '\n ', (None, -1, -1)), |
cc7f5b3fbbed
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_NS, ('x', 'http://example.org/'), (None, -1, -1)), |
cc7f5b3fbbed
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.START, (QName('http://example.org/}p'), Attrs()), (None, -1, -1)), |
cc7f5b3fbbed
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.END, QName('http://example.org/}p'), (None, -1, -1)), |
cc7f5b3fbbed
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.END_NS, 'x', (None, -1, -1)), |
cc7f5b3fbbed
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.TEXT, '\n ', (None, -1, -1)), |
cc7f5b3fbbed
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.START_NS, ('x', 'http://example.org/'), (None, -1, -1)), |
cc7f5b3fbbed
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.START, (QName('http://example.org/}p'), Attrs()), (None, -1, -1)), |
cc7f5b3fbbed
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.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
|
178 (Stream.END_NS, 'x', (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
179 (Stream.TEXT, '\n ', (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
180 (Stream.END, QName('div'), (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
181 ]) |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
182 output = stream.render(XMLSerializer) |
402
cc7f5b3fbbed
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
|
183 self.assertEqual("""<div> |
cc7f5b3fbbed
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
|
184 <x:p xmlns:x="http://example.org/"/> |
cc7f5b3fbbed
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 <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
|
186 </div>""", output) |
caafc67d2d0f
Handle expressions containing non-ASCII strings as arguments for `py:with`, `py:def`, and `py:for`.
cmlenz
parents:
280
diff
changeset
|
187 |
410
3460b04daeac
Improve the handling of namespaces in serialization.
cmlenz
parents:
408
diff
changeset
|
188 def test_atom_with_xhtml(self): |
3460b04daeac
Improve the handling of namespaces in serialization.
cmlenz
parents:
408
diff
changeset
|
189 text = """<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"> |
3460b04daeac
Improve the handling of namespaces in serialization.
cmlenz
parents:
408
diff
changeset
|
190 <id>urn:uuid:c60843aa-0da8-4fa6-bbe5-98007bc6774e</id> |
3460b04daeac
Improve the handling of namespaces in serialization.
cmlenz
parents:
408
diff
changeset
|
191 <updated>2007-01-28T11:36:02.807108-06:00</updated> |
3460b04daeac
Improve the handling of namespaces in serialization.
cmlenz
parents:
408
diff
changeset
|
192 <title type="xhtml"> |
3460b04daeac
Improve the handling of namespaces in serialization.
cmlenz
parents:
408
diff
changeset
|
193 <div xmlns="http://www.w3.org/1999/xhtml">Example</div> |
3460b04daeac
Improve the handling of namespaces in serialization.
cmlenz
parents:
408
diff
changeset
|
194 </title> |
3460b04daeac
Improve the handling of namespaces in serialization.
cmlenz
parents:
408
diff
changeset
|
195 <subtitle type="xhtml"> |
3460b04daeac
Improve the handling of namespaces in serialization.
cmlenz
parents:
408
diff
changeset
|
196 <div xmlns="http://www.w3.org/1999/xhtml">Bla bla bla</div> |
3460b04daeac
Improve the handling of namespaces in serialization.
cmlenz
parents:
408
diff
changeset
|
197 </subtitle> |
3460b04daeac
Improve the handling of namespaces in serialization.
cmlenz
parents:
408
diff
changeset
|
198 <icon/> |
3460b04daeac
Improve the handling of namespaces in serialization.
cmlenz
parents:
408
diff
changeset
|
199 </feed>""" |
3460b04daeac
Improve the handling of namespaces in serialization.
cmlenz
parents:
408
diff
changeset
|
200 output = XML(text).render(XMLSerializer) |
3460b04daeac
Improve the handling of namespaces in serialization.
cmlenz
parents:
408
diff
changeset
|
201 self.assertEqual(text, output) |
3460b04daeac
Improve the handling of namespaces in serialization.
cmlenz
parents:
408
diff
changeset
|
202 |
1 | 203 |
123
93bbdcf9428b
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
204 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
|
205 |
524
49848aaa7839
Add special handling for `xml:lang` to HTML/XHTML serialization.
cmlenz
parents:
448
diff
changeset
|
206 def test_xml_lang(self): |
49848aaa7839
Add special handling for `xml:lang` to HTML/XHTML serialization.
cmlenz
parents:
448
diff
changeset
|
207 text = '<p xml:lang="en">English text</p>' |
49848aaa7839
Add special handling for `xml:lang` to HTML/XHTML serialization.
cmlenz
parents:
448
diff
changeset
|
208 output = XML(text).render(XHTMLSerializer) |
49848aaa7839
Add special handling for `xml:lang` to HTML/XHTML serialization.
cmlenz
parents:
448
diff
changeset
|
209 self.assertEqual('<p lang="en" xml:lang="en">English text</p>', output) |
49848aaa7839
Add special handling for `xml:lang` to HTML/XHTML serialization.
cmlenz
parents:
448
diff
changeset
|
210 |
49848aaa7839
Add special handling for `xml:lang` to HTML/XHTML serialization.
cmlenz
parents:
448
diff
changeset
|
211 def test_xml_lang_nodup(self): |
49848aaa7839
Add special handling for `xml:lang` to HTML/XHTML serialization.
cmlenz
parents:
448
diff
changeset
|
212 text = '<p xml:lang="en" lang="en">English text</p>' |
49848aaa7839
Add special handling for `xml:lang` to HTML/XHTML serialization.
cmlenz
parents:
448
diff
changeset
|
213 output = XML(text).render(XHTMLSerializer) |
49848aaa7839
Add special handling for `xml:lang` to HTML/XHTML serialization.
cmlenz
parents:
448
diff
changeset
|
214 self.assertEqual('<p xml:lang="en" lang="en">English text</p>', output) |
49848aaa7839
Add special handling for `xml:lang` to HTML/XHTML serialization.
cmlenz
parents:
448
diff
changeset
|
215 |
123
93bbdcf9428b
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
216 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
|
217 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
|
218 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
|
219 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
|
220 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
|
221 |
346
2304e080ec07
Whitespace was not getting preserved in HTML `<pre>` elements that contained other HTML elements.
cmlenz
parents:
314
diff
changeset
|
222 def test_pre_whitespace(self): |
2304e080ec07
Whitespace was not getting preserved in HTML `<pre>` elements that contained other HTML elements.
cmlenz
parents:
314
diff
changeset
|
223 content = '\nHey <em>there</em>. \n\n I am indented.\n' |
2304e080ec07
Whitespace was not getting preserved in HTML `<pre>` elements that contained other HTML elements.
cmlenz
parents:
314
diff
changeset
|
224 stream = XML('<pre>%s</pre>' % content) |
2304e080ec07
Whitespace was not getting preserved in HTML `<pre>` elements that contained other HTML elements.
cmlenz
parents:
314
diff
changeset
|
225 output = stream.render(XHTMLSerializer) |
2304e080ec07
Whitespace was not getting preserved in HTML `<pre>` elements that contained other HTML elements.
cmlenz
parents:
314
diff
changeset
|
226 self.assertEqual('<pre>%s</pre>' % content, output) |
2304e080ec07
Whitespace was not getting preserved in HTML `<pre>` elements that contained other HTML elements.
cmlenz
parents:
314
diff
changeset
|
227 |
123
93bbdcf9428b
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
228 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
|
229 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
|
230 output = XML(text).render(XHTMLSerializer) |
703
3a4f2fd6f5e2
merge in trunk up through r818 - fundamentally changed the way MatchSet works, but actually is more consistent now
aflett
parents:
671
diff
changeset
|
231 self.assertEqual('<foo> Do not mess \n\n with me </foo>', output) |
123
93bbdcf9428b
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
232 |
177
dbae9efe5704
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
233 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
|
234 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
|
235 <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
|
236 </html>""" |
177
dbae9efe5704
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
237 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
|
238 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
|
239 <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
|
240 </html>""", output) |
177
dbae9efe5704
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
241 |
141
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
242 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
|
243 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
|
244 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
|
245 /*]]>*/</script>""" |
141
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
246 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
|
247 self.assertEqual(text, output) |
141
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
248 |
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
|
249 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
|
250 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
|
251 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
|
252 /*]]>*/</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
|
253 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
|
254 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
|
255 |
141
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
256 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
|
257 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
|
258 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
|
259 /*]]>*/</style>""" |
141
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
260 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
|
261 self.assertEqual(text, output) |
141
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
262 |
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
|
263 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
|
264 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
|
265 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
|
266 /*]]>*/</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
|
267 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
|
268 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
|
269 |
158
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
270 def test_embedded_svg(self): |
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
271 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
|
272 <body> |
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
273 <button> |
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
274 <svg:svg width="600px" height="400px"> |
410
3460b04daeac
Improve the handling of namespaces in serialization.
cmlenz
parents:
408
diff
changeset
|
275 <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
|
276 </svg:svg> |
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
277 </button> |
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
278 </body> |
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
279 </html>""" |
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
280 output = XML(text).render(XHTMLSerializer) |
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
281 self.assertEqual(text, output) |
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
282 |
177
dbae9efe5704
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
283 def test_xhtml_namespace_prefix(self): |
410
3460b04daeac
Improve the handling of namespaces in serialization.
cmlenz
parents:
408
diff
changeset
|
284 text = """<div xmlns="http://www.w3.org/1999/xhtml"> |
3460b04daeac
Improve the handling of namespaces in serialization.
cmlenz
parents:
408
diff
changeset
|
285 <strong>Hello</strong> |
3460b04daeac
Improve the handling of namespaces in serialization.
cmlenz
parents:
408
diff
changeset
|
286 </div>""" |
177
dbae9efe5704
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
287 output = XML(text).render(XHTMLSerializer) |
dbae9efe5704
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
288 self.assertEqual(text, output) |
dbae9efe5704
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
289 |
313
caafc67d2d0f
Handle expressions containing non-ASCII strings as arguments for `py:with`, `py:def`, and `py:for`.
cmlenz
parents:
280
diff
changeset
|
290 def test_nested_default_namespaces(self): |
314
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
291 stream = Stream([ |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
292 (Stream.START_NS, ('', 'http://example.org/'), (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
293 (Stream.START, (QName('div'), Attrs()), (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
294 (Stream.TEXT, '\n ', (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
295 (Stream.START_NS, ('', 'http://example.org/'), (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
296 (Stream.START, (QName('p'), Attrs()), (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
297 (Stream.END, QName('p'), (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
298 (Stream.END_NS, '', (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, ('', '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, '', (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.END, QName('div'), (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
306 (Stream.END_NS, '', (None, -1, -1)) |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
307 ]) |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
308 output = stream.render(XHTMLSerializer) |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
309 self.assertEqual("""<div xmlns="http://example.org/"> |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
310 <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
|
311 <p></p> |
caafc67d2d0f
Handle expressions containing non-ASCII strings as arguments for `py:with`, `py:def`, and `py:for`.
cmlenz
parents:
280
diff
changeset
|
312 </div>""", output) |
caafc67d2d0f
Handle expressions containing non-ASCII strings as arguments for `py:with`, `py:def`, and `py:for`.
cmlenz
parents:
280
diff
changeset
|
313 |
caafc67d2d0f
Handle expressions containing non-ASCII strings as arguments for `py:with`, `py:def`, and `py:for`.
cmlenz
parents:
280
diff
changeset
|
314 def test_nested_bound_namespaces(self): |
314
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
315 stream = Stream([ |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
316 (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
|
317 (Stream.START, (QName('div'), Attrs()), (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
318 (Stream.TEXT, '\n ', (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
319 (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
|
320 (Stream.START, (QName('p'), Attrs()), (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
321 (Stream.END, QName('p'), (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
322 (Stream.END_NS, 'x', (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
323 (Stream.TEXT, '\n ', (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
324 (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
|
325 (Stream.START, (QName('p'), Attrs()), (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
326 (Stream.END, QName('p'), (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
327 (Stream.END_NS, 'x', (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
328 (Stream.TEXT, '\n ', (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
329 (Stream.END, QName('div'), (None, -1, -1)), |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
330 (Stream.END_NS, 'x', (None, -1, -1)) |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
331 ]) |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
332 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
|
333 self.assertEqual("""<div xmlns:x="http://example.org/"> |
314
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
334 <p></p> |
b592333efe1b
Improved the unit tests for nested namespaces in serialization.
cmlenz
parents:
313
diff
changeset
|
335 <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
|
336 </div>""", output) |
caafc67d2d0f
Handle expressions containing non-ASCII strings as arguments for `py:with`, `py:def`, and `py:for`.
cmlenz
parents:
280
diff
changeset
|
337 |
448 | 338 def test_html5_doctype(self): |
339 stream = HTML('<html></html>') | |
340 output = stream.render(XHTMLSerializer, doctype=DocType.HTML5) | |
341 self.assertEqual('<!DOCTYPE html>\n<html></html>', output) | |
342 | |
123
93bbdcf9428b
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
343 |
93bbdcf9428b
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
344 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
|
345 |
524
49848aaa7839
Add special handling for `xml:lang` to HTML/XHTML serialization.
cmlenz
parents:
448
diff
changeset
|
346 def test_xml_lang(self): |
49848aaa7839
Add special handling for `xml:lang` to HTML/XHTML serialization.
cmlenz
parents:
448
diff
changeset
|
347 text = '<p xml:lang="en">English text</p>' |
49848aaa7839
Add special handling for `xml:lang` to HTML/XHTML serialization.
cmlenz
parents:
448
diff
changeset
|
348 output = XML(text).render(HTMLSerializer) |
49848aaa7839
Add special handling for `xml:lang` to HTML/XHTML serialization.
cmlenz
parents:
448
diff
changeset
|
349 self.assertEqual('<p lang="en">English text</p>', output) |
49848aaa7839
Add special handling for `xml:lang` to HTML/XHTML serialization.
cmlenz
parents:
448
diff
changeset
|
350 |
49848aaa7839
Add special handling for `xml:lang` to HTML/XHTML serialization.
cmlenz
parents:
448
diff
changeset
|
351 def test_xml_lang_nodup(self): |
49848aaa7839
Add special handling for `xml:lang` to HTML/XHTML serialization.
cmlenz
parents:
448
diff
changeset
|
352 text = '<p lang="en" xml:lang="en">English text</p>' |
49848aaa7839
Add special handling for `xml:lang` to HTML/XHTML serialization.
cmlenz
parents:
448
diff
changeset
|
353 output = XML(text).render(HTMLSerializer) |
49848aaa7839
Add special handling for `xml:lang` to HTML/XHTML serialization.
cmlenz
parents:
448
diff
changeset
|
354 self.assertEqual('<p lang="en">English text</p>', output) |
49848aaa7839
Add special handling for `xml:lang` to HTML/XHTML serialization.
cmlenz
parents:
448
diff
changeset
|
355 |
346
2304e080ec07
Whitespace was not getting preserved in HTML `<pre>` elements that contained other HTML elements.
cmlenz
parents:
314
diff
changeset
|
356 def test_textarea_whitespace(self): |
2304e080ec07
Whitespace was not getting preserved in HTML `<pre>` elements that contained other HTML elements.
cmlenz
parents:
314
diff
changeset
|
357 content = '\nHey there. \n\n I am indented.\n' |
2304e080ec07
Whitespace was not getting preserved in HTML `<pre>` elements that contained other HTML elements.
cmlenz
parents:
314
diff
changeset
|
358 stream = XML('<textarea name="foo">%s</textarea>' % content) |
2304e080ec07
Whitespace was not getting preserved in HTML `<pre>` elements that contained other HTML elements.
cmlenz
parents:
314
diff
changeset
|
359 output = stream.render(HTMLSerializer) |
2304e080ec07
Whitespace was not getting preserved in HTML `<pre>` elements that contained other HTML elements.
cmlenz
parents:
314
diff
changeset
|
360 self.assertEqual('<textarea name="foo">%s</textarea>' % content, output) |
2304e080ec07
Whitespace was not getting preserved in HTML `<pre>` elements that contained other HTML elements.
cmlenz
parents:
314
diff
changeset
|
361 |
2304e080ec07
Whitespace was not getting preserved in HTML `<pre>` elements that contained other HTML elements.
cmlenz
parents:
314
diff
changeset
|
362 def test_pre_whitespace(self): |
2304e080ec07
Whitespace was not getting preserved in HTML `<pre>` elements that contained other HTML elements.
cmlenz
parents:
314
diff
changeset
|
363 content = '\nHey <em>there</em>. \n\n I am indented.\n' |
2304e080ec07
Whitespace was not getting preserved in HTML `<pre>` elements that contained other HTML elements.
cmlenz
parents:
314
diff
changeset
|
364 stream = XML('<pre>%s</pre>' % content) |
2304e080ec07
Whitespace was not getting preserved in HTML `<pre>` elements that contained other HTML elements.
cmlenz
parents:
314
diff
changeset
|
365 output = stream.render(HTMLSerializer) |
2304e080ec07
Whitespace was not getting preserved in HTML `<pre>` elements that contained other HTML elements.
cmlenz
parents:
314
diff
changeset
|
366 self.assertEqual('<pre>%s</pre>' % content, output) |
2304e080ec07
Whitespace was not getting preserved in HTML `<pre>` elements that contained other HTML elements.
cmlenz
parents:
314
diff
changeset
|
367 |
123
93bbdcf9428b
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
368 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
|
369 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
|
370 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
|
371 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
|
372 |
177
dbae9efe5704
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
373 def test_empty_script(self): |
dbae9efe5704
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
374 text = '<script src="foo.js" />' |
dbae9efe5704
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
375 output = XML(text).render(XHTMLSerializer) |
dbae9efe5704
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
376 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
|
377 |
141
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
378 def test_script_escaping(self): |
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
379 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
|
380 output = XML(text).render(HTMLSerializer) |
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
381 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
|
382 output) |
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
383 |
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
|
384 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
|
385 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
|
386 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
|
387 </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
|
388 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
|
389 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
|
390 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
|
391 </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
|
392 |
141
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
393 def test_style_escaping(self): |
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
394 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
|
395 output = XML(text).render(HTMLSerializer) |
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
396 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
|
397 output) |
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
398 |
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
|
399 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
|
400 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
|
401 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
|
402 </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
|
403 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
|
404 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
|
405 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
|
406 </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
|
407 |
448 | 408 def test_html5_doctype(self): |
409 stream = HTML('<html></html>') | |
410 output = stream.render(HTMLSerializer, doctype=DocType.HTML5) | |
411 self.assertEqual('<!DOCTYPE html>\n<html></html>', output) | |
412 | |
123
93bbdcf9428b
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
413 |
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
|
414 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
|
415 |
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
|
416 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
|
417 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
|
418 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
|
419 |
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
|
420 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
|
421 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
|
422 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
|
423 [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
|
424 |
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
|
425 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
|
426 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
|
427 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
|
428 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
|
429 [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
|
430 |
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
|
431 |
1 | 432 def suite(): |
433 suite = unittest.TestSuite() | |
85 | 434 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
|
435 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
|
436 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
|
437 suite.addTest(unittest.makeSuite(EmptyTagFilterTestCase, 'test')) |
85 | 438 suite.addTest(doctest.DocTestSuite(XMLSerializer.__module__)) |
1 | 439 return suite |
440 | |
441 if __name__ == '__main__': | |
442 unittest.main(defaultTest='suite') |