Mercurial > genshi > mirror
annotate markup/tests/output.py @ 93:08d77c7725e2 trunk
Minor bugfi x follow-up to [97]: don't yield the terminator event from the whitespace filter.
author | cmlenz |
---|---|
date | Thu, 20 Jul 2006 23:33:51 +0000 |
parents | 80386d62814f |
children | 71f3db26eecb |
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 |
19 from markup.output import DocType, XMLSerializer | |
20 | |
21 | |
22 class XMLSerializerTestCase(unittest.TestCase): | |
23 | |
24 def test_doctype_in_stream(self): | |
25 stream = Stream([(Stream.DOCTYPE, DocType.HTML_STRICT, ('?', -1, -1))]) | |
26 output = stream.render(XMLSerializer) | |
27 self.assertEqual('<!DOCTYPE html PUBLIC ' | |
28 '"-//W3C//DTD HTML 4.01//EN" ' | |
29 '"http://www.w3.org/TR/html4/strict.dtd">\n', | |
30 output) | |
31 | |
32 def test_doctype_in_stream_no_sysid(self): | |
33 stream = Stream([(Stream.DOCTYPE, | |
34 ('html', '-//W3C//DTD HTML 4.01//EN', None), | |
35 ('?', -1, -1))]) | |
36 output = stream.render(XMLSerializer) | |
37 self.assertEqual('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">\n', | |
38 output) | |
39 | |
40 def test_doctype_in_stream_no_pubid(self): | |
41 stream = Stream([(Stream.DOCTYPE, | |
42 ('html', None, 'http://www.w3.org/TR/html4/strict.dtd'), | |
43 ('?', -1, -1))]) | |
44 output = stream.render(XMLSerializer) | |
45 self.assertEqual('<!DOCTYPE html SYSTEM ' | |
46 '"http://www.w3.org/TR/html4/strict.dtd">\n', | |
47 output) | |
48 | |
49 def test_doctype_in_stream_no_pubid_or_sysid(self): | |
50 stream = Stream([(Stream.DOCTYPE, ('html', None, None), | |
51 ('?', -1, -1))]) | |
52 output = stream.render(XMLSerializer) | |
53 self.assertEqual('<!DOCTYPE html>\n', output) | |
54 | |
55 def test_serializer_doctype(self): | |
56 stream = Stream([]) | |
57 output = stream.render(XMLSerializer, doctype=DocType.HTML_STRICT) | |
58 self.assertEqual('<!DOCTYPE html PUBLIC ' | |
59 '"-//W3C//DTD HTML 4.01//EN" ' | |
60 '"http://www.w3.org/TR/html4/strict.dtd">\n', | |
61 output) | |
62 | |
63 def test_doctype_one_and_only(self): | |
64 stream = Stream([(Stream.DOCTYPE, ('html', None, None), ('?', -1, -1))]) | |
65 output = stream.render(XMLSerializer, doctype=DocType.HTML_STRICT) | |
66 self.assertEqual('<!DOCTYPE html PUBLIC ' | |
67 '"-//W3C//DTD HTML 4.01//EN" ' | |
68 '"http://www.w3.org/TR/html4/strict.dtd">\n', | |
69 output) | |
70 | |
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
|
71 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
|
72 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
|
73 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
|
74 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
|
75 |
1 | 76 |
77 def suite(): | |
78 suite = unittest.TestSuite() | |
85 | 79 suite.addTest(unittest.makeSuite(XMLSerializerTestCase, 'test')) |
80 suite.addTest(doctest.DocTestSuite(XMLSerializer.__module__)) | |
1 | 81 return suite |
82 | |
83 if __name__ == '__main__': | |
84 unittest.main(defaultTest='suite') |