Mercurial > genshi > mirror
annotate markup/tests/core.py @ 189:0be9ba422a33 trunk
Bump up version number on trunk.
author | cmlenz |
---|---|
date | Tue, 22 Aug 2006 15:39:28 +0000 |
parents | a4a0ca41b6ad |
children | 51d4101f49ca |
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 * |
147
a4a0ca41b6ad
Use `xmlcharrefreplace` when encoding the output in `Stream.render()`, so that encoding the output to legacy encodings such as ASCII or ISO-8859-1 should always work.
cmlenz
parents:
116
diff
changeset
|
18 from markup.input import XML, ParseError |
a4a0ca41b6ad
Use `xmlcharrefreplace` when encoding the output in `Stream.render()`, so that encoding the output to legacy encodings such as ASCII or ISO-8859-1 should always work.
cmlenz
parents:
116
diff
changeset
|
19 |
a4a0ca41b6ad
Use `xmlcharrefreplace` when encoding the output in `Stream.render()`, so that encoding the output to legacy encodings such as ASCII or ISO-8859-1 should always work.
cmlenz
parents:
116
diff
changeset
|
20 |
a4a0ca41b6ad
Use `xmlcharrefreplace` when encoding the output in `Stream.render()`, so that encoding the output to legacy encodings such as ASCII or ISO-8859-1 should always work.
cmlenz
parents:
116
diff
changeset
|
21 class StreamTestCase(unittest.TestCase): |
a4a0ca41b6ad
Use `xmlcharrefreplace` when encoding the output in `Stream.render()`, so that encoding the output to legacy encodings such as ASCII or ISO-8859-1 should always work.
cmlenz
parents:
116
diff
changeset
|
22 |
a4a0ca41b6ad
Use `xmlcharrefreplace` when encoding the output in `Stream.render()`, so that encoding the output to legacy encodings such as ASCII or ISO-8859-1 should always work.
cmlenz
parents:
116
diff
changeset
|
23 def test_render_utf8(self): |
a4a0ca41b6ad
Use `xmlcharrefreplace` when encoding the output in `Stream.render()`, so that encoding the output to legacy encodings such as ASCII or ISO-8859-1 should always work.
cmlenz
parents:
116
diff
changeset
|
24 xml = XML('<li>Über uns</li>') |
a4a0ca41b6ad
Use `xmlcharrefreplace` when encoding the output in `Stream.render()`, so that encoding the output to legacy encodings such as ASCII or ISO-8859-1 should always work.
cmlenz
parents:
116
diff
changeset
|
25 self.assertEqual('<li>Über uns</li>', xml.render()) |
a4a0ca41b6ad
Use `xmlcharrefreplace` when encoding the output in `Stream.render()`, so that encoding the output to legacy encodings such as ASCII or ISO-8859-1 should always work.
cmlenz
parents:
116
diff
changeset
|
26 |
a4a0ca41b6ad
Use `xmlcharrefreplace` when encoding the output in `Stream.render()`, so that encoding the output to legacy encodings such as ASCII or ISO-8859-1 should always work.
cmlenz
parents:
116
diff
changeset
|
27 def test_render_unicode(self): |
a4a0ca41b6ad
Use `xmlcharrefreplace` when encoding the output in `Stream.render()`, so that encoding the output to legacy encodings such as ASCII or ISO-8859-1 should always work.
cmlenz
parents:
116
diff
changeset
|
28 xml = XML('<li>Über uns</li>') |
a4a0ca41b6ad
Use `xmlcharrefreplace` when encoding the output in `Stream.render()`, so that encoding the output to legacy encodings such as ASCII or ISO-8859-1 should always work.
cmlenz
parents:
116
diff
changeset
|
29 self.assertEqual(u'<li>Über uns</li>', xml.render(encoding=None)) |
a4a0ca41b6ad
Use `xmlcharrefreplace` when encoding the output in `Stream.render()`, so that encoding the output to legacy encodings such as ASCII or ISO-8859-1 should always work.
cmlenz
parents:
116
diff
changeset
|
30 |
a4a0ca41b6ad
Use `xmlcharrefreplace` when encoding the output in `Stream.render()`, so that encoding the output to legacy encodings such as ASCII or ISO-8859-1 should always work.
cmlenz
parents:
116
diff
changeset
|
31 def test_render_ascii(self): |
a4a0ca41b6ad
Use `xmlcharrefreplace` when encoding the output in `Stream.render()`, so that encoding the output to legacy encodings such as ASCII or ISO-8859-1 should always work.
cmlenz
parents:
116
diff
changeset
|
32 xml = XML('<li>Über uns</li>') |
a4a0ca41b6ad
Use `xmlcharrefreplace` when encoding the output in `Stream.render()`, so that encoding the output to legacy encodings such as ASCII or ISO-8859-1 should always work.
cmlenz
parents:
116
diff
changeset
|
33 self.assertEqual('<li>Über uns</li>', xml.render(encoding='ascii')) |
1 | 34 |
35 | |
36 class MarkupTestCase(unittest.TestCase): | |
37 | |
116 | 38 def test_repr(self): |
39 markup = Markup('foo') | |
40 self.assertEquals('<Markup "foo">', repr(markup)) | |
41 | |
1 | 42 def test_escape(self): |
43 markup = escape('<b>"&"</b>') | |
44 assert isinstance(markup, Markup) | |
45 self.assertEquals('<b>"&"</b>', markup) | |
46 | |
47 def test_escape_noquotes(self): | |
48 markup = escape('<b>"&"</b>', quotes=False) | |
49 assert isinstance(markup, Markup) | |
50 self.assertEquals('<b>"&"</b>', markup) | |
51 | |
52 def test_unescape_markup(self): | |
53 string = '<b>"&"</b>' | |
54 markup = Markup.escape(string) | |
55 assert isinstance(markup, Markup) | |
56 self.assertEquals(string, unescape(markup)) | |
57 | |
58 def test_add_str(self): | |
59 markup = Markup('<b>foo</b>') + '<br/>' | |
60 assert isinstance(markup, Markup) | |
61 self.assertEquals('<b>foo</b><br/>', markup) | |
62 | |
63 def test_add_markup(self): | |
64 markup = Markup('<b>foo</b>') + Markup('<br/>') | |
65 assert isinstance(markup, Markup) | |
66 self.assertEquals('<b>foo</b><br/>', markup) | |
67 | |
68 def test_add_reverse(self): | |
69 markup = 'foo' + Markup('<b>bar</b>') | |
70 assert isinstance(markup, unicode) | |
71 self.assertEquals('foo<b>bar</b>', markup) | |
72 | |
73 def test_mod(self): | |
74 markup = Markup('<b>%s</b>') % '&' | |
75 assert isinstance(markup, Markup) | |
76 self.assertEquals('<b>&</b>', markup) | |
77 | |
78 def test_mod_multi(self): | |
79 markup = Markup('<b>%s</b> %s') % ('&', 'boo') | |
80 assert isinstance(markup, Markup) | |
81 self.assertEquals('<b>&</b> boo', markup) | |
82 | |
83 def test_mul(self): | |
84 markup = Markup('<b>foo</b>') * 2 | |
85 assert isinstance(markup, Markup) | |
86 self.assertEquals('<b>foo</b><b>foo</b>', markup) | |
87 | |
88 def test_join(self): | |
89 markup = Markup('<br />').join(['foo', '<bar />', Markup('<baz />')]) | |
90 assert isinstance(markup, Markup) | |
91 self.assertEquals('foo<br /><bar /><br /><baz />', markup) | |
92 | |
93 def test_stripentities_all(self): | |
94 markup = Markup('& j').stripentities() | |
95 assert isinstance(markup, Markup) | |
96 self.assertEquals('& j', markup) | |
97 | |
98 def test_stripentities_keepxml(self): | |
116 | 99 markup = Markup('& j').stripentities(keepxmlentities=True) |
1 | 100 assert isinstance(markup, Markup) |
116 | 101 self.assertEquals('& j', markup) |
1 | 102 |
103 def test_striptags_empty(self): | |
104 markup = Markup('<br />').striptags() | |
105 assert isinstance(markup, Markup) | |
106 self.assertEquals('', markup) | |
107 | |
108 def test_striptags_mid(self): | |
109 markup = Markup('<a href="#">fo<br />o</a>').striptags() | |
110 assert isinstance(markup, Markup) | |
111 self.assertEquals('foo', markup) | |
112 | |
113 | |
114 def suite(): | |
115 suite = unittest.TestSuite() | |
147
a4a0ca41b6ad
Use `xmlcharrefreplace` when encoding the output in `Stream.render()`, so that encoding the output to legacy encodings such as ASCII or ISO-8859-1 should always work.
cmlenz
parents:
116
diff
changeset
|
116 suite.addTest(unittest.makeSuite(StreamTestCase, 'test')) |
1 | 117 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
|
118 suite.addTest(doctest.DocTestSuite(Markup.__module__)) |
1 | 119 return suite |
120 | |
121 if __name__ == '__main__': | |
122 unittest.main(defaultTest='suite') |