annotate genshi/tests/core.py @ 395:55cf81951686 experimental-inline

inline branch: Merged [439:479/trunk].
author cmlenz
date Thu, 28 Dec 2006 18:17:10 +0000
parents 08ada6b4b767
children 9729855cacf4 f0bb2c5ea0ff
rev   line source
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
1 # -*- coding: utf-8 -*-
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
2 #
66
822089ae65ce Switch copyright to Edgewall and URLs to markup.edgewall.org.
cmlenz
parents: 27
diff changeset
3 # Copyright (C) 2006 Edgewall Software
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
4 # All rights reserved.
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
5 #
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
6 # This software is licensed as described in the file COPYING, which
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
7 # you should have received as part of this distribution. The terms
230
24757b771651 Renamed Markup to Genshi in repository.
cmlenz
parents: 212
diff changeset
8 # are also available at http://genshi.edgewall.org/wiki/License.
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
9 #
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
10 # This software consists of voluntary contributions made by many
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
11 # individuals. For the exact contribution history, see the revision
230
24757b771651 Renamed Markup to Genshi in repository.
cmlenz
parents: 212
diff changeset
12 # history and logs, available at http://genshi.edgewall.org/log/.
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
13
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
14 import doctest
279
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
15 import pickle
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
16 from StringIO import StringIO
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
17 import unittest
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
18
279
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
19 from genshi import core
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
20 from genshi.core import Markup, Namespace, QName, escape, unescape
230
24757b771651 Renamed Markup to Genshi in repository.
cmlenz
parents: 212
diff changeset
21 from genshi.input import XML, ParseError
147
f7fb556f2678 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
f7fb556f2678 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
f7fb556f2678 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 class StreamTestCase(unittest.TestCase):
f7fb556f2678 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
f7fb556f2678 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 def test_render_utf8(self):
f7fb556f2678 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 xml = XML('<li>Über uns</li>')
f7fb556f2678 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 self.assertEqual('<li>Über uns</li>', xml.render())
f7fb556f2678 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
f7fb556f2678 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 def test_render_unicode(self):
f7fb556f2678 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 xml = XML('<li>Über uns</li>')
f7fb556f2678 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 self.assertEqual(u'<li>Über uns</li>', xml.render(encoding=None))
f7fb556f2678 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
f7fb556f2678 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
34 def test_render_ascii(self):
f7fb556f2678 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
35 xml = XML('<li>Über uns</li>')
f7fb556f2678 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
36 self.assertEqual('<li>&#220;ber uns</li>', xml.render(encoding='ascii'))
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
37
279
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
38 def test_pickle(self):
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
39 xml = XML('<li>Foo</li>')
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
40 buf = StringIO()
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
41 pickle.dump(xml, buf, 2)
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
42 buf.seek(0)
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
43 xml = pickle.load(buf)
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
44 self.assertEquals('<li>Foo</li>', xml.render())
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
45
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
46
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
47 class MarkupTestCase(unittest.TestCase):
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
48
116
88ac4c680120 Merged [135:138/branches/experimental/cspeedups].
cmlenz
parents: 113
diff changeset
49 def test_repr(self):
88ac4c680120 Merged [135:138/branches/experimental/cspeedups].
cmlenz
parents: 113
diff changeset
50 markup = Markup('foo')
395
55cf81951686 inline branch: Merged [439:479/trunk].
cmlenz
parents: 326
diff changeset
51 self.assertEquals("<Markup u'foo'>", repr(markup))
116
88ac4c680120 Merged [135:138/branches/experimental/cspeedups].
cmlenz
parents: 113
diff changeset
52
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
53 def test_escape(self):
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
54 markup = escape('<b>"&"</b>')
212
e8c43127d9a9 Refactored the handling of empty tags in the serializer: use an `EmptyTagFilter` that combines adjacent start/end events, instead of the generic pushback-iterator.
cmlenz
parents: 204
diff changeset
55 assert type(markup) is Markup
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
56 self.assertEquals('&lt;b&gt;&#34;&amp;&#34;&lt;/b&gt;', markup)
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
57
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
58 def test_escape_noquotes(self):
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
59 markup = escape('<b>"&"</b>', quotes=False)
212
e8c43127d9a9 Refactored the handling of empty tags in the serializer: use an `EmptyTagFilter` that combines adjacent start/end events, instead of the generic pushback-iterator.
cmlenz
parents: 204
diff changeset
60 assert type(markup) is Markup
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
61 self.assertEquals('&lt;b&gt;"&amp;"&lt;/b&gt;', markup)
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
62
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
63 def test_unescape_markup(self):
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
64 string = '<b>"&"</b>'
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
65 markup = Markup.escape(string)
212
e8c43127d9a9 Refactored the handling of empty tags in the serializer: use an `EmptyTagFilter` that combines adjacent start/end events, instead of the generic pushback-iterator.
cmlenz
parents: 204
diff changeset
66 assert type(markup) is Markup
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
67 self.assertEquals(string, unescape(markup))
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
68
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
69 def test_add_str(self):
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
70 markup = Markup('<b>foo</b>') + '<br/>'
212
e8c43127d9a9 Refactored the handling of empty tags in the serializer: use an `EmptyTagFilter` that combines adjacent start/end events, instead of the generic pushback-iterator.
cmlenz
parents: 204
diff changeset
71 assert type(markup) is Markup
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
72 self.assertEquals('<b>foo</b>&lt;br/&gt;', markup)
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
73
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
74 def test_add_markup(self):
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
75 markup = Markup('<b>foo</b>') + Markup('<br/>')
212
e8c43127d9a9 Refactored the handling of empty tags in the serializer: use an `EmptyTagFilter` that combines adjacent start/end events, instead of the generic pushback-iterator.
cmlenz
parents: 204
diff changeset
76 assert type(markup) is Markup
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
77 self.assertEquals('<b>foo</b><br/>', markup)
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
78
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
79 def test_add_reverse(self):
204
516a6cae0aa8 * Implement reverse add/mul operators for `Markup` class, so that the result is also a `Markup` instance.
cmlenz
parents: 147
diff changeset
80 markup = '<br/>' + Markup('<b>bar</b>')
212
e8c43127d9a9 Refactored the handling of empty tags in the serializer: use an `EmptyTagFilter` that combines adjacent start/end events, instead of the generic pushback-iterator.
cmlenz
parents: 204
diff changeset
81 assert type(markup) is Markup
204
516a6cae0aa8 * Implement reverse add/mul operators for `Markup` class, so that the result is also a `Markup` instance.
cmlenz
parents: 147
diff changeset
82 self.assertEquals('&lt;br/&gt;<b>bar</b>', markup)
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
83
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
84 def test_mod(self):
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
85 markup = Markup('<b>%s</b>') % '&'
212
e8c43127d9a9 Refactored the handling of empty tags in the serializer: use an `EmptyTagFilter` that combines adjacent start/end events, instead of the generic pushback-iterator.
cmlenz
parents: 204
diff changeset
86 assert type(markup) is Markup
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
87 self.assertEquals('<b>&amp;</b>', markup)
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
88
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
89 def test_mod_multi(self):
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
90 markup = Markup('<b>%s</b> %s') % ('&', 'boo')
212
e8c43127d9a9 Refactored the handling of empty tags in the serializer: use an `EmptyTagFilter` that combines adjacent start/end events, instead of the generic pushback-iterator.
cmlenz
parents: 204
diff changeset
91 assert type(markup) is Markup
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
92 self.assertEquals('<b>&amp;</b> boo', markup)
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
93
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
94 def test_mul(self):
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
95 markup = Markup('<b>foo</b>') * 2
212
e8c43127d9a9 Refactored the handling of empty tags in the serializer: use an `EmptyTagFilter` that combines adjacent start/end events, instead of the generic pushback-iterator.
cmlenz
parents: 204
diff changeset
96 assert type(markup) is Markup
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
97 self.assertEquals('<b>foo</b><b>foo</b>', markup)
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
98
204
516a6cae0aa8 * Implement reverse add/mul operators for `Markup` class, so that the result is also a `Markup` instance.
cmlenz
parents: 147
diff changeset
99 def test_mul_reverse(self):
516a6cae0aa8 * Implement reverse add/mul operators for `Markup` class, so that the result is also a `Markup` instance.
cmlenz
parents: 147
diff changeset
100 markup = 2 * Markup('<b>foo</b>')
212
e8c43127d9a9 Refactored the handling of empty tags in the serializer: use an `EmptyTagFilter` that combines adjacent start/end events, instead of the generic pushback-iterator.
cmlenz
parents: 204
diff changeset
101 assert type(markup) is Markup
204
516a6cae0aa8 * Implement reverse add/mul operators for `Markup` class, so that the result is also a `Markup` instance.
cmlenz
parents: 147
diff changeset
102 self.assertEquals('<b>foo</b><b>foo</b>', markup)
516a6cae0aa8 * Implement reverse add/mul operators for `Markup` class, so that the result is also a `Markup` instance.
cmlenz
parents: 147
diff changeset
103
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
104 def test_join(self):
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
105 markup = Markup('<br />').join(['foo', '<bar />', Markup('<baz />')])
212
e8c43127d9a9 Refactored the handling of empty tags in the serializer: use an `EmptyTagFilter` that combines adjacent start/end events, instead of the generic pushback-iterator.
cmlenz
parents: 204
diff changeset
106 assert type(markup) is Markup
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
107 self.assertEquals('foo<br />&lt;bar /&gt;<br /><baz />', markup)
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
108
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
109 def test_stripentities_all(self):
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
110 markup = Markup('&amp; &#106;').stripentities()
212
e8c43127d9a9 Refactored the handling of empty tags in the serializer: use an `EmptyTagFilter` that combines adjacent start/end events, instead of the generic pushback-iterator.
cmlenz
parents: 204
diff changeset
111 assert type(markup) is Markup
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
112 self.assertEquals('& j', markup)
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
113
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
114 def test_stripentities_keepxml(self):
116
88ac4c680120 Merged [135:138/branches/experimental/cspeedups].
cmlenz
parents: 113
diff changeset
115 markup = Markup('&amp; &#106;').stripentities(keepxmlentities=True)
212
e8c43127d9a9 Refactored the handling of empty tags in the serializer: use an `EmptyTagFilter` that combines adjacent start/end events, instead of the generic pushback-iterator.
cmlenz
parents: 204
diff changeset
116 assert type(markup) is Markup
116
88ac4c680120 Merged [135:138/branches/experimental/cspeedups].
cmlenz
parents: 113
diff changeset
117 self.assertEquals('&amp; j', markup)
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
118
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
119 def test_striptags_empty(self):
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
120 markup = Markup('<br />').striptags()
212
e8c43127d9a9 Refactored the handling of empty tags in the serializer: use an `EmptyTagFilter` that combines adjacent start/end events, instead of the generic pushback-iterator.
cmlenz
parents: 204
diff changeset
121 assert type(markup) is Markup
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
122 self.assertEquals('', markup)
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
123
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
124 def test_striptags_mid(self):
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
125 markup = Markup('<a href="#">fo<br />o</a>').striptags()
212
e8c43127d9a9 Refactored the handling of empty tags in the serializer: use an `EmptyTagFilter` that combines adjacent start/end events, instead of the generic pushback-iterator.
cmlenz
parents: 204
diff changeset
126 assert type(markup) is Markup
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
127 self.assertEquals('foo', markup)
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
128
279
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
129 def test_pickle(self):
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
130 markup = Markup('foo')
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
131 buf = StringIO()
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
132 pickle.dump(markup, buf, 2)
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
133 buf.seek(0)
395
55cf81951686 inline branch: Merged [439:479/trunk].
cmlenz
parents: 326
diff changeset
134 self.assertEquals("<Markup u'foo'>", repr(pickle.load(buf)))
279
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
135
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
136
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
137 class NamespaceTestCase(unittest.TestCase):
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
138
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
139 def test_pickle(self):
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
140 ns = Namespace('http://www.example.org/namespace')
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
141 buf = StringIO()
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
142 pickle.dump(ns, buf, 2)
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
143 buf.seek(0)
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
144 unpickled = pickle.load(buf)
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
145 self.assertEquals('<Namespace "http://www.example.org/namespace">',
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
146 repr(unpickled))
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
147 self.assertEquals('http://www.example.org/namespace', unpickled.uri)
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
148
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
149
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
150 class QNameTestCase(unittest.TestCase):
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
151
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
152 def test_pickle(self):
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
153 qname = QName('http://www.example.org/namespace}elem')
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
154 buf = StringIO()
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
155 pickle.dump(qname, buf, 2)
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
156 buf.seek(0)
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
157 unpickled = pickle.load(buf)
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
158 self.assertEquals('{http://www.example.org/namespace}elem', unpickled)
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
159 self.assertEquals('http://www.example.org/namespace',
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
160 unpickled.namespace)
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
161 self.assertEquals('elem', unpickled.localname)
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
162
326
08ada6b4b767 Fixed `__repr__` of the `QName`, `Attrs`, and `Expression` classes so that the output can be used as code to instantiate the object again.
cmlenz
parents: 279
diff changeset
163 def test_repr(self):
08ada6b4b767 Fixed `__repr__` of the `QName`, `Attrs`, and `Expression` classes so that the output can be used as code to instantiate the object again.
cmlenz
parents: 279
diff changeset
164 self.assertEqual("QName(u'elem')", repr(QName('elem')))
08ada6b4b767 Fixed `__repr__` of the `QName`, `Attrs`, and `Expression` classes so that the output can be used as code to instantiate the object again.
cmlenz
parents: 279
diff changeset
165 self.assertEqual("QName(u'http://www.example.org/namespace}elem')",
08ada6b4b767 Fixed `__repr__` of the `QName`, `Attrs`, and `Expression` classes so that the output can be used as code to instantiate the object again.
cmlenz
parents: 279
diff changeset
166 repr(QName('http://www.example.org/namespace}elem')))
08ada6b4b767 Fixed `__repr__` of the `QName`, `Attrs`, and `Expression` classes so that the output can be used as code to instantiate the object again.
cmlenz
parents: 279
diff changeset
167
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
168
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
169 def suite():
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
170 suite = unittest.TestSuite()
147
f7fb556f2678 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
171 suite.addTest(unittest.makeSuite(StreamTestCase, 'test'))
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
172 suite.addTest(unittest.makeSuite(MarkupTestCase, 'test'))
279
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
173 suite.addTest(unittest.makeSuite(NamespaceTestCase, 'test'))
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
174 suite.addTest(unittest.makeSuite(QNameTestCase, 'test'))
4b5b4653d41e Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents: 230
diff changeset
175 suite.addTest(doctest.DocTestSuite(core))
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
176 return suite
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
177
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
178 if __name__ == '__main__':
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
179 unittest.main(defaultTest='suite')
Copyright (C) 2012-2017 Edgewall Software