[Python-checkins] CVS: python/dist/src/Lib/test test_minidom.py,1.14,1.15
Fred L. Drake
python-dev@python.org
Tue, 21 Nov 2000 14:02:46 -0800
Update of /cvsroot/python/python/dist/src/Lib/test
In directory slayer.i.sourceforge.net:/tmp/cvs-serv16231/Lib/test
Modified Files:
test_minidom.py
Log Message:
testInsertBefore(): Rewritten to actually test insertBefore() somewhat.
testAAA(),
testAAB(): Added checks that the results are right.
testTooManyDocumentElements(): Added code to actually test this.
testCloneElementDeep()
testCloneElementShallow(): Filled these in with test code.
_testCloneElementCopiesAttributes(),
_setupCloneElement(): Helper functions used with the other
testCloneElement*() functions.
testCloneElementShallowCopiesAttributes(): No longer a separate test;
_setupCloneElement() uses _testCloneElementCopiesAttributes() to
test that this is always done.
testNormalize(): Added to check Node.normalize().
Index: test_minidom.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_minidom.py,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -r1.14 -r1.15
*** test_minidom.py 2000/10/23 17:22:07 1.14
--- test_minidom.py 2000/11/21 22:02:43 1.15
***************
*** 38,51 ****
def testInsertBefore():
! dom = parse(tstfile)
! docel = dom.documentElement
! #docel.insertBefore( dom.createProcessingInstruction("a", "b"),
! # docel.childNodes[1])
!
! #docel.insertBefore( dom.createProcessingInstruction("a", "b"),
! # docel.childNodes[0])
!
! #confirm( docel.childNodes[0].tet == "a")
! #confirm( docel.childNodes[2].tet == "a")
dom.unlink()
--- 38,71 ----
def testInsertBefore():
! dom = parseString("<doc><foo/></doc>")
! root = dom.documentElement
! elem = root.childNodes[0]
! nelem = dom.createElement("element")
! root.insertBefore(nelem, elem)
! confirm(len(root.childNodes) == 2
! and root.childNodes[0] is nelem
! and root.childNodes[1] is elem
! and root.firstChild is nelem
! and root.lastChild is elem
! and root.toxml() == "<doc><element/><foo/></doc>"
! , "testInsertBefore -- node properly placed in tree")
! nelem = dom.createElement("element")
! root.insertBefore(nelem, None)
! confirm(len(root.childNodes) == 3
! and root.childNodes[1] is elem
! and root.childNodes[2] is nelem
! and root.lastChild is nelem
! and nelem.previousSibling is elem
! and root.toxml() == "<doc><element/><foo/><element/></doc>"
! , "testInsertBefore -- node properly placed in tree")
! nelem2 = dom.createElement("bar")
! root.insertBefore(nelem2, nelem)
! confirm(len(root.childNodes) == 4
! and root.childNodes[2] is nelem2
! and root.childNodes[3] is nelem
! and nelem2.nextSibling is nelem
! and nelem.previousSibling is nelem2
! and root.toxml() == "<doc><element/><foo/><bar/><element/></doc>"
! , "testInsertBefore -- node properly placed in tree")
dom.unlink()
***************
*** 78,81 ****
--- 98,102 ----
el = dom.documentElement
el.setAttribute("spam", "jam2")
+ confirm(el.toxml() == '<abc spam="jam2"/>', "testAAA")
dom.unlink()
***************
*** 85,88 ****
--- 106,110 ----
el.setAttribute("spam", "jam")
el.setAttribute("spam", "jam2")
+ confirm(el.toxml() == '<abc spam="jam2"/>', "testAAB")
dom.unlink()
***************
*** 243,247 ****
def testDocumentElement(): pass
! def testTooManyDocumentElements(): pass
def testCreateElementNS(): pass
--- 265,280 ----
def testDocumentElement(): pass
! def testTooManyDocumentElements():
! doc = parseString("<doc/>")
! elem = doc.createElement("extra")
! try:
! doc.appendChild(elem)
! except TypeError:
! print "Caught expected exception when adding extra document element."
! else:
! print "Failed to catch expected exception when" \
! " adding extra document element."
! elem.unlink()
! doc.unlink()
def testCreateElementNS(): pass
***************
*** 291,300 ****
def testHasChildNodes(): pass
! def testCloneElementShallow(): pass
- def testCloneElementShallowCopiesAttributes(): pass
-
- def testCloneElementDeep(): pass
-
def testCloneDocumentShallow(): pass
--- 324,376 ----
def testHasChildNodes(): pass
! def testCloneElementShallow():
! dom, clone = _setupCloneElement(0)
! confirm(len(clone.childNodes) == 0
! and clone.parentNode is None
! and clone.toxml() == '<doc attr="value"/>'
! , "testCloneElementShallow")
! dom.unlink()
!
! def testCloneElementDeep():
! dom, clone = _setupCloneElement(1)
! confirm(len(clone.childNodes) == 1
! and clone.parentNode is None
! and clone.toxml() == '<doc attr="value"><foo/></doc>'
! , "testCloneElementDeep")
! dom.unlink()
!
! def _setupCloneElement(deep):
! dom = parseString("<doc attr='value'><foo/></doc>")
! root = dom.documentElement
! clone = root.cloneNode(deep)
! _testCloneElementCopiesAttributes(
! root, clone, "testCloneElement" + (deep and "Deep" or "Shallow"))
! # mutilate the original so shared data is detected
! root.tagName = root.nodeName = "MODIFIED"
! root.setAttribute("attr", "NEW VALUE")
! root.setAttribute("added", "VALUE")
! return dom, clone
!
! def _testCloneElementCopiesAttributes(e1, e2, test):
! attrs1 = e1.attributes
! attrs2 = e2.attributes
! keys1 = attrs1.keys()
! keys2 = attrs2.keys()
! keys1.sort()
! keys2.sort()
! confirm(keys1 == keys2, "clone of element has same attribute keys")
! for i in range(len(keys1)):
! a1 = attrs1.item(i)
! a2 = attrs2.item(i)
! confirm(a1 is not a2
! and a1.value == a2.value
! and a1.nodeValue == a2.nodeValue
! and a1.namespaceURI == a2.namespaceURI
! and a1.localName == a2.localName
! , "clone of attribute node has proper attribute values")
! confirm(a2.ownerElement is e2,
! "clone of attribute node correctly owned")
!
def testCloneDocumentShallow(): pass
***************
*** 308,311 ****
--- 384,400 ----
def testClonePIDeep(): pass
+
+ def testNormalize():
+ doc = parseString("<doc/>")
+ root = doc.documentElement
+ root.appendChild(doc.createTextNode("first"))
+ root.appendChild(doc.createTextNode("second"))
+ confirm(len(root.childNodes) == 2, "testNormalize -- preparation")
+ doc.normalize()
+ confirm(len(root.childNodes) == 1
+ and root.firstChild is root.lastChild
+ and root.firstChild.data == "firstsecond"
+ , "testNormalize -- result")
+ doc.unlink()
def testSiblings():