summaryrefslogtreecommitdiff
path: root/Lib/test/test_minidom.py
diff options
context:
space:
mode:
authorR. David Murray <rdmurray@bitdance.com>2009-04-09 22:16:43 +0000
committerR. David Murray <rdmurray@bitdance.com>2009-04-09 22:16:43 +0000
commitdc6da8abda6e9faeb34b53520563eed21d42e7e5 (patch)
treed838c98db711d189ccbbe10cdcf38ab8db059541 /Lib/test/test_minidom.py
parenta6191803545927421de2d5a7d9b7a7a1034a363c (diff)
downloadcpython-git-dc6da8abda6e9faeb34b53520563eed21d42e7e5.tar.gz
Merged revisions 71414 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r71414 | r.david.murray | 2009-04-09 17:54:50 -0400 (Thu, 09 Apr 2009) | 3 lines Issue #2170: refactored xml.dom.minidom.normalize, increasing both its clarity and its speed. ........
Diffstat (limited to 'Lib/test/test_minidom.py')
-rw-r--r--Lib/test/test_minidom.py161
1 files changed, 161 insertions, 0 deletions
diff --git a/Lib/test/test_minidom.py b/Lib/test/test_minidom.py
index 59dca5069b..76b7354ed4 100644
--- a/Lib/test/test_minidom.py
+++ b/Lib/test/test_minidom.py
@@ -789,6 +789,167 @@ class MinidomTest(unittest.TestCase):
"testNormalize -- single empty node removed")
doc.unlink()
+ def testNormalizeCombineAndNextSibling(self):
+ doc = parseString("<doc/>")
+ root = doc.documentElement
+ root.appendChild(doc.createTextNode("first"))
+ root.appendChild(doc.createTextNode("second"))
+ root.appendChild(doc.createElement("i"))
+ self.confirm(len(root.childNodes) == 3
+ and root.childNodes.length == 3,
+ "testNormalizeCombineAndNextSibling -- preparation")
+ doc.normalize()
+ self.confirm(len(root.childNodes) == 2
+ and root.childNodes.length == 2
+ and root.firstChild.data == "firstsecond"
+ and root.firstChild is not root.lastChild
+ and root.firstChild.nextSibling is root.lastChild
+ and root.firstChild.previousSibling is None
+ and root.lastChild.previousSibling is root.firstChild
+ and root.lastChild.nextSibling is None
+ , "testNormalizeCombinedAndNextSibling -- result")
+ doc.unlink()
+
+ def testNormalizeDeleteWithPrevSibling(self):
+ doc = parseString("<doc/>")
+ root = doc.documentElement
+ root.appendChild(doc.createTextNode("first"))
+ root.appendChild(doc.createTextNode(""))
+ self.confirm(len(root.childNodes) == 2
+ and root.childNodes.length == 2,
+ "testNormalizeDeleteWithPrevSibling -- preparation")
+ doc.normalize()
+ self.confirm(len(root.childNodes) == 1
+ and root.childNodes.length == 1
+ and root.firstChild.data == "first"
+ and root.firstChild is root.lastChild
+ and root.firstChild.nextSibling is None
+ and root.firstChild.previousSibling is None
+ , "testNormalizeDeleteWithPrevSibling -- result")
+ doc.unlink()
+
+ def testNormalizeDeleteWithNextSibling(self):
+ doc = parseString("<doc/>")
+ root = doc.documentElement
+ root.appendChild(doc.createTextNode(""))
+ root.appendChild(doc.createTextNode("second"))
+ self.confirm(len(root.childNodes) == 2
+ and root.childNodes.length == 2,
+ "testNormalizeDeleteWithNextSibling -- preparation")
+ doc.normalize()
+ self.confirm(len(root.childNodes) == 1
+ and root.childNodes.length == 1
+ and root.firstChild.data == "second"
+ and root.firstChild is root.lastChild
+ and root.firstChild.nextSibling is None
+ and root.firstChild.previousSibling is None
+ , "testNormalizeDeleteWithNextSibling -- result")
+ doc.unlink()
+
+ def testNormalizeDeleteWithTwoNonTextSiblings(self):
+ doc = parseString("<doc/>")
+ root = doc.documentElement
+ root.appendChild(doc.createElement("i"))
+ root.appendChild(doc.createTextNode(""))
+ root.appendChild(doc.createElement("i"))
+ self.confirm(len(root.childNodes) == 3
+ and root.childNodes.length == 3,
+ "testNormalizeDeleteWithTwoSiblings -- preparation")
+ doc.normalize()
+ self.confirm(len(root.childNodes) == 2
+ and root.childNodes.length == 2
+ and root.firstChild is not root.lastChild
+ and root.firstChild.nextSibling is root.lastChild
+ and root.firstChild.previousSibling is None
+ and root.lastChild.previousSibling is root.firstChild
+ and root.lastChild.nextSibling is None
+ , "testNormalizeDeleteWithTwoSiblings -- result")
+ doc.unlink()
+
+ def testNormalizeDeleteAndCombine(self):
+ doc = parseString("<doc/>")
+ root = doc.documentElement
+ root.appendChild(doc.createTextNode(""))
+ root.appendChild(doc.createTextNode("second"))
+ root.appendChild(doc.createTextNode(""))
+ root.appendChild(doc.createTextNode("fourth"))
+ root.appendChild(doc.createTextNode(""))
+ self.confirm(len(root.childNodes) == 5
+ and root.childNodes.length == 5,
+ "testNormalizeDeleteAndCombine -- preparation")
+ doc.normalize()
+ self.confirm(len(root.childNodes) == 1
+ and root.childNodes.length == 1
+ and root.firstChild is root.lastChild
+ and root.firstChild.data == "secondfourth"
+ and root.firstChild.previousSibling is None
+ and root.firstChild.nextSibling is None
+ , "testNormalizeDeleteAndCombine -- result")
+ doc.unlink()
+
+ def testNormalizeRecursion(self):
+ doc = parseString("<doc>"
+ "<o>"
+ "<i/>"
+ "t"
+ #
+ #x
+ "</o>"
+ "<o>"
+ "<o>"
+ "t2"
+ #x2
+ "</o>"
+ "t3"
+ #x3
+ "</o>"
+ #
+ "</doc>")
+ root = doc.documentElement
+ root.childNodes[0].appendChild(doc.createTextNode(""))
+ root.childNodes[0].appendChild(doc.createTextNode("x"))
+ root.childNodes[1].childNodes[0].appendChild(doc.createTextNode("x2"))
+ root.childNodes[1].appendChild(doc.createTextNode("x3"))
+ root.appendChild(doc.createTextNode(""))
+ self.confirm(len(root.childNodes) == 3
+ and root.childNodes.length == 3
+ and len(root.childNodes[0].childNodes) == 4
+ and root.childNodes[0].childNodes.length == 4
+ and len(root.childNodes[1].childNodes) == 3
+ and root.childNodes[1].childNodes.length == 3
+ and len(root.childNodes[1].childNodes[0].childNodes) == 2
+ and root.childNodes[1].childNodes[0].childNodes.length == 2
+ , "testNormalize2 -- preparation")
+ doc.normalize()
+ self.confirm(len(root.childNodes) == 2
+ and root.childNodes.length == 2
+ and len(root.childNodes[0].childNodes) == 2
+ and root.childNodes[0].childNodes.length == 2
+ and len(root.childNodes[1].childNodes) == 2
+ and root.childNodes[1].childNodes.length == 2
+ and len(root.childNodes[1].childNodes[0].childNodes) == 1
+ and root.childNodes[1].childNodes[0].childNodes.length == 1
+ , "testNormalize2 -- childNodes lengths")
+ self.confirm(root.childNodes[0].childNodes[1].data == "tx"
+ and root.childNodes[1].childNodes[0].childNodes[0].data == "t2x2"
+ and root.childNodes[1].childNodes[1].data == "t3x3"
+ , "testNormalize2 -- joined text fields")
+ self.confirm(root.childNodes[0].childNodes[1].nextSibling is None
+ and root.childNodes[0].childNodes[1].previousSibling
+ is root.childNodes[0].childNodes[0]
+ and root.childNodes[0].childNodes[0].previousSibling is None
+ and root.childNodes[0].childNodes[0].nextSibling
+ is root.childNodes[0].childNodes[1]
+ and root.childNodes[1].childNodes[1].nextSibling is None
+ and root.childNodes[1].childNodes[1].previousSibling
+ is root.childNodes[1].childNodes[0]
+ and root.childNodes[1].childNodes[0].previousSibling is None
+ and root.childNodes[1].childNodes[0].nextSibling
+ is root.childNodes[1].childNodes[1]
+ , "testNormalize2 -- sibling pointers")
+ doc.unlink()
+
+
def testBug1433694(self):
doc = parseString("<o><i/>t</o>")
node = doc.documentElement