annotate markup/tests/output.py @ 105:71f3db26eecb trunk

Include processing instructions in serialized streams.
author cmlenz
date Fri, 28 Jul 2006 15:15:50 +0000
parents 80386d62814f
children 10279d2eeec9
rev   line source
1
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
1 # -*- coding: utf-8 -*-
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
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
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
4 # All rights reserved.
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
5 #
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
6 # This software is licensed as described in the file COPYING, which
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
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
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
9 #
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
10 # This software consists of voluntary contributions made by many
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
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
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
13
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
14 import doctest
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
15 import unittest
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
16 import sys
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
17
85
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
18 from markup.core import Stream
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
19 from markup.output import DocType, XMLSerializer
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
20
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
21
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
22 class XMLSerializerTestCase(unittest.TestCase):
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
23
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
24 def test_doctype_in_stream(self):
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
25 stream = Stream([(Stream.DOCTYPE, DocType.HTML_STRICT, ('?', -1, -1))])
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
26 output = stream.render(XMLSerializer)
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
27 self.assertEqual('<!DOCTYPE html PUBLIC '
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
28 '"-//W3C//DTD HTML 4.01//EN" '
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
29 '"http://www.w3.org/TR/html4/strict.dtd">\n',
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
30 output)
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
31
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
32 def test_doctype_in_stream_no_sysid(self):
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
33 stream = Stream([(Stream.DOCTYPE,
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
34 ('html', '-//W3C//DTD HTML 4.01//EN', None),
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
35 ('?', -1, -1))])
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
36 output = stream.render(XMLSerializer)
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
37 self.assertEqual('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">\n',
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
38 output)
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
39
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
40 def test_doctype_in_stream_no_pubid(self):
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
41 stream = Stream([(Stream.DOCTYPE,
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
42 ('html', None, 'http://www.w3.org/TR/html4/strict.dtd'),
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
43 ('?', -1, -1))])
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
44 output = stream.render(XMLSerializer)
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
45 self.assertEqual('<!DOCTYPE html SYSTEM '
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
46 '"http://www.w3.org/TR/html4/strict.dtd">\n',
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
47 output)
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
48
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
49 def test_doctype_in_stream_no_pubid_or_sysid(self):
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
50 stream = Stream([(Stream.DOCTYPE, ('html', None, None),
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
51 ('?', -1, -1))])
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
52 output = stream.render(XMLSerializer)
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
53 self.assertEqual('<!DOCTYPE html>\n', output)
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
54
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
55 def test_serializer_doctype(self):
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
56 stream = Stream([])
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
57 output = stream.render(XMLSerializer, doctype=DocType.HTML_STRICT)
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
58 self.assertEqual('<!DOCTYPE html PUBLIC '
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
59 '"-//W3C//DTD HTML 4.01//EN" '
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
60 '"http://www.w3.org/TR/html4/strict.dtd">\n',
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
61 output)
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
62
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
63 def test_doctype_one_and_only(self):
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
64 stream = Stream([(Stream.DOCTYPE, ('html', None, None), ('?', -1, -1))])
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
65 output = stream.render(XMLSerializer, doctype=DocType.HTML_STRICT)
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
66 self.assertEqual('<!DOCTYPE html PUBLIC '
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
67 '"-//W3C//DTD HTML 4.01//EN" '
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
68 '"http://www.w3.org/TR/html4/strict.dtd">\n',
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
69 output)
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
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
105
71f3db26eecb Include processing instructions in serialized streams.
cmlenz
parents: 89
diff changeset
76 def test_processing_instruction(self):
71f3db26eecb Include processing instructions in serialized streams.
cmlenz
parents: 89
diff changeset
77 stream = Stream([(Stream.PI, ('python', 'x = 2'), ('?', -1, -1))])
71f3db26eecb Include processing instructions in serialized streams.
cmlenz
parents: 89
diff changeset
78 output = stream.render(XMLSerializer)
71f3db26eecb Include processing instructions in serialized streams.
cmlenz
parents: 89
diff changeset
79 self.assertEqual('<?python x = 2?>', output)
71f3db26eecb Include processing instructions in serialized streams.
cmlenz
parents: 89
diff changeset
80
1
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
81
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
82 def suite():
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
83 suite = unittest.TestSuite()
85
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
84 suite.addTest(unittest.makeSuite(XMLSerializerTestCase, 'test'))
4938c310d904 Improve handling of DOCTYPE declarations.
cmlenz
parents: 66
diff changeset
85 suite.addTest(doctest.DocTestSuite(XMLSerializer.__module__))
1
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
86 return suite
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
87
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
88 if __name__ == '__main__':
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
89 unittest.main(defaultTest='suite')
Copyright (C) 2012-2017 Edgewall Software