2 # -*- coding: utf-8 -*-
5 # Author: David Goodger <goodger@python.org>
6 # Copyright: This module has been placed in the public domain.
9 Test module for nodes.py.
13 from types
import ClassType
14 import DocutilsTestSupport
# must be imported before docutils
15 from DocutilsTestSupport
import nodes
, utils
20 class TextTests(unittest
.TestCase
):
23 self
.text
= nodes
.Text('Line 1.\nLine 2.')
24 self
.unicode_text
= nodes
.Text(unicode('Möhren', 'utf8'))
27 self
.assertEquals(repr(self
.text
), r
"<#text: 'Line 1.\nLine 2.'>")
30 self
.assertEquals(str(self
.text
), 'Line 1.\nLine 2.')
32 def test_unicode(self
):
33 self
.assertEquals(unicode(self
.unicode_text
), unicode('Möhren', 'utf8'))
34 self
.assertEquals(str(self
.unicode_text
), 'M\xf6hren')
36 def test_astext(self
):
37 self
.assertEquals(self
.text
.astext(), 'Line 1.\nLine 2.')
39 def test_pformat(self
):
40 self
.assertEquals(self
.text
.pformat(), 'Line 1.\nLine 2.\n')
42 def test_asciirestriction(self
):
43 self
.assertRaises(UnicodeError, nodes
.Text
, 'hol%s' % chr(224))
44 # more specifically: UnicodeDecodeError since py2.3
47 class ElementTests(unittest
.TestCase
):
50 element
= nodes
.Element()
51 self
.assertEquals(repr(element
), '<Element: >')
52 self
.assertEquals(str(element
), '<Element/>')
54 self
.assertEquals(dom
.toxml(), '<Element/>')
57 self
.assertEquals(repr(element
), '<Element: >')
58 self
.assertEquals(str(element
), '<Element attr="1"/>')
60 self
.assertEquals(dom
.toxml(), '<Element attr="1"/>')
62 self
.assertEquals(element
.pformat(), '<Element attr="1">\n')
64 element
['mark'] = u
'\u2022'
65 self
.assertEquals(repr(element
), '<Element: >')
66 self
.assertEquals(str(element
), '<Element mark="\\u2022"/>')
68 self
.assertEquals(dom
.toxml(), u
'<Element mark="\u2022"/>')
71 def test_withtext(self
):
72 element
= nodes
.Element('text\nmore', nodes
.Text('text\nmore'))
73 self
.assertEquals(repr(element
), r
"<Element: <#text: 'text\nmore'>>")
74 self
.assertEquals(str(element
), '<Element>text\nmore</Element>')
76 self
.assertEquals(dom
.toxml(), '<Element>text\nmore</Element>')
79 self
.assertEquals(repr(element
), r
"<Element: <#text: 'text\nmore'>>")
80 self
.assertEquals(str(element
),
81 '<Element attr="1">text\nmore</Element>')
83 self
.assertEquals(dom
.toxml(),
84 '<Element attr="1">text\nmore</Element>')
86 self
.assertEquals(element
.pformat(),
87 '<Element attr="1">\n text\n more\n')
90 element
= nodes
.Element()
91 element
+= nodes
.Element()
92 self
.assert_(len(element
))
94 self
.assert_(not len(element
))
96 def test_normal_attributes(self
):
97 element
= nodes
.Element()
98 self
.assert_('foo' not in element
)
99 self
.assertRaises(KeyError, element
.__getitem
__, 'foo')
100 element
['foo'] = 'sometext'
101 self
.assertEquals(element
['foo'], 'sometext')
103 self
.assertRaises(KeyError, element
.__getitem
__, 'foo')
105 def test_default_attributes(self
):
106 element
= nodes
.Element()
107 self
.assertEquals(element
['ids'], [])
108 self
.assertEquals(element
.non_default_attributes(), {})
109 self
.assert_(not element
.is_not_default('ids'))
110 self
.assert_(element
['ids'] is not nodes
.Element()['ids'])
111 element
['ids'].append('someid')
112 self
.assertEquals(element
['ids'], ['someid'])
113 self
.assertEquals(element
.non_default_attributes(),
115 self
.assert_(element
.is_not_default('ids'))
117 def test_update_basic_atts(self
):
118 element1
= nodes
.Element(ids
=['foo', 'bar'], test
=['test1'])
119 element2
= nodes
.Element(ids
=['baz', 'qux'], test
=['test2'])
120 element1
.update_basic_atts(element2
)
121 # 'ids' are appended because 'ids' is a basic attribute.
122 self
.assertEquals(element1
['ids'], ['foo', 'bar', 'baz', 'qux'])
123 # 'test' is not overwritten because it is not a basic attribute.
124 self
.assertEquals(element1
['test'], ['test1'])
126 def test_replace_self(self
):
127 parent
= nodes
.Element(ids
=['parent'])
128 child1
= nodes
.Element(ids
=['child1'])
129 grandchild
= nodes
.Element(ids
=['grandchild'])
131 child2
= nodes
.Element(ids
=['child2'])
132 twins
= [nodes
.Element(ids
=['twin%s' % i
]) for i
in (1, 2)]
134 child3
= nodes
.Element(ids
=['child3'])
135 child4
= nodes
.Element(ids
=['child4'])
136 parent
+= [child1
, child2
, child3
, child4
]
137 self
.assertEquals(parent
.pformat(), """\
138 <Element ids="parent">
139 <Element ids="child1">
140 <Element ids="grandchild">
141 <Element ids="child2">
142 <Element ids="twin1">
143 <Element ids="twin2">
144 <Element ids="child3">
145 <Element ids="child4">
147 # Replace child1 with the grandchild.
148 child1
.replace_self(child1
[0])
149 self
.assertEquals(parent
[0], grandchild
)
150 # Assert that 'ids' have been updated.
151 self
.assertEquals(grandchild
['ids'], ['grandchild', 'child1'])
152 # Replace child2 with its children.
153 child2
.replace_self(child2
[:])
154 self
.assertEquals(parent
[1:3], twins
)
155 # Assert that 'ids' have been propagated to first child.
156 self
.assertEquals(twins
[0]['ids'], ['twin1', 'child2'])
157 self
.assertEquals(twins
[1]['ids'], ['twin2'])
158 # Replace child3 with new child.
159 newchild
= nodes
.Element(ids
=['newchild'])
160 child3
.replace_self(newchild
)
161 self
.assertEquals(parent
[3], newchild
)
162 self
.assertEquals(newchild
['ids'], ['newchild', 'child3'])
163 # Crazy but possible case: Substitute child4 for itself.
164 child4
.replace_self(child4
)
165 # Make sure the 'child4' ID hasn't been duplicated.
166 self
.assertEquals(child4
['ids'], ['child4'])
167 self
.assertEquals(len(parent
), 5)
169 def test_unicode(self
):
170 node
= nodes
.Element(u
'Möhren', nodes
.Text(unicode('Möhren', 'utf8'),
171 unicode('Möhren', 'utf8')))
172 self
.assertEquals(unicode(node
), unicode('<Element>Möhren</Element>',
176 class MiscTests(unittest
.TestCase
):
178 def test_node_class_names(self
):
179 node_class_names
= []
181 c
= getattr(nodes
, x
)
182 if isinstance(c
, (type, ClassType
)) and issubclass(c
, nodes
.Node
) \
183 and len(c
.__bases
__) > 1:
184 node_class_names
.append(x
)
185 node_class_names
.sort()
186 nodes
.node_class_names
.sort()
187 self
.assertEquals(node_class_names
, nodes
.node_class_names
)
189 ids
= [(u
'a', 'a'), ('A', 'a'), ('', ''), ('a b \n c', 'a-b-c'),
190 ('a.b.c', 'a-b-c'), (' - a - b - c - ', 'a-b-c'), (' - ', ''),
191 (u
'\u2020\u2066', ''), (u
'a \xa7 b \u2020 c', 'a-b-c'),
192 ('1', ''), ('1abc', 'abc'),
195 (u
'\u00f8 o with stroke', 'o-o-with-stroke'),
196 (u
'\u0111 d with stroke', 'd-d-with-stroke'),
197 (u
'\u0127 h with stroke', 'h-h-with-stroke'),
198 (u
'\u0131 dotless i', 'i-dotless-i'),
199 (u
'\u0142 l with stroke', 'l-l-with-stroke'),
200 (u
'\u0167 t with stroke', 't-t-with-stroke'),
201 # From Latin Extended-B
202 (u
'\u0180 b with stroke', 'b-b-with-stroke'),
203 (u
'\u0183 b with topbar', 'b-b-with-topbar'),
204 (u
'\u0188 c with hook', 'c-c-with-hook'),
205 (u
'\u018c d with topbar', 'd-d-with-topbar'),
206 (u
'\u0192 f with hook', 'f-f-with-hook'),
207 (u
'\u0199 k with hook', 'k-k-with-hook'),
208 (u
'\u019a l with bar', 'l-l-with-bar'),
209 (u
'\u019e n with long right leg', 'n-n-with-long-right-leg'),
210 (u
'\u01a5 p with hook', 'p-p-with-hook'),
211 (u
'\u01ab t with palatal hook', 't-t-with-palatal-hook'),
212 (u
'\u01ad t with hook', 't-t-with-hook'),
213 (u
'\u01b4 y with hook', 'y-y-with-hook'),
214 (u
'\u01b6 z with stroke', 'z-z-with-stroke'),
215 (u
'\u01e5 g with stroke', 'g-g-with-stroke'),
216 (u
'\u0225 z with hook', 'z-z-with-hook'),
217 (u
'\u0234 l with curl', 'l-l-with-curl'),
218 (u
'\u0235 n with curl', 'n-n-with-curl'),
219 (u
'\u0236 t with curl', 't-t-with-curl'),
220 (u
'\u0237 dotless j', 'j-dotless-j'),
221 (u
'\u023c c with stroke', 'c-c-with-stroke'),
222 (u
'\u023f s with swash tail', 's-s-with-swash-tail'),
223 (u
'\u0240 z with swash tail', 'z-z-with-swash-tail'),
224 (u
'\u0247 e with stroke', 'e-e-with-stroke'),
225 (u
'\u0249 j with stroke', 'j-j-with-stroke'),
226 (u
'\u024b q with hook tail', 'q-q-with-hook-tail'),
227 (u
'\u024d r with stroke', 'r-r-with-stroke'),
228 (u
'\u024f y with stroke', 'y-y-with-stroke'),
230 ids_unicode_not_2_2
= [
231 # From Latin-1 Supplements
232 (u
'\u00e0: a with grave', 'a-a-with-grave'),
233 (u
'\u00e1 a with acute', 'a-a-with-acute'),
234 (u
'\u00e2 a with circumflex', 'a-a-with-circumflex'),
235 (u
'\u00e3 a with tilde', 'a-a-with-tilde'),
236 (u
'\u00e4 a with diaeresis', 'a-a-with-diaeresis'),
237 (u
'\u00e5 a with ring above', 'a-a-with-ring-above'),
238 (u
'\u00e7 c with cedilla', 'c-c-with-cedilla'),
239 (u
'\u00e8 e with grave', 'e-e-with-grave'),
240 (u
'\u00e9 e with acute', 'e-e-with-acute'),
241 (u
'\u00ea e with circumflex', 'e-e-with-circumflex'),
242 (u
'\u00eb e with diaeresis', 'e-e-with-diaeresis'),
243 (u
'\u00ec i with grave', 'i-i-with-grave'),
244 (u
'\u00ed i with acute', 'i-i-with-acute'),
245 (u
'\u00ee i with circumflex', 'i-i-with-circumflex'),
246 (u
'\u00ef i with diaeresis', 'i-i-with-diaeresis'),
247 (u
'\u00f1 n with tilde', 'n-n-with-tilde'),
248 (u
'\u00f2 o with grave', 'o-o-with-grave'),
249 (u
'\u00f3 o with acute', 'o-o-with-acute'),
250 (u
'\u00f4 o with circumflex', 'o-o-with-circumflex'),
251 (u
'\u00f5 o with tilde', 'o-o-with-tilde'),
252 (u
'\u00f6 o with diaeresis', 'o-o-with-diaeresis'),
253 (u
'\u00f9 u with grave', 'u-u-with-grave'),
254 (u
'\u00fa u with acute', 'u-u-with-acute'),
255 (u
'\u00fb u with circumflex', 'u-u-with-circumflex'),
256 (u
'\u00fc u with diaeresis', 'u-u-with-diaeresis'),
257 (u
'\u00fd y with acute', 'y-y-with-acute'),
258 (u
'\u00ff y with diaeresis', 'y-y-with-diaeresis'),
259 # From Latin Extended-A
260 (u
'\u0101 a with macron', 'a-a-with-macron'),
261 (u
'\u0103 a with breve', 'a-a-with-breve'),
262 (u
'\u0105 a with ogonek', 'a-a-with-ogonek'),
263 (u
'\u0107 c with acute', 'c-c-with-acute'),
264 (u
'\u0109 c with circumflex', 'c-c-with-circumflex'),
265 (u
'\u010b c with dot above', 'c-c-with-dot-above'),
266 (u
'\u010d c with caron', 'c-c-with-caron'),
267 (u
'\u010f d with caron', 'd-d-with-caron'),
268 (u
'\u0113 e with macron', 'e-e-with-macron'),
269 (u
'\u0115 e with breve', 'e-e-with-breve'),
270 (u
'\u0117 e with dot above', 'e-e-with-dot-above'),
271 (u
'\u0119 e with ogonek', 'e-e-with-ogonek'),
272 (u
'\u011b e with caron', 'e-e-with-caron'),
273 (u
'\u011d g with circumflex', 'g-g-with-circumflex'),
274 (u
'\u011f g with breve', 'g-g-with-breve'),
275 (u
'\u0121 g with dot above', 'g-g-with-dot-above'),
276 (u
'\u0123 g with cedilla', 'g-g-with-cedilla'),
277 (u
'\u0125 h with circumflex', 'h-h-with-circumflex'),
278 (u
'\u0129 i with tilde', 'i-i-with-tilde'),
279 (u
'\u012b i with macron', 'i-i-with-macron'),
280 (u
'\u012d i with breve', 'i-i-with-breve'),
281 (u
'\u012f i with ogonek', 'i-i-with-ogonek'),
282 (u
'\u0133 ligature ij', 'ij-ligature-ij'),
283 (u
'\u0135 j with circumflex', 'j-j-with-circumflex'),
284 (u
'\u0137 k with cedilla', 'k-k-with-cedilla'),
285 (u
'\u013a l with acute', 'l-l-with-acute'),
286 (u
'\u013c l with cedilla', 'l-l-with-cedilla'),
287 (u
'\u013e l with caron', 'l-l-with-caron'),
288 (u
'\u0140 l with middle dot', 'l-l-with-middle-dot'),
289 (u
'\u0144 n with acute', 'n-n-with-acute'),
290 (u
'\u0146 n with cedilla', 'n-n-with-cedilla'),
291 (u
'\u0148 n with caron', 'n-n-with-caron'),
292 (u
'\u014d o with macron', 'o-o-with-macron'),
293 (u
'\u014f o with breve', 'o-o-with-breve'),
294 (u
'\u0151 o with double acute', 'o-o-with-double-acute'),
295 (u
'\u0155 r with acute', 'r-r-with-acute'),
296 (u
'\u0157 r with cedilla', 'r-r-with-cedilla'),
297 (u
'\u0159 r with caron', 'r-r-with-caron'),
298 (u
'\u015b s with acute', 's-s-with-acute'),
299 (u
'\u015d s with circumflex', 's-s-with-circumflex'),
300 (u
'\u015f s with cedilla', 's-s-with-cedilla'),
301 (u
'\u0161 s with caron', 's-s-with-caron'),
302 (u
'\u0163 t with cedilla', 't-t-with-cedilla'),
303 (u
'\u0165 t with caron', 't-t-with-caron'),
304 (u
'\u0169 u with tilde', 'u-u-with-tilde'),
305 (u
'\u016b u with macron', 'u-u-with-macron'),
306 (u
'\u016d u with breve', 'u-u-with-breve'),
307 (u
'\u016f u with ring above', 'u-u-with-ring-above'),
308 (u
'\u0171 u with double acute', 'u-u-with-double-acute'),
309 (u
'\u0173 u with ogonek', 'u-u-with-ogonek'),
310 (u
'\u0175 w with circumflex', 'w-w-with-circumflex'),
311 (u
'\u0177 y with circumflex', 'y-y-with-circumflex'),
312 (u
'\u017a z with acute', 'z-z-with-acute'),
313 (u
'\u017c z with dot above', 'z-z-with-dot-above'),
314 (u
'\u017e z with caron', 'z-z-with-caron'),
315 # From Latin Extended-B
316 (u
'\u01a1 o with horn', 'o-o-with-horn'),
317 (u
'\u01b0 u with horn', 'u-u-with-horn'),
318 (u
'\u01c6 dz with caron', 'dz-dz-with-caron'),
319 (u
'\u01c9 lj', 'lj-lj'),
320 (u
'\u01cc nj', 'nj-nj'),
321 (u
'\u01ce a with caron', 'a-a-with-caron'),
322 (u
'\u01d0 i with caron', 'i-i-with-caron'),
323 (u
'\u01d2 o with caron', 'o-o-with-caron'),
324 (u
'\u01d4 u with caron', 'u-u-with-caron'),
325 (u
'\u01e7 g with caron', 'g-g-with-caron'),
326 (u
'\u01e9 k with caron', 'k-k-with-caron'),
327 (u
'\u01eb o with ogonek', 'o-o-with-ogonek'),
328 (u
'\u01ed o with ogonek and macron', 'o-o-with-ogonek-and-macron'),
329 (u
'\u01f0 j with caron', 'j-j-with-caron'),
330 (u
'\u01f3 dz', 'dz-dz'),
331 (u
'\u01f5 g with acute', 'g-g-with-acute'),
332 (u
'\u01f9 n with grave', 'n-n-with-grave'),
333 (u
'\u0201 a with double grave', 'a-a-with-double-grave'),
334 (u
'\u0203 a with inverted breve', 'a-a-with-inverted-breve'),
335 (u
'\u0205 e with double grave', 'e-e-with-double-grave'),
336 (u
'\u0207 e with inverted breve', 'e-e-with-inverted-breve'),
337 (u
'\u0209 i with double grave', 'i-i-with-double-grave'),
338 (u
'\u020b i with inverted breve', 'i-i-with-inverted-breve'),
339 (u
'\u020d o with double grave', 'o-o-with-double-grave'),
340 (u
'\u020f o with inverted breve', 'o-o-with-inverted-breve'),
341 (u
'\u0211 r with double grave', 'r-r-with-double-grave'),
342 (u
'\u0213 r with inverted breve', 'r-r-with-inverted-breve'),
343 (u
'\u0215 u with double grave', 'u-u-with-double-grave'),
344 (u
'\u0217 u with inverted breve', 'u-u-with-inverted-breve'),
345 (u
'\u0219 s with comma below', 's-s-with-comma-below'),
346 (u
'\u021b t with comma below', 't-t-with-comma-below'),
347 (u
'\u021f h with caron', 'h-h-with-caron'),
348 (u
'\u0227 a with dot above', 'a-a-with-dot-above'),
349 (u
'\u0229 e with cedilla', 'e-e-with-cedilla'),
350 (u
'\u022f o with dot above', 'o-o-with-dot-above'),
351 (u
'\u0233 y with macron', 'y-y-with-macron'),
352 # digraphs From Latin-1 Supplements
353 (u
'\u00df: ligature sz', 'sz-ligature-sz'),
354 (u
'\u00e6 ae', 'ae-ae'),
355 (u
'\u0153 ligature oe', 'oe-ligature-oe'),
356 (u
'\u0238 db digraph', 'db-db-digraph'),
357 (u
'\u0239 qp digraph', 'qp-qp-digraph'),
360 def test_make_id(self
):
362 tests
= self
.ids
+ self
.ids_unicode_all
364 if sys
.version_info
[:2] != (2, 2):
365 tests
+= self
.ids_unicode_not_2_2
366 for input, expect
in tests
:
367 output
= nodes
.make_id(input)
369 failures
.append("'%s' != '%s'" % (expect
, output
))
371 self
.fail("%d failures in %d\n%s" % (len(failures
), len(self
.ids
), "\n".join(failures
)))
373 def test_traverse(self
):
376 e
[0] += nodes
.Element()
377 e
[0] += nodes
.TextElement()
378 e
[0][1] += nodes
.Text('some text')
381 self
.assertEquals(list(e
.traverse()),
382 [e
, e
[0], e
[0][0], e
[0][1], e
[0][1][0], e
[1], e
[2]])
383 self
.assertEquals(list(e
.traverse(include_self
=0)),
384 [e
[0], e
[0][0], e
[0][1], e
[0][1][0], e
[1], e
[2]])
385 self
.assertEquals(list(e
.traverse(descend
=0)),
387 self
.assertEquals(list(e
[0].traverse(descend
=0, ascend
=1)),
389 self
.assertEquals(list(e
[0][0].traverse(descend
=0, ascend
=1)),
390 [e
[0][0], e
[0][1], e
[1], e
[2]])
391 self
.assertEquals(list(e
[0][0].traverse(descend
=0, siblings
=1)),
393 self
.testlist
= e
[0:2]
394 self
.assertEquals(list(e
.traverse(condition
=self
.not_in_testlist
)),
395 [e
, e
[0][0], e
[0][1], e
[0][1][0], e
[2]])
396 # Return siblings despite siblings=0 because ascend is true.
397 self
.assertEquals(list(e
[1].traverse(ascend
=1, siblings
=0)),
399 self
.assertEquals(list(e
[0].traverse()),
400 [e
[0], e
[0][0], e
[0][1], e
[0][1][0]])
401 self
.testlist
= [e
[0][0], e
[0][1]]
402 self
.assertEquals(list(e
[0].traverse(condition
=self
.not_in_testlist
)),
404 self
.testlist
.append(e
[0][1][0])
405 self
.assertEquals(list(e
[0].traverse(condition
=self
.not_in_testlist
)),
407 self
.assertEquals(list(e
.traverse(nodes
.TextElement
)), [e
[0][1]])
409 def test_next_node(self
):
412 e
[0] += nodes
.Element()
413 e
[0] += nodes
.TextElement()
414 e
[0][1] += nodes
.Text('some text')
417 self
.testlist
= [e
[0], e
[0][1], e
[1]]
418 compare
= [(e
, e
[0][0]),
420 (e
[0][0], e
[0][1][0]),
421 (e
[0][1], e
[0][1][0]),
425 for node
, next_node
in compare
:
426 self
.assertEquals(node
.next_node(self
.not_in_testlist
, ascend
=1),
428 self
.assertEquals(e
[0][0].next_node(ascend
=1), e
[0][1])
429 self
.assertEquals(e
[2].next_node(), None)
431 def not_in_testlist(self
, x
):
432 return x
not in self
.testlist
435 grandchild
= nodes
.Text('rawsource')
436 child
= nodes
.emphasis('rawsource', grandchild
, att
='child')
437 e
= nodes
.Element('rawsource', child
, att
='e')
440 self
.assert_(e
is not e_copy
)
441 # Internal attributes (like `rawsource`) are not copied.
442 self
.assertEquals(e
.rawsource
, 'rawsource')
443 self
.assertEquals(e_copy
.rawsource
, '')
444 self
.assertEquals(e_copy
['att'], 'e')
445 # Children are not copied.
446 self
.assertEquals(len(e_copy
), 0)
448 e_deepcopy
= e
.deepcopy()
449 self
.assertEquals(e_deepcopy
.rawsource
, '')
450 self
.assertEquals(e_deepcopy
['att'], 'e')
451 # Children are copied recursively.
452 self
.assertEquals(e_deepcopy
[0][0], grandchild
)
453 self
.assert_(e_deepcopy
[0][0] is not grandchild
)
454 self
.assertEquals(e_deepcopy
[0]['att'], 'child')
457 class TreeCopyVisitorTests(unittest
.TestCase
):
460 document
= utils
.new_document('test data')
461 document
+= nodes
.paragraph('', 'Paragraph 1.')
462 blist
= nodes
.bullet_list()
463 for i
in range(1, 6):
464 item
= nodes
.list_item()
465 for j
in range(1, 4):
466 item
+= nodes
.paragraph('', 'Item %s, paragraph %s.' % (i
, j
))
469 self
.document
= document
471 def compare_trees(self
, one
, two
):
472 self
.assertEquals(one
.__class
__, two
.__class
__)
473 self
.assertNotEquals(id(one
), id(two
))
474 self
.assertEquals(len(one
.children
), len(two
.children
))
475 for i
in range(len(one
.children
)):
476 self
.compare_trees(one
.children
[i
], two
.children
[i
])
478 def test_copy_whole(self
):
479 visitor
= nodes
.TreeCopyVisitor(self
.document
)
480 self
.document
.walkabout(visitor
)
481 newtree
= visitor
.get_tree_copy()
482 self
.assertEquals(self
.document
.pformat(), newtree
.pformat())
483 self
.compare_trees(self
.document
, newtree
)
486 class MiscFunctionTests(unittest
.TestCase
):
488 names
= [('a', 'a'), ('A', 'a'), ('A a A', 'a a a'),
489 ('A a A a', 'a a a a'),
490 (' AaA\n\r\naAa\tAaA\t\t', 'aaa aaa aaa')]
492 def test_normalize_name(self
):
493 for input, output
in self
.names
:
494 normed
= nodes
.fully_normalize_name(input)
495 self
.assertEquals(normed
, output
)
497 def test_set_id_default(self
):
499 document
= utils
.new_document('test')
501 element
= nodes
.Element(names
=['test'])
502 document
.set_id(element
)
503 self
.assertEquals(element
['ids'], ['test'])
505 element
= nodes
.Element()
506 document
.set_id(element
)
507 self
.assertEquals(element
['ids'], ['id1'])
509 def test_set_id_custom(self
):
511 document
= utils
.new_document('test')
513 document
.settings
.id_prefix
= 'prefix'
514 document
.settings
.auto_id_prefix
= 'auto'
516 element
= nodes
.Element(names
=['test'])
517 document
.set_id(element
)
518 self
.assertEquals(element
['ids'], ['prefixtest'])
520 element
= nodes
.Element()
521 document
.set_id(element
)
522 self
.assertEquals(element
['ids'], ['prefixauto1'])
525 if __name__
== '__main__':