Mercurial > genshi > mirror
annotate markup/tests/output.py @ 125:1a55c9d57cc7 stable-0.1.x 0.1.0
Prepare [milestone:0.1] release.
author | cmlenz |
---|---|
date | Thu, 03 Aug 2006 17:10:41 +0000 |
parents | 10279d2eeec9 |
children | 520a5b7dd6d2 |
rev | line source |
---|---|
1 | 1 # -*- coding: utf-8 -*- |
2 # | |
66
59eb24184e9c
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
59eb24184e9c
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
59eb24184e9c
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 |
123
10279d2eeec9
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
19 from markup.input import HTML |
10279d2eeec9
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, \ |
10279d2eeec9
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
21 HTMLSerializer |
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
80386d62814f
Support comments in templates that are not included in the output, in the same way Kid does: if the comment text starts with a `!` character, it is stripped from the output.
cmlenz
parents:
85
diff
changeset
|
73 def test_comment(self): |
80386d62814f
Support comments in templates that are not included in the output, in the same way Kid does: if the comment text starts with a `!` character, it is stripped from the output.
cmlenz
parents:
85
diff
changeset
|
74 stream = Stream([(Stream.COMMENT, 'foo bar', ('?', -1, -1))]) |
80386d62814f
Support comments in templates that are not included in the output, in the same way Kid does: if the comment text starts with a `!` character, it is stripped from the output.
cmlenz
parents:
85
diff
changeset
|
75 output = stream.render(XMLSerializer) |
80386d62814f
Support comments in templates that are not included in the output, in the same way Kid does: if the comment text starts with a `!` character, it is stripped from the output.
cmlenz
parents:
85
diff
changeset
|
76 self.assertEqual('<!--foo bar-->', output) |
80386d62814f
Support comments in templates that are not included in the output, in the same way Kid does: if the comment text starts with a `!` character, it is stripped from the output.
cmlenz
parents:
85
diff
changeset
|
77 |
105
71f3db26eecb
Include processing instructions in serialized streams.
cmlenz
parents:
89
diff
changeset
|
78 def test_processing_instruction(self): |
71f3db26eecb
Include processing instructions in serialized streams.
cmlenz
parents:
89
diff
changeset
|
79 stream = Stream([(Stream.PI, ('python', 'x = 2'), ('?', -1, -1))]) |
71f3db26eecb
Include processing instructions in serialized streams.
cmlenz
parents:
89
diff
changeset
|
80 output = stream.render(XMLSerializer) |
71f3db26eecb
Include processing instructions in serialized streams.
cmlenz
parents:
89
diff
changeset
|
81 self.assertEqual('<?python x = 2?>', output) |
71f3db26eecb
Include processing instructions in serialized streams.
cmlenz
parents:
89
diff
changeset
|
82 |
1 | 83 |
123
10279d2eeec9
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): |
10279d2eeec9
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
85 |
10279d2eeec9
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): |
10279d2eeec9
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' |
10279d2eeec9
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
88 stream = HTML('<textarea name="foo">%s</textarea>' % content) |
10279d2eeec9
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) |
10279d2eeec9
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) |
10279d2eeec9
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
91 |
10279d2eeec9
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): |
10279d2eeec9
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>' |
10279d2eeec9
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
94 output = HTML(text).render(XHTMLSerializer) |
10279d2eeec9
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) |
10279d2eeec9
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
96 |
10279d2eeec9
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
97 |
10279d2eeec9
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
98 class HTMLSerializerTestCase(unittest.TestCase): |
10279d2eeec9
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
99 |
10279d2eeec9
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
100 def test_xml_space(self): |
10279d2eeec9
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
101 text = '<foo xml:space="preserve"> Do not mess \n\n with me </foo>' |
10279d2eeec9
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
102 output = HTML(text).render(HTMLSerializer) |
10279d2eeec9
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
103 self.assertEqual('<foo> Do not mess \n\n with me </foo>', output) |
10279d2eeec9
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
104 |
10279d2eeec9
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
105 |
1 | 106 def suite(): |
107 suite = unittest.TestSuite() | |
85 | 108 suite.addTest(unittest.makeSuite(XMLSerializerTestCase, 'test')) |
123
10279d2eeec9
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
109 suite.addTest(unittest.makeSuite(XHTMLSerializerTestCase, 'test')) |
10279d2eeec9
Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents:
105
diff
changeset
|
110 suite.addTest(unittest.makeSuite(HTMLSerializerTestCase, 'test')) |
85 | 111 suite.addTest(doctest.DocTestSuite(XMLSerializer.__module__)) |
1 | 112 return suite |
113 | |
114 if __name__ == '__main__': | |
115 unittest.main(defaultTest='suite') |