blob: 5bdee808412478d7fb04f6c3afa5d7e87f6a5e1e [file] [log] [blame]
Fred Drake17647f52000-07-03 16:37:42 +00001# test for xml.dom.minidom
Paul Prescod7993bcc2000-07-01 14:54:16 +00002
Fred Drake17647f52000-07-03 16:37:42 +00003from xml.dom.minidom import parse, Node, Document, parseString
Barry Warsawc79dff62000-09-26 18:00:20 +00004import xml.parsers.expat
Fred Drake17647f52000-07-03 16:37:42 +00005
6import os.path
7import sys
8import traceback
Martin v. Löwis89c528b2000-09-19 16:22:10 +00009from test_support import verbose
Fred Drake17647f52000-07-03 16:37:42 +000010
11if __name__ == "__main__":
12 base = sys.argv[0]
13else:
14 base = __file__
15tstfile = os.path.join(os.path.dirname(base), "test.xml")
16del base
Paul Prescod7993bcc2000-07-01 14:54:16 +000017
Jeremy Hylton3b0c6002000-10-12 17:31:36 +000018def confirm(test, testname = "Test"):
Fred Drake004d5e62000-10-23 17:22:08 +000019 if test:
Paul Prescod10d27662000-09-18 19:07:26 +000020 print "Passed " + testname
Fred Drake004d5e62000-10-23 17:22:08 +000021 else:
Paul Prescod10d27662000-09-18 19:07:26 +000022 print "Failed " + testname
23 raise Exception
24
Jeremy Hylton3b0c6002000-10-12 17:31:36 +000025Node._debug = 1
Paul Prescod7993bcc2000-07-01 14:54:16 +000026
Paul Prescod10d27662000-09-18 19:07:26 +000027def testParseFromFile():
28 from StringIO import StringIO
Jeremy Hylton3b0c6002000-10-12 17:31:36 +000029 dom = parse(StringIO(open(tstfile).read()))
Paul Prescod4c799192000-09-19 19:33:02 +000030 dom.unlink()
Martin v. Löwis89c528b2000-09-19 16:22:10 +000031 confirm(isinstance(dom,Document))
Paul Prescod10d27662000-09-18 19:07:26 +000032
Jeremy Hylton3b0c6002000-10-12 17:31:36 +000033def testGetElementsByTagName():
34 dom = parse(tstfile)
35 confirm(dom.getElementsByTagName("LI") == \
36 dom.documentElement.getElementsByTagName("LI"))
Paul Prescod7993bcc2000-07-01 14:54:16 +000037 dom.unlink()
Paul Prescod7993bcc2000-07-01 14:54:16 +000038
Jeremy Hylton3b0c6002000-10-12 17:31:36 +000039def testInsertBefore():
Fred Drakea1bde802000-11-21 22:02:43 +000040 dom = parseString("<doc><foo/></doc>")
41 root = dom.documentElement
42 elem = root.childNodes[0]
43 nelem = dom.createElement("element")
44 root.insertBefore(nelem, elem)
45 confirm(len(root.childNodes) == 2
46 and root.childNodes[0] is nelem
47 and root.childNodes[1] is elem
48 and root.firstChild is nelem
49 and root.lastChild is elem
50 and root.toxml() == "<doc><element/><foo/></doc>"
51 , "testInsertBefore -- node properly placed in tree")
52 nelem = dom.createElement("element")
53 root.insertBefore(nelem, None)
54 confirm(len(root.childNodes) == 3
55 and root.childNodes[1] is elem
56 and root.childNodes[2] is nelem
57 and root.lastChild is nelem
58 and nelem.previousSibling is elem
59 and root.toxml() == "<doc><element/><foo/><element/></doc>"
60 , "testInsertBefore -- node properly placed in tree")
61 nelem2 = dom.createElement("bar")
62 root.insertBefore(nelem2, nelem)
63 confirm(len(root.childNodes) == 4
64 and root.childNodes[2] is nelem2
65 and root.childNodes[3] is nelem
66 and nelem2.nextSibling is nelem
67 and nelem.previousSibling is nelem2
68 and root.toxml() == "<doc><element/><foo/><bar/><element/></doc>"
69 , "testInsertBefore -- node properly placed in tree")
Paul Prescod7993bcc2000-07-01 14:54:16 +000070 dom.unlink()
Paul Prescod7993bcc2000-07-01 14:54:16 +000071
72def testAppendChild():
Jeremy Hylton3b0c6002000-10-12 17:31:36 +000073 dom = parse(tstfile)
74 dom.documentElement.appendChild(dom.createComment(u"Hello"))
75 confirm(dom.documentElement.childNodes[-1].nodeName == "#comment")
76 confirm(dom.documentElement.childNodes[-1].data == "Hello")
Paul Prescod7993bcc2000-07-01 14:54:16 +000077 dom.unlink()
Paul Prescod7993bcc2000-07-01 14:54:16 +000078
79def testNonZero():
Jeremy Hylton3b0c6002000-10-12 17:31:36 +000080 dom = parse(tstfile)
81 confirm(dom)# should not be zero
82 dom.appendChild(dom.createComment("foo"))
83 confirm(not dom.childNodes[-1].childNodes)
Paul Prescod7993bcc2000-07-01 14:54:16 +000084 dom.unlink()
Paul Prescod7993bcc2000-07-01 14:54:16 +000085
86def testUnlink():
Jeremy Hylton3b0c6002000-10-12 17:31:36 +000087 dom = parse(tstfile)
Paul Prescod7993bcc2000-07-01 14:54:16 +000088 dom.unlink()
Paul Prescod7993bcc2000-07-01 14:54:16 +000089
90def testElement():
Jeremy Hylton3b0c6002000-10-12 17:31:36 +000091 dom = Document()
92 dom.appendChild(dom.createElement("abc"))
93 confirm(dom.documentElement)
Paul Prescod7993bcc2000-07-01 14:54:16 +000094 dom.unlink()
Paul Prescod7993bcc2000-07-01 14:54:16 +000095
96def testAAA():
Jeremy Hylton3b0c6002000-10-12 17:31:36 +000097 dom = parseString("<abc/>")
98 el = dom.documentElement
99 el.setAttribute("spam", "jam2")
Fred Drakea1bde802000-11-21 22:02:43 +0000100 confirm(el.toxml() == '<abc spam="jam2"/>', "testAAA")
Paul Prescod7993bcc2000-07-01 14:54:16 +0000101 dom.unlink()
Paul Prescod7993bcc2000-07-01 14:54:16 +0000102
103def testAAB():
Jeremy Hylton3b0c6002000-10-12 17:31:36 +0000104 dom = parseString("<abc/>")
105 el = dom.documentElement
106 el.setAttribute("spam", "jam")
107 el.setAttribute("spam", "jam2")
Fred Drakea1bde802000-11-21 22:02:43 +0000108 confirm(el.toxml() == '<abc spam="jam2"/>', "testAAB")
Paul Prescod7993bcc2000-07-01 14:54:16 +0000109 dom.unlink()
Paul Prescod7993bcc2000-07-01 14:54:16 +0000110
111def testAddAttr():
Jeremy Hylton3b0c6002000-10-12 17:31:36 +0000112 dom = Document()
113 child = dom.appendChild(dom.createElement("abc"))
Paul Prescod7993bcc2000-07-01 14:54:16 +0000114
Jeremy Hylton3b0c6002000-10-12 17:31:36 +0000115 child.setAttribute("def", "ghi")
116 confirm(child.getAttribute("def") == "ghi")
117 confirm(child.attributes["def"].value == "ghi")
Paul Prescod7993bcc2000-07-01 14:54:16 +0000118
Jeremy Hylton3b0c6002000-10-12 17:31:36 +0000119 child.setAttribute("jkl", "mno")
120 confirm(child.getAttribute("jkl") == "mno")
121 confirm(child.attributes["jkl"].value == "mno")
Paul Prescod7993bcc2000-07-01 14:54:16 +0000122
Jeremy Hylton3b0c6002000-10-12 17:31:36 +0000123 confirm(len(child.attributes) == 2)
Paul Prescod7993bcc2000-07-01 14:54:16 +0000124
Jeremy Hylton3b0c6002000-10-12 17:31:36 +0000125 child.setAttribute("def", "newval")
126 confirm(child.getAttribute("def") == "newval")
127 confirm(child.attributes["def"].value == "newval")
Paul Prescod7993bcc2000-07-01 14:54:16 +0000128
Jeremy Hylton3b0c6002000-10-12 17:31:36 +0000129 confirm(len(child.attributes) == 2)
Paul Prescod7993bcc2000-07-01 14:54:16 +0000130 dom.unlink()
Paul Prescod7993bcc2000-07-01 14:54:16 +0000131
132def testDeleteAttr():
Jeremy Hylton3b0c6002000-10-12 17:31:36 +0000133 dom = Document()
134 child = dom.appendChild(dom.createElement("abc"))
Paul Prescod7993bcc2000-07-01 14:54:16 +0000135
Jeremy Hylton3b0c6002000-10-12 17:31:36 +0000136 confirm(len(child.attributes) == 0)
137 child.setAttribute("def", "ghi")
138 confirm(len(child.attributes) == 1)
Paul Prescod7993bcc2000-07-01 14:54:16 +0000139 del child.attributes["def"]
Jeremy Hylton3b0c6002000-10-12 17:31:36 +0000140 confirm(len(child.attributes) == 0)
Paul Prescod7993bcc2000-07-01 14:54:16 +0000141 dom.unlink()
Paul Prescod7993bcc2000-07-01 14:54:16 +0000142
143def testRemoveAttr():
Jeremy Hylton3b0c6002000-10-12 17:31:36 +0000144 dom = Document()
145 child = dom.appendChild(dom.createElement("abc"))
Paul Prescod7993bcc2000-07-01 14:54:16 +0000146
Jeremy Hylton3b0c6002000-10-12 17:31:36 +0000147 child.setAttribute("def", "ghi")
148 confirm(len(child.attributes) == 1)
149 child.removeAttribute("def")
150 confirm(len(child.attributes) == 0)
Paul Prescod7993bcc2000-07-01 14:54:16 +0000151
152 dom.unlink()
153
154def testRemoveAttrNS():
Jeremy Hylton3b0c6002000-10-12 17:31:36 +0000155 dom = Document()
156 child = dom.appendChild(
157 dom.createElementNS("http://www.python.org", "python:abc"))
Fred Drake004d5e62000-10-23 17:22:08 +0000158 child.setAttributeNS("http://www.w3.org", "xmlns:python",
Jeremy Hylton3b0c6002000-10-12 17:31:36 +0000159 "http://www.python.org")
160 child.setAttributeNS("http://www.python.org", "python:abcattr", "foo")
161 confirm(len(child.attributes) == 2)
162 child.removeAttributeNS("http://www.python.org", "abcattr")
163 confirm(len(child.attributes) == 1)
Paul Prescod7993bcc2000-07-01 14:54:16 +0000164
165 dom.unlink()
Fred Drake004d5e62000-10-23 17:22:08 +0000166
Paul Prescod7993bcc2000-07-01 14:54:16 +0000167def testRemoveAttributeNode():
Jeremy Hylton3b0c6002000-10-12 17:31:36 +0000168 dom = Document()
169 child = dom.appendChild(dom.createElement("foo"))
170 child.setAttribute("spam", "jam")
171 confirm(len(child.attributes) == 1)
172 node = child.getAttributeNode("spam")
173 child.removeAttributeNode(node)
174 confirm(len(child.attributes) == 0)
Paul Prescod7993bcc2000-07-01 14:54:16 +0000175
176 dom.unlink()
Paul Prescod7993bcc2000-07-01 14:54:16 +0000177
178def testChangeAttr():
Jeremy Hylton3b0c6002000-10-12 17:31:36 +0000179 dom = parseString("<abc/>")
180 el = dom.documentElement
181 el.setAttribute("spam", "jam")
182 confirm(len(el.attributes) == 1)
183 el.setAttribute("spam", "bam")
184 confirm(len(el.attributes) == 1)
185 el.attributes["spam"] = "ham"
186 confirm(len(el.attributes) == 1)
187 el.setAttribute("spam2", "bam")
188 confirm(len(el.attributes) == 2)
189 el.attributes[ "spam2"] = "bam2"
190 confirm(len(el.attributes) == 2)
Paul Prescod7993bcc2000-07-01 14:54:16 +0000191 dom.unlink()
Paul Prescod7993bcc2000-07-01 14:54:16 +0000192
193def testGetAttrList():
194 pass
195
196def testGetAttrValues(): pass
197
198def testGetAttrLength(): pass
199
200def testGetAttribute(): pass
201
202def testGetAttributeNS(): pass
203
204def testGetAttributeNode(): pass
205
206def testGetElementsByTagNameNS(): pass
207
208def testGetEmptyNodeListFromElementsByTagNameNS(): pass
209
210def testElementReprAndStr():
Jeremy Hylton3b0c6002000-10-12 17:31:36 +0000211 dom = Document()
212 el = dom.appendChild(dom.createElement("abc"))
213 string1 = repr(el)
214 string2 = str(el)
215 confirm(string1 == string2)
Paul Prescod7993bcc2000-07-01 14:54:16 +0000216 dom.unlink()
217
218# commented out until Fredrick's fix is checked in
219def _testElementReprAndStrUnicode():
Jeremy Hylton3b0c6002000-10-12 17:31:36 +0000220 dom = Document()
221 el = dom.appendChild(dom.createElement(u"abc"))
222 string1 = repr(el)
223 string2 = str(el)
224 confirm(string1 == string2)
Paul Prescod7993bcc2000-07-01 14:54:16 +0000225 dom.unlink()
226
227# commented out until Fredrick's fix is checked in
228def _testElementReprAndStrUnicodeNS():
Jeremy Hylton3b0c6002000-10-12 17:31:36 +0000229 dom = Document()
230 el = dom.appendChild(
231 dom.createElementNS(u"http://www.slashdot.org", u"slash:abc"))
232 string1 = repr(el)
233 string2 = str(el)
234 confirm(string1 == string2)
235 confirm(string1.find("slash:abc") != -1)
Paul Prescod7993bcc2000-07-01 14:54:16 +0000236 dom.unlink()
Jeremy Hylton3b0c6002000-10-12 17:31:36 +0000237 confirm(len(Node.allnodes) == 0)
Paul Prescod7993bcc2000-07-01 14:54:16 +0000238
239def testAttributeRepr():
Jeremy Hylton3b0c6002000-10-12 17:31:36 +0000240 dom = Document()
241 el = dom.appendChild(dom.createElement(u"abc"))
242 node = el.setAttribute("abc", "def")
243 confirm(str(node) == repr(node))
Paul Prescod7993bcc2000-07-01 14:54:16 +0000244 dom.unlink()
Jeremy Hylton3b0c6002000-10-12 17:31:36 +0000245 confirm(len(Node.allnodes) == 0)
Paul Prescod7993bcc2000-07-01 14:54:16 +0000246
247def testTextNodeRepr(): pass
248
Martin v. Löwis0a84a332000-10-06 22:42:55 +0000249def testWriteXML():
250 str = '<a b="c"/>'
251 dom = parseString(str)
252 domstr = dom.toxml()
253 dom.unlink()
254 confirm(str == domstr)
Jeremy Hylton3b0c6002000-10-12 17:31:36 +0000255 confirm(len(Node.allnodes) == 0)
Paul Prescod7993bcc2000-07-01 14:54:16 +0000256
257def testProcessingInstruction(): pass
258
259def testProcessingInstructionRepr(): pass
260
261def testTextRepr(): pass
262
263def testWriteText(): pass
264
265def testDocumentElement(): pass
266
Fred Drakea1bde802000-11-21 22:02:43 +0000267def testTooManyDocumentElements():
268 doc = parseString("<doc/>")
269 elem = doc.createElement("extra")
270 try:
271 doc.appendChild(elem)
272 except TypeError:
273 print "Caught expected exception when adding extra document element."
274 else:
275 print "Failed to catch expected exception when" \
276 " adding extra document element."
277 elem.unlink()
278 doc.unlink()
Paul Prescod7993bcc2000-07-01 14:54:16 +0000279
280def testCreateElementNS(): pass
281
282def testCreatAttributeNS(): pass
283
284def testParse(): pass
285
286def testParseString(): pass
287
288def testComment(): pass
289
290def testAttrListItem(): pass
291
292def testAttrListItems(): pass
293
294def testAttrListItemNS(): pass
295
296def testAttrListKeys(): pass
297
298def testAttrListKeysNS(): pass
299
300def testAttrListValues(): pass
301
302def testAttrListLength(): pass
303
304def testAttrList__getitem__(): pass
305
306def testAttrList__setitem__(): pass
307
308def testSetAttrValueandNodeValue(): pass
309
310def testParseElement(): pass
311
312def testParseAttributes(): pass
313
314def testParseElementNamespaces(): pass
315
316def testParseAttributeNamespaces(): pass
317
318def testParseProcessingInstructions(): pass
319
320def testChildNodes(): pass
321
322def testFirstChild(): pass
323
324def testHasChildNodes(): pass
325
Fred Drakea1bde802000-11-21 22:02:43 +0000326def testCloneElementShallow():
327 dom, clone = _setupCloneElement(0)
328 confirm(len(clone.childNodes) == 0
329 and clone.parentNode is None
330 and clone.toxml() == '<doc attr="value"/>'
331 , "testCloneElementShallow")
332 dom.unlink()
Paul Prescod7993bcc2000-07-01 14:54:16 +0000333
Fred Drakea1bde802000-11-21 22:02:43 +0000334def testCloneElementDeep():
335 dom, clone = _setupCloneElement(1)
336 confirm(len(clone.childNodes) == 1
337 and clone.parentNode is None
338 and clone.toxml() == '<doc attr="value"><foo/></doc>'
339 , "testCloneElementDeep")
340 dom.unlink()
Paul Prescod7993bcc2000-07-01 14:54:16 +0000341
Fred Drakea1bde802000-11-21 22:02:43 +0000342def _setupCloneElement(deep):
343 dom = parseString("<doc attr='value'><foo/></doc>")
344 root = dom.documentElement
345 clone = root.cloneNode(deep)
346 _testCloneElementCopiesAttributes(
347 root, clone, "testCloneElement" + (deep and "Deep" or "Shallow"))
348 # mutilate the original so shared data is detected
349 root.tagName = root.nodeName = "MODIFIED"
350 root.setAttribute("attr", "NEW VALUE")
351 root.setAttribute("added", "VALUE")
352 return dom, clone
353
354def _testCloneElementCopiesAttributes(e1, e2, test):
355 attrs1 = e1.attributes
356 attrs2 = e2.attributes
357 keys1 = attrs1.keys()
358 keys2 = attrs2.keys()
359 keys1.sort()
360 keys2.sort()
361 confirm(keys1 == keys2, "clone of element has same attribute keys")
362 for i in range(len(keys1)):
363 a1 = attrs1.item(i)
364 a2 = attrs2.item(i)
365 confirm(a1 is not a2
366 and a1.value == a2.value
367 and a1.nodeValue == a2.nodeValue
368 and a1.namespaceURI == a2.namespaceURI
369 and a1.localName == a2.localName
370 , "clone of attribute node has proper attribute values")
371 confirm(a2.ownerElement is e2,
372 "clone of attribute node correctly owned")
373
Paul Prescod7993bcc2000-07-01 14:54:16 +0000374
375def testCloneDocumentShallow(): pass
376
377def testCloneDocumentDeep(): pass
378
379def testCloneAttributeShallow(): pass
380
381def testCloneAttributeDeep(): pass
382
383def testClonePIShallow(): pass
384
385def testClonePIDeep(): pass
386
Fred Drakea1bde802000-11-21 22:02:43 +0000387def testNormalize():
388 doc = parseString("<doc/>")
389 root = doc.documentElement
390 root.appendChild(doc.createTextNode("first"))
391 root.appendChild(doc.createTextNode("second"))
392 confirm(len(root.childNodes) == 2, "testNormalize -- preparation")
393 doc.normalize()
394 confirm(len(root.childNodes) == 1
395 and root.firstChild is root.lastChild
396 and root.firstChild.data == "firstsecond"
397 , "testNormalize -- result")
398 doc.unlink()
399
Lars Gustäbelf27f5ab2000-10-11 22:36:00 +0000400def testSiblings():
401 doc = parseString("<doc><?pi?>text?<elm/></doc>")
402 root = doc.documentElement
403 (pi, text, elm) = root.childNodes
Paul Prescod7993bcc2000-07-01 14:54:16 +0000404
Fred Drake004d5e62000-10-23 17:22:08 +0000405 confirm(pi.nextSibling is text and
406 pi.previousSibling is None and
407 text.nextSibling is elm and
408 text.previousSibling is pi and
409 elm.nextSibling is None and
Lars Gustäbelf27f5ab2000-10-11 22:36:00 +0000410 elm.previousSibling is text, "testSiblings")
411
412 doc.unlink()
413
414def testParents():
415 doc = parseString("<doc><elm1><elm2/><elm2><elm3/></elm2></elm1></doc>")
416 root = doc.documentElement
417 elm1 = root.childNodes[0]
418 (elm2a, elm2b) = elm1.childNodes
419 elm3 = elm2b.childNodes[0]
420
421 confirm(root.parentNode is doc and
422 elm1.parentNode is root and
423 elm2a.parentNode is elm1 and
424 elm2b.parentNode is elm1 and
425 elm3.parentNode is elm2b, "testParents")
426
427 doc.unlink()
428
Lars Gustäbel5bad5a42000-10-13 20:54:10 +0000429def testSAX2DOM():
Lars Gustäbelf27f5ab2000-10-11 22:36:00 +0000430 from xml.dom import pulldom
431
Lars Gustäbel5bad5a42000-10-13 20:54:10 +0000432 sax2dom = pulldom.SAX2DOM()
433 sax2dom.startDocument()
434 sax2dom.startElement("doc", {})
435 sax2dom.characters("text")
436 sax2dom.startElement("subelm", {})
437 sax2dom.characters("text")
438 sax2dom.endElement("subelm")
Fred Drake004d5e62000-10-23 17:22:08 +0000439 sax2dom.characters("text")
Lars Gustäbel5bad5a42000-10-13 20:54:10 +0000440 sax2dom.endElement("doc")
441 sax2dom.endDocument()
Lars Gustäbelf27f5ab2000-10-11 22:36:00 +0000442
Lars Gustäbel5bad5a42000-10-13 20:54:10 +0000443 doc = sax2dom.document
Lars Gustäbelf27f5ab2000-10-11 22:36:00 +0000444 root = doc.documentElement
445 (text1, elm1, text2) = root.childNodes
446 text3 = elm1.childNodes[0]
447
448 confirm(text1.previousSibling is None and
449 text1.nextSibling is elm1 and
450 elm1.previousSibling is text1 and
451 elm1.nextSibling is text2 and
452 text2.previousSibling is elm1 and
453 text2.nextSibling is None and
454 text3.previousSibling is None and
Lars Gustäbel5bad5a42000-10-13 20:54:10 +0000455 text3.nextSibling is None, "testSAX2DOM - siblings")
Lars Gustäbelf27f5ab2000-10-11 22:36:00 +0000456
457 confirm(root.parentNode is doc and
458 text1.parentNode is root and
459 elm1.parentNode is root and
460 text2.parentNode is root and
Lars Gustäbel5bad5a42000-10-13 20:54:10 +0000461 text3.parentNode is elm1, "testSAX2DOM - parents")
Fred Drake004d5e62000-10-23 17:22:08 +0000462
Lars Gustäbelf27f5ab2000-10-11 22:36:00 +0000463 doc.unlink()
464
465# --- MAIN PROGRAM
Fred Drake004d5e62000-10-23 17:22:08 +0000466
Jeremy Hylton3b0c6002000-10-12 17:31:36 +0000467names = globals().keys()
Paul Prescod7993bcc2000-07-01 14:54:16 +0000468names.sort()
Paul Prescod10d27662000-09-18 19:07:26 +0000469
Jeremy Hylton3b0c6002000-10-12 17:31:36 +0000470works = 1
Paul Prescod10d27662000-09-18 19:07:26 +0000471
Paul Prescod7993bcc2000-07-01 14:54:16 +0000472for name in names:
Jeremy Hylton3b0c6002000-10-12 17:31:36 +0000473 if name.startswith("test"):
474 func = globals()[name]
Paul Prescod7993bcc2000-07-01 14:54:16 +0000475 try:
476 func()
477 print "Test Succeeded", name
Fred Drakeebe73022000-10-09 19:57:39 +0000478 confirm(len(Node.allnodes) == 0,
479 "assertion: len(Node.allnodes) == 0")
Jeremy Hylton3b0c6002000-10-12 17:31:36 +0000480 if len(Node.allnodes):
Paul Prescod7993bcc2000-07-01 14:54:16 +0000481 print "Garbage left over:"
Martin v. Löwis89c528b2000-09-19 16:22:10 +0000482 if verbose:
483 print Node.allnodes.items()[0:10]
484 else:
485 # Don't print specific nodes if repeatable results
486 # are needed
487 print len(Node.allnodes)
Jeremy Hylton3b0c6002000-10-12 17:31:36 +0000488 Node.allnodes = {}
489 except Exception, e:
490 works = 0
Paul Prescod7993bcc2000-07-01 14:54:16 +0000491 print "Test Failed: ", name
Jeremy Hylton3b0c6002000-10-12 17:31:36 +0000492 traceback.print_exception(*sys.exc_info())
Paul Prescod7993bcc2000-07-01 14:54:16 +0000493 print `e`
Jeremy Hylton3b0c6002000-10-12 17:31:36 +0000494 Node.allnodes = {}
Paul Prescod10d27662000-09-18 19:07:26 +0000495
496if works:
497 print "All tests succeeded"
498else:
499 print "\n\n\n\n************ Check for failures!"
Paul Prescod7993bcc2000-07-01 14:54:16 +0000500
Guido van Rossum9e79a252000-09-21 20:10:39 +0000501Node.debug = None # Delete debug output collected in a StringIO object
502Node._debug = 0 # And reset debug mode