Mercurial > genshi > genshi-test
annotate markup/tests/output.py @ 226:09f869a98149
Add reStructuredText documentation files.
author | cmlenz |
---|---|
date | Fri, 08 Sep 2006 08:44:31 +0000 |
parents | e8c43127d9a9 |
children |
rev | line source |
---|---|
1 | 1 # -*- coding: utf-8 -*- |
2 # | |
66
822089ae65ce
Switch copyright to Edgewall and URLs to markup.edgewall.org.
cmlenz
parents:
27
diff
changeset
|
3 # Copyright (C) 2006 Edgewall Software |
1 | 4 # All rights reserved. |
5 # | |
6 # This software is licensed as described in the file COPYING, which | |
7 # you should have received as part of this distribution. The terms | |
66
822089ae65ce
Switch copyright to Edgewall and URLs to markup.edgewall.org.
cmlenz
parents:
27
diff
changeset
|
8 # are also available at http://markup.edgewall.org/wiki/License. |
1 | 9 # |
10 # This software consists of voluntary contributions made by many | |
11 # individuals. For the exact contribution history, see the revision | |
66
822089ae65ce
Switch copyright to Edgewall and URLs to markup.edgewall.org.
cmlenz
parents:
27
diff
changeset
|
12 # history and logs, available at http://markup.edgewall.org/log/. |
1 | 13 |
14 import doctest | |
15 import unittest | |
16 import sys | |
17 | |
85 | 18 from markup.core import Stream |
141
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
19 from markup.input import HTML, XML |
123
93bbdcf9428b
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
20 from markup.output import DocType, XMLSerializer, XHTMLSerializer, \ |
212
e8c43127d9a9
Refactored the handling of empty tags in the serializer: use an `EmptyTagFilter` that combines adjacent start/end events, instead of the generic pushback-iterator.
cmlenz
parents:
178
diff
changeset
|
21 HTMLSerializer, EmptyTagFilter |
85 | 22 |
23 | |
24 class XMLSerializerTestCase(unittest.TestCase): | |
25 | |
26 def test_doctype_in_stream(self): | |
27 stream = Stream([(Stream.DOCTYPE, DocType.HTML_STRICT, ('?', -1, -1))]) | |
28 output = stream.render(XMLSerializer) | |
29 self.assertEqual('<!DOCTYPE html PUBLIC ' | |
30 '"-//W3C//DTD HTML 4.01//EN" ' | |
31 '"http://www.w3.org/TR/html4/strict.dtd">\n', | |
32 output) | |
33 | |
34 def test_doctype_in_stream_no_sysid(self): | |
35 stream = Stream([(Stream.DOCTYPE, | |
36 ('html', '-//W3C//DTD HTML 4.01//EN', None), | |
37 ('?', -1, -1))]) | |
38 output = stream.render(XMLSerializer) | |
39 self.assertEqual('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">\n', | |
40 output) | |
41 | |
42 def test_doctype_in_stream_no_pubid(self): | |
43 stream = Stream([(Stream.DOCTYPE, | |
44 ('html', None, 'http://www.w3.org/TR/html4/strict.dtd'), | |
45 ('?', -1, -1))]) | |
46 output = stream.render(XMLSerializer) | |
47 self.assertEqual('<!DOCTYPE html SYSTEM ' | |
48 '"http://www.w3.org/TR/html4/strict.dtd">\n', | |
49 output) | |
50 | |
51 def test_doctype_in_stream_no_pubid_or_sysid(self): | |
52 stream = Stream([(Stream.DOCTYPE, ('html', None, None), | |
53 ('?', -1, -1))]) | |
54 output = stream.render(XMLSerializer) | |
55 self.assertEqual('<!DOCTYPE html>\n', output) | |
56 | |
57 def test_serializer_doctype(self): | |
58 stream = Stream([]) | |
59 output = stream.render(XMLSerializer, doctype=DocType.HTML_STRICT) | |
60 self.assertEqual('<!DOCTYPE html PUBLIC ' | |
61 '"-//W3C//DTD HTML 4.01//EN" ' | |
62 '"http://www.w3.org/TR/html4/strict.dtd">\n', | |
63 output) | |
64 | |
65 def test_doctype_one_and_only(self): | |
66 stream = Stream([(Stream.DOCTYPE, ('html', None, None), ('?', -1, -1))]) | |
67 output = stream.render(XMLSerializer, doctype=DocType.HTML_STRICT) | |
68 self.assertEqual('<!DOCTYPE html PUBLIC ' | |
69 '"-//W3C//DTD HTML 4.01//EN" ' | |
70 '"http://www.w3.org/TR/html4/strict.dtd">\n', | |
71 output) | |
72 | |
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
|
73 def test_comment(self): |
d4c7617900e3
Support comments in templates that are not included in the output, in the same way Kid does: if the comment text starts with a `!` character, it is stripped from the output.
cmlenz
parents:
85
diff
changeset
|
74 stream = Stream([(Stream.COMMENT, 'foo bar', ('?', -1, -1))]) |
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
|
75 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
|
76 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
|
77 |
105
334a338847af
Include processing instructions in serialized streams.
cmlenz
parents:
89
diff
changeset
|
78 def test_processing_instruction(self): |
334a338847af
Include processing instructions in serialized streams.
cmlenz
parents:
89
diff
changeset
|
79 stream = Stream([(Stream.PI, ('python', 'x = 2'), ('?', -1, -1))]) |
334a338847af
Include processing instructions in serialized streams.
cmlenz
parents:
89
diff
changeset
|
80 output = stream.render(XMLSerializer) |
334a338847af
Include processing instructions in serialized streams.
cmlenz
parents:
89
diff
changeset
|
81 self.assertEqual('<?python x = 2?>', output) |
334a338847af
Include processing instructions in serialized streams.
cmlenz
parents:
89
diff
changeset
|
82 |
1 | 83 |
123
93bbdcf9428b
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
84 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
|
85 |
93bbdcf9428b
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
86 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
|
87 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
|
88 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
|
89 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
|
90 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
|
91 |
93bbdcf9428b
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
92 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
|
93 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
|
94 output = XML(text).render(XHTMLSerializer) |
123
93bbdcf9428b
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
95 self.assertEqual(text, output) |
93bbdcf9428b
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
96 |
177
dbae9efe5704
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
97 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
|
98 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
|
99 <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
|
100 </html>""" |
177
dbae9efe5704
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
101 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
|
102 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
|
103 <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
|
104 </html>""", output) |
177
dbae9efe5704
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
105 |
141
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
106 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
|
107 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
|
108 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
|
109 /*]]>*/</script>""" |
141
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
110 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
|
111 self.assertEqual(text, output) |
141
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
112 |
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
113 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
|
114 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
|
115 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
|
116 /*]]>*/</style>""" |
141
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
117 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
|
118 self.assertEqual(text, output) |
141
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
119 |
158
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
120 def test_embedded_svg(self): |
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
121 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
|
122 <body> |
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
123 <button> |
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
124 <svg:svg width="600px" height="400px"> |
160 | 125 <svg:polygon id="triangle" points="50,50 50,300 300,300" /> |
158
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
126 </svg:svg> |
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
127 </button> |
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
128 </body> |
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
129 </html>""" |
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
130 output = XML(text).render(XHTMLSerializer) |
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
131 self.assertEqual(text, output) |
8e81177059f3
* Add test case for SVG content embedded in an HTML document.
cmlenz
parents:
143
diff
changeset
|
132 |
177
dbae9efe5704
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
133 def test_xhtml_namespace_prefix(self): |
dbae9efe5704
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
134 text = """<html:div xmlns:html="http://www.w3.org/1999/xhtml"> |
dbae9efe5704
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
135 <html:strong>Hello</html:strong> |
dbae9efe5704
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
136 </html:div>""" |
dbae9efe5704
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
137 output = XML(text).render(XHTMLSerializer) |
dbae9efe5704
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
138 self.assertEqual(text, output) |
dbae9efe5704
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
139 |
123
93bbdcf9428b
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
140 |
93bbdcf9428b
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
141 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
|
142 |
93bbdcf9428b
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
143 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
|
144 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
|
145 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
|
146 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
|
147 |
177
dbae9efe5704
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
148 def test_empty_script(self): |
dbae9efe5704
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
149 text = '<script src="foo.js" />' |
dbae9efe5704
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
150 output = XML(text).render(XHTMLSerializer) |
dbae9efe5704
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
cmlenz
parents:
160
diff
changeset
|
151 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
|
152 |
141
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
153 def test_script_escaping(self): |
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
154 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
|
155 output = XML(text).render(HTMLSerializer) |
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
156 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
|
157 output) |
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
158 |
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
159 def test_style_escaping(self): |
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
160 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
|
161 output = XML(text).render(HTMLSerializer) |
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
162 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
|
163 output) |
b3ceaa35fb6b
* No escaping of `<script>` or `<style>` tags in HTML output (see #24)
cmlenz
parents:
123
diff
changeset
|
164 |
123
93bbdcf9428b
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
165 |
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
|
166 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
|
167 |
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
|
168 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
|
169 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
|
170 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
|
171 |
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
|
172 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
|
173 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
|
174 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
|
175 [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
|
176 |
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
|
177 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
|
178 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
|
179 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
|
180 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
|
181 [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
|
182 |
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
|
183 |
1 | 184 def suite(): |
185 suite = unittest.TestSuite() | |
85 | 186 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
|
187 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
|
188 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
|
189 suite.addTest(unittest.makeSuite(EmptyTagFilterTestCase, 'test')) |
85 | 190 suite.addTest(doctest.DocTestSuite(XMLSerializer.__module__)) |
1 | 191 return suite |
192 | |
193 if __name__ == '__main__': | |
194 unittest.main(defaultTest='suite') |