Mercurial > genshi > mirror
annotate markup/tests/core.py @ 143:3d4c214c979a trunk
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.
author | cmlenz |
---|---|
date | Fri, 11 Aug 2006 14:08:13 +0000 |
parents | c77c113846d6 |
children | a4a0ca41b6ad |
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 | |
18
5420cfe42d36
Actually make use of the `markup.core.Namespace` class, and add a couple of doctests.
cmlenz
parents:
1
diff
changeset
|
17 from markup.core import * |
21
b4d17897d053
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
18
diff
changeset
|
18 from markup.input import ParseError |
1 | 19 |
20 | |
21 class MarkupTestCase(unittest.TestCase): | |
22 | |
116 | 23 def test_repr(self): |
24 markup = Markup('foo') | |
25 self.assertEquals('<Markup "foo">', repr(markup)) | |
26 | |
1 | 27 def test_escape(self): |
28 markup = escape('<b>"&"</b>') | |
29 assert isinstance(markup, Markup) | |
30 self.assertEquals('<b>"&"</b>', markup) | |
31 | |
32 def test_escape_noquotes(self): | |
33 markup = escape('<b>"&"</b>', quotes=False) | |
34 assert isinstance(markup, Markup) | |
35 self.assertEquals('<b>"&"</b>', markup) | |
36 | |
37 def test_unescape_markup(self): | |
38 string = '<b>"&"</b>' | |
39 markup = Markup.escape(string) | |
40 assert isinstance(markup, Markup) | |
41 self.assertEquals(string, unescape(markup)) | |
42 | |
43 def test_add_str(self): | |
44 markup = Markup('<b>foo</b>') + '<br/>' | |
45 assert isinstance(markup, Markup) | |
46 self.assertEquals('<b>foo</b><br/>', markup) | |
47 | |
48 def test_add_markup(self): | |
49 markup = Markup('<b>foo</b>') + Markup('<br/>') | |
50 assert isinstance(markup, Markup) | |
51 self.assertEquals('<b>foo</b><br/>', markup) | |
52 | |
53 def test_add_reverse(self): | |
54 markup = 'foo' + Markup('<b>bar</b>') | |
55 assert isinstance(markup, unicode) | |
56 self.assertEquals('foo<b>bar</b>', markup) | |
57 | |
58 def test_mod(self): | |
59 markup = Markup('<b>%s</b>') % '&' | |
60 assert isinstance(markup, Markup) | |
61 self.assertEquals('<b>&</b>', markup) | |
62 | |
63 def test_mod_multi(self): | |
64 markup = Markup('<b>%s</b> %s') % ('&', 'boo') | |
65 assert isinstance(markup, Markup) | |
66 self.assertEquals('<b>&</b> boo', markup) | |
67 | |
68 def test_mul(self): | |
69 markup = Markup('<b>foo</b>') * 2 | |
70 assert isinstance(markup, Markup) | |
71 self.assertEquals('<b>foo</b><b>foo</b>', markup) | |
72 | |
73 def test_join(self): | |
74 markup = Markup('<br />').join(['foo', '<bar />', Markup('<baz />')]) | |
75 assert isinstance(markup, Markup) | |
76 self.assertEquals('foo<br /><bar /><br /><baz />', markup) | |
77 | |
78 def test_stripentities_all(self): | |
79 markup = Markup('& j').stripentities() | |
80 assert isinstance(markup, Markup) | |
81 self.assertEquals('& j', markup) | |
82 | |
83 def test_stripentities_keepxml(self): | |
116 | 84 markup = Markup('& j').stripentities(keepxmlentities=True) |
1 | 85 assert isinstance(markup, Markup) |
116 | 86 self.assertEquals('& j', markup) |
1 | 87 |
88 def test_striptags_empty(self): | |
89 markup = Markup('<br />').striptags() | |
90 assert isinstance(markup, Markup) | |
91 self.assertEquals('', markup) | |
92 | |
93 def test_striptags_mid(self): | |
94 markup = Markup('<a href="#">fo<br />o</a>').striptags() | |
95 assert isinstance(markup, Markup) | |
96 self.assertEquals('foo', markup) | |
97 | |
98 | |
99 def suite(): | |
100 suite = unittest.TestSuite() | |
101 suite.addTest(unittest.makeSuite(MarkupTestCase, 'test')) | |
18
5420cfe42d36
Actually make use of the `markup.core.Namespace` class, and add a couple of doctests.
cmlenz
parents:
1
diff
changeset
|
102 suite.addTest(doctest.DocTestSuite(Markup.__module__)) |
1 | 103 return suite |
104 | |
105 if __name__ == '__main__': | |
106 unittest.main(defaultTest='suite') |