Mercurial > genshi > mirror
annotate genshi/tests/core.py @ 703:af57b12e3dd2 experimental-match-fastpaths
merge in trunk up through r818 - fundamentally changed the way MatchSet works, but actually is more consistent now
author | aflett |
---|---|
date | Mon, 31 Mar 2008 22:47:50 +0000 |
parents | 050657e221d4 |
children | 5420fe9d99a9 d143dd73789b |
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 | |
230 | 8 # are also available at http://genshi.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 | |
230 | 12 # history and logs, available at http://genshi.edgewall.org/log/. |
1 | 13 |
14 import doctest | |
279
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
15 import pickle |
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
16 from StringIO import StringIO |
703
af57b12e3dd2
merge in trunk up through r818 - fundamentally changed the way MatchSet works, but actually is more consistent now
aflett
parents:
666
diff
changeset
|
17 try: |
af57b12e3dd2
merge in trunk up through r818 - fundamentally changed the way MatchSet works, but actually is more consistent now
aflett
parents:
666
diff
changeset
|
18 from cStringIO import StringIO as cStringIO |
af57b12e3dd2
merge in trunk up through r818 - fundamentally changed the way MatchSet works, but actually is more consistent now
aflett
parents:
666
diff
changeset
|
19 except ImportError: |
af57b12e3dd2
merge in trunk up through r818 - fundamentally changed the way MatchSet works, but actually is more consistent now
aflett
parents:
666
diff
changeset
|
20 cStringIO = StringIO |
1 | 21 import unittest |
22 | |
279
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
23 from genshi import core |
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
24 from genshi.core import Markup, Namespace, QName, escape, unescape |
230 | 25 from genshi.input import XML, ParseError |
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
|
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 |
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 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
|
29 |
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 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
|
31 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
|
32 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
|
33 |
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
|
34 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
|
35 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
|
36 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
|
37 |
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
|
38 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
|
39 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
|
40 self.assertEqual('<li>Über uns</li>', xml.render(encoding='ascii')) |
1 | 41 |
703
af57b12e3dd2
merge in trunk up through r818 - fundamentally changed the way MatchSet works, but actually is more consistent now
aflett
parents:
666
diff
changeset
|
42 def test_render_output_stream_utf8(self): |
af57b12e3dd2
merge in trunk up through r818 - fundamentally changed the way MatchSet works, but actually is more consistent now
aflett
parents:
666
diff
changeset
|
43 xml = XML('<li>Über uns</li>') |
af57b12e3dd2
merge in trunk up through r818 - fundamentally changed the way MatchSet works, but actually is more consistent now
aflett
parents:
666
diff
changeset
|
44 strio = cStringIO() |
af57b12e3dd2
merge in trunk up through r818 - fundamentally changed the way MatchSet works, but actually is more consistent now
aflett
parents:
666
diff
changeset
|
45 self.assertEqual(None, xml.render(out=strio)) |
af57b12e3dd2
merge in trunk up through r818 - fundamentally changed the way MatchSet works, but actually is more consistent now
aflett
parents:
666
diff
changeset
|
46 self.assertEqual('<li>Über uns</li>', strio.getvalue()) |
af57b12e3dd2
merge in trunk up through r818 - fundamentally changed the way MatchSet works, but actually is more consistent now
aflett
parents:
666
diff
changeset
|
47 |
af57b12e3dd2
merge in trunk up through r818 - fundamentally changed the way MatchSet works, but actually is more consistent now
aflett
parents:
666
diff
changeset
|
48 def test_render_output_stream_unicode(self): |
af57b12e3dd2
merge in trunk up through r818 - fundamentally changed the way MatchSet works, but actually is more consistent now
aflett
parents:
666
diff
changeset
|
49 xml = XML('<li>Über uns</li>') |
af57b12e3dd2
merge in trunk up through r818 - fundamentally changed the way MatchSet works, but actually is more consistent now
aflett
parents:
666
diff
changeset
|
50 strio = StringIO() |
af57b12e3dd2
merge in trunk up through r818 - fundamentally changed the way MatchSet works, but actually is more consistent now
aflett
parents:
666
diff
changeset
|
51 self.assertEqual(None, xml.render(encoding=None, out=strio)) |
af57b12e3dd2
merge in trunk up through r818 - fundamentally changed the way MatchSet works, but actually is more consistent now
aflett
parents:
666
diff
changeset
|
52 self.assertEqual(u'<li>Über uns</li>', strio.getvalue()) |
af57b12e3dd2
merge in trunk up through r818 - fundamentally changed the way MatchSet works, but actually is more consistent now
aflett
parents:
666
diff
changeset
|
53 |
279
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
54 def test_pickle(self): |
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
55 xml = XML('<li>Foo</li>') |
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
56 buf = StringIO() |
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
57 pickle.dump(xml, buf, 2) |
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
58 buf.seek(0) |
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
59 xml = pickle.load(buf) |
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
60 self.assertEquals('<li>Foo</li>', xml.render()) |
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
61 |
1 | 62 |
63 class MarkupTestCase(unittest.TestCase): | |
64 | |
116 | 65 def test_repr(self): |
66 markup = Markup('foo') | |
382
2682dabbcd04
* Added documentation for the various stream event kinds.
cmlenz
parents:
326
diff
changeset
|
67 self.assertEquals("<Markup u'foo'>", repr(markup)) |
116 | 68 |
1 | 69 def test_escape(self): |
70 markup = escape('<b>"&"</b>') | |
212
0141f45c18e1
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 | 72 self.assertEquals('<b>"&"</b>', markup) |
73 | |
74 def test_escape_noquotes(self): | |
75 markup = escape('<b>"&"</b>', quotes=False) | |
212
0141f45c18e1
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 | 77 self.assertEquals('<b>"&"</b>', markup) |
78 | |
79 def test_unescape_markup(self): | |
80 string = '<b>"&"</b>' | |
81 markup = Markup.escape(string) | |
212
0141f45c18e1
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
|
82 assert type(markup) is Markup |
1 | 83 self.assertEquals(string, unescape(markup)) |
84 | |
85 def test_add_str(self): | |
86 markup = Markup('<b>foo</b>') + '<br/>' | |
212
0141f45c18e1
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
|
87 assert type(markup) is Markup |
1 | 88 self.assertEquals('<b>foo</b><br/>', markup) |
89 | |
90 def test_add_markup(self): | |
91 markup = Markup('<b>foo</b>') + Markup('<br/>') | |
212
0141f45c18e1
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
|
92 assert type(markup) is Markup |
1 | 93 self.assertEquals('<b>foo</b><br/>', markup) |
94 | |
95 def test_add_reverse(self): | |
204
51d4101f49ca
* Implement reverse add/mul operators for `Markup` class, so that the result is also a `Markup` instance.
cmlenz
parents:
147
diff
changeset
|
96 markup = '<br/>' + Markup('<b>bar</b>') |
212
0141f45c18e1
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
|
97 assert type(markup) is Markup |
204
51d4101f49ca
* Implement reverse add/mul operators for `Markup` class, so that the result is also a `Markup` instance.
cmlenz
parents:
147
diff
changeset
|
98 self.assertEquals('<br/><b>bar</b>', markup) |
1 | 99 |
100 def test_mod(self): | |
101 markup = Markup('<b>%s</b>') % '&' | |
212
0141f45c18e1
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
|
102 assert type(markup) is Markup |
1 | 103 self.assertEquals('<b>&</b>', markup) |
104 | |
105 def test_mod_multi(self): | |
106 markup = Markup('<b>%s</b> %s') % ('&', 'boo') | |
212
0141f45c18e1
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
|
107 assert type(markup) is Markup |
1 | 108 self.assertEquals('<b>&</b> boo', markup) |
109 | |
110 def test_mul(self): | |
111 markup = Markup('<b>foo</b>') * 2 | |
212
0141f45c18e1
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
|
112 assert type(markup) is Markup |
1 | 113 self.assertEquals('<b>foo</b><b>foo</b>', markup) |
114 | |
204
51d4101f49ca
* Implement reverse add/mul operators for `Markup` class, so that the result is also a `Markup` instance.
cmlenz
parents:
147
diff
changeset
|
115 def test_mul_reverse(self): |
51d4101f49ca
* Implement reverse add/mul operators for `Markup` class, so that the result is also a `Markup` instance.
cmlenz
parents:
147
diff
changeset
|
116 markup = 2 * Markup('<b>foo</b>') |
212
0141f45c18e1
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
|
117 assert type(markup) is Markup |
204
51d4101f49ca
* Implement reverse add/mul operators for `Markup` class, so that the result is also a `Markup` instance.
cmlenz
parents:
147
diff
changeset
|
118 self.assertEquals('<b>foo</b><b>foo</b>', markup) |
51d4101f49ca
* Implement reverse add/mul operators for `Markup` class, so that the result is also a `Markup` instance.
cmlenz
parents:
147
diff
changeset
|
119 |
1 | 120 def test_join(self): |
121 markup = Markup('<br />').join(['foo', '<bar />', Markup('<baz />')]) | |
212
0141f45c18e1
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
|
122 assert type(markup) is Markup |
1 | 123 self.assertEquals('foo<br /><bar /><br /><baz />', markup) |
124 | |
125 def test_stripentities_all(self): | |
126 markup = Markup('& j').stripentities() | |
212
0141f45c18e1
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
|
127 assert type(markup) is Markup |
1 | 128 self.assertEquals('& j', markup) |
129 | |
130 def test_stripentities_keepxml(self): | |
116 | 131 markup = Markup('& j').stripentities(keepxmlentities=True) |
212
0141f45c18e1
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
|
132 assert type(markup) is Markup |
116 | 133 self.assertEquals('& j', markup) |
1 | 134 |
135 def test_striptags_empty(self): | |
136 markup = Markup('<br />').striptags() | |
212
0141f45c18e1
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
|
137 assert type(markup) is Markup |
1 | 138 self.assertEquals('', markup) |
139 | |
140 def test_striptags_mid(self): | |
141 markup = Markup('<a href="#">fo<br />o</a>').striptags() | |
212
0141f45c18e1
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
|
142 assert type(markup) is Markup |
1 | 143 self.assertEquals('foo', markup) |
144 | |
279
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
145 def test_pickle(self): |
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
146 markup = Markup('foo') |
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
147 buf = StringIO() |
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
148 pickle.dump(markup, buf, 2) |
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
149 buf.seek(0) |
382
2682dabbcd04
* Added documentation for the various stream event kinds.
cmlenz
parents:
326
diff
changeset
|
150 self.assertEquals("<Markup u'foo'>", repr(pickle.load(buf))) |
279
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
151 |
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
152 |
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
153 class NamespaceTestCase(unittest.TestCase): |
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
154 |
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
155 def test_pickle(self): |
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
156 ns = Namespace('http://www.example.org/namespace') |
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
157 buf = StringIO() |
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
158 pickle.dump(ns, buf, 2) |
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
159 buf.seek(0) |
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
160 unpickled = pickle.load(buf) |
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
161 self.assertEquals('<Namespace "http://www.example.org/namespace">', |
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
162 repr(unpickled)) |
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
163 self.assertEquals('http://www.example.org/namespace', unpickled.uri) |
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
164 |
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
165 |
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
166 class QNameTestCase(unittest.TestCase): |
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
167 |
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
168 def test_pickle(self): |
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
169 qname = QName('http://www.example.org/namespace}elem') |
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
170 buf = StringIO() |
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
171 pickle.dump(qname, buf, 2) |
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
172 buf.seek(0) |
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
173 unpickled = pickle.load(buf) |
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
174 self.assertEquals('{http://www.example.org/namespace}elem', unpickled) |
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
175 self.assertEquals('http://www.example.org/namespace', |
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
176 unpickled.namespace) |
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
177 self.assertEquals('elem', unpickled.localname) |
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
178 |
326
f999da894391
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
|
179 def test_repr(self): |
f999da894391
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
|
180 self.assertEqual("QName(u'elem')", repr(QName('elem'))) |
f999da894391
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
|
181 self.assertEqual("QName(u'http://www.example.org/namespace}elem')", |
f999da894391
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
|
182 repr(QName('http://www.example.org/namespace}elem'))) |
f999da894391
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
|
183 |
666
050657e221d4
`QName` can now be constructed from a string with a leading curly brace, and some doc improvements. Closes #164.
cmlenz
parents:
382
diff
changeset
|
184 def test_leading_curly_brace(self): |
050657e221d4
`QName` can now be constructed from a string with a leading curly brace, and some doc improvements. Closes #164.
cmlenz
parents:
382
diff
changeset
|
185 qname = QName('{http://www.example.org/namespace}elem') |
050657e221d4
`QName` can now be constructed from a string with a leading curly brace, and some doc improvements. Closes #164.
cmlenz
parents:
382
diff
changeset
|
186 self.assertEquals('http://www.example.org/namespace', qname.namespace) |
050657e221d4
`QName` can now be constructed from a string with a leading curly brace, and some doc improvements. Closes #164.
cmlenz
parents:
382
diff
changeset
|
187 self.assertEquals('elem', qname.localname) |
050657e221d4
`QName` can now be constructed from a string with a leading curly brace, and some doc improvements. Closes #164.
cmlenz
parents:
382
diff
changeset
|
188 |
1 | 189 |
190 def suite(): | |
191 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
|
192 suite.addTest(unittest.makeSuite(StreamTestCase, 'test')) |
1 | 193 suite.addTest(unittest.makeSuite(MarkupTestCase, 'test')) |
279
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
194 suite.addTest(unittest.makeSuite(NamespaceTestCase, 'test')) |
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
195 suite.addTest(unittest.makeSuite(QNameTestCase, 'test')) |
a99666402b12
Some adjustments to make core data structures picklable (requires protocol 2).
cmlenz
parents:
230
diff
changeset
|
196 suite.addTest(doctest.DocTestSuite(core)) |
1 | 197 return suite |
198 | |
199 if __name__ == '__main__': | |
200 unittest.main(defaultTest='suite') |