Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-63882: Break downand tests intest_minidom#133026

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
hugovk merged 1 commit intopython:mainfromStanFromIreland:minidom-750-up
May 5, 2025
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
182 changes: 88 additions & 94 deletionsLib/test/test_minidom.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -102,41 +102,38 @@ def testInsertBefore(self):
elem = root.childNodes[0]
nelem = dom.createElement("element")
root.insertBefore(nelem, elem)
self.confirm(len(root.childNodes) == 2
and root.childNodes.length == 2
and root.childNodes[0] is nelem
and root.childNodes.item(0) is nelem
and root.childNodes[1] is elem
and root.childNodes.item(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")
self.assertEqual(len(root.childNodes), 2)
self.assertEqual(root.childNodes.length, 2)
self.assertIs(root.childNodes[0], nelem)
self.assertIs(root.childNodes.item(0), nelem)
self.assertIs(root.childNodes[1], elem)
self.assertIs(root.childNodes.item(1), elem)
self.assertIs(root.firstChild, nelem)
self.assertIs(root.lastChild, elem)
self.assertEqual(root.toxml(), "<doc><element/><foo/></doc>")
nelem = dom.createElement("element")
root.insertBefore(nelem, None)
self.confirm(len(root.childNodes) == 3
and root.childNodes.length == 3
and root.childNodes[1] is elem
and root.childNodes.item(1) is elem
and root.childNodes[2] is nelem
and root.childNodes.item(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")
self.assertEqual(len(root.childNodes), 3)
self.assertEqual(root.childNodes.length, 3)
self.assertIs(root.childNodes[1], elem)
self.assertIs(root.childNodes.item(1), elem)
self.assertIs(root.childNodes[2], nelem)
self.assertIs(root.childNodes.item(2), nelem)
self.assertIs(root.lastChild, nelem)
self.assertIs(nelem.previousSibling, elem)
self.assertEqual(root.toxml(), "<doc><element/><foo/><element/></doc>")
nelem2 = dom.createElement("bar")
root.insertBefore(nelem2, nelem)
self.confirm(len(root.childNodes) == 4
and root.childNodes.length == 4
and root.childNodes[2] is nelem2
and root.childNodes.item(2) is nelem2
and root.childNodes[3] is nelem
and root.childNodes.item(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")
self.assertEqual(len(root.childNodes), 4)
self.assertEqual(root.childNodes.length, 4)
self.assertIs(root.childNodes[2], nelem2)
self.assertIs(root.childNodes.item(2), nelem2)
self.assertIs(root.childNodes[3], nelem)
self.assertIs(root.childNodes.item(3), nelem)
self.assertIs(nelem2.nextSibling, nelem)
self.assertIs(nelem.previousSibling, nelem2)
self.assertEqual(root.toxml(),
"<doc><element/><foo/><bar/><element/></doc>")
dom.unlink()

def _create_fragment_test_nodes(self):
Expand DownExpand Up@@ -342,8 +339,8 @@ def testRemoveAttributeNode(self):
self.assertRaises(xml.dom.NotFoundErr, child.removeAttributeNode,
None)
self.assertIs(node, child.removeAttributeNode(node))
self.confirm(len(child.attributes) == 0
andchild.getAttributeNode("spam") is None)
self.assertEqual(len(child.attributes), 0)
self.assertIsNone(child.getAttributeNode("spam"))
dom2 = Document()
child2 = dom2.appendChild(dom2.createElement("foo"))
node2 = child2.getAttributeNode("spam")
Expand All@@ -366,33 +363,34 @@ def testChangeAttr(self):
# Set this attribute to be an ID and make sure that doesn't change
# when changing the value:
el.setIdAttribute("spam")
self.confirm(len(el.attributes) == 1
andel.attributes["spam"].value =="bam"
andel.attributes["spam"].nodeValue =="bam"
andel.getAttribute("spam") =="bam"
andel.getAttributeNode("spam").isId)
self.assertEqual(len(el.attributes), 1)
self.assertEqual(el.attributes["spam"].value,"bam")
self.assertEqual(el.attributes["spam"].nodeValue,"bam")
self.assertEqual(el.getAttribute("spam"),"bam")
self.assertTrue(el.getAttributeNode("spam").isId)
el.attributes["spam"] = "ham"
self.confirm(len(el.attributes) == 1
andel.attributes["spam"].value =="ham"
andel.attributes["spam"].nodeValue =="ham"
andel.getAttribute("spam") =="ham"
andel.attributes["spam"].isId)
self.assertEqual(len(el.attributes), 1)
self.assertEqual(el.attributes["spam"].value,"ham")
self.assertEqual(el.attributes["spam"].nodeValue,"ham")
self.assertEqual(el.getAttribute("spam"),"ham")
self.assertTrue(el.attributes["spam"].isId)
el.setAttribute("spam2", "bam")
self.confirm(len(el.attributes) == 2
andel.attributes["spam"].value =="ham"
andel.attributes["spam"].nodeValue =="ham"
andel.getAttribute("spam") =="ham"
andel.attributes["spam2"].value =="bam"
andel.attributes["spam2"].nodeValue =="bam"
andel.getAttribute("spam2") == "bam")
self.assertEqual(len(el.attributes), 2)
self.assertEqual(el.attributes["spam"].value,"ham")
self.assertEqual(el.attributes["spam"].nodeValue,"ham")
self.assertEqual(el.getAttribute("spam"),"ham")
self.assertEqual(el.attributes["spam2"].value,"bam")
self.assertEqual(el.attributes["spam2"].nodeValue,"bam")
self.assertEqual(el.getAttribute("spam2"), "bam")
el.attributes["spam2"] = "bam2"
self.confirm(len(el.attributes) == 2
and el.attributes["spam"].value == "ham"
and el.attributes["spam"].nodeValue == "ham"
and el.getAttribute("spam") == "ham"
and el.attributes["spam2"].value == "bam2"
and el.attributes["spam2"].nodeValue == "bam2"
and el.getAttribute("spam2") == "bam2")

self.assertEqual(len(el.attributes), 2)
self.assertEqual(el.attributes["spam"].value, "ham")
self.assertEqual(el.attributes["spam"].nodeValue, "ham")
self.assertEqual(el.getAttribute("spam"), "ham")
self.assertEqual(el.attributes["spam2"].value, "bam2")
self.assertEqual(el.attributes["spam2"].nodeValue, "bam2")
self.assertEqual(el.getAttribute("spam2"), "bam2")
dom.unlink()

def testGetAttrList(self):
Expand DownExpand Up@@ -433,12 +431,12 @@ def testGetElementsByTagNameNS(self):
dom = parseString(d)
elems = dom.getElementsByTagNameNS("http://pyxml.sf.net/minidom",
"myelem")
self.confirm(len(elems) == 1
andelems[0].namespaceURI =="http://pyxml.sf.net/minidom"
andelems[0].localName =="myelem"
andelems[0].prefix =="minidom"
andelems[0].tagName =="minidom:myelem"
andelems[0].nodeName == "minidom:myelem")
self.assertEqual(len(elems), 1)
self.assertEqual(elems[0].namespaceURI,"http://pyxml.sf.net/minidom")
self.assertEqual(elems[0].localName,"myelem")
self.assertEqual(elems[0].prefix,"minidom")
self.assertEqual(elems[0].tagName,"minidom:myelem")
self.assertEqual(elems[0].nodeName, "minidom:myelem")
dom.unlink()

def get_empty_nodelist_from_elements_by_tagName_ns_helper(self, doc, nsuri,
Expand DownExpand Up@@ -589,17 +587,17 @@ def test_toprettyxml_preserves_content_of_text_node(self):
def testProcessingInstruction(self):
dom = parseString('<e><?mypi \t\n data \t\n ?></e>')
pi = dom.documentElement.firstChild
self.confirm(pi.target =="mypi"
andpi.data =="data \t\n "
andpi.nodeName =="mypi"
andpi.nodeType ==Node.PROCESSING_INSTRUCTION_NODE
andpi.attributes is None
and notpi.hasChildNodes()
andlen(pi.childNodes) == 0
andpi.firstChild is None
andpi.lastChild is None
andpi.localName is None
andpi.namespaceURI == xml.dom.EMPTY_NAMESPACE)
self.assertEqual(pi.target,"mypi")
self.assertEqual(pi.data,"data \t\n ")
self.assertEqual(pi.nodeName,"mypi")
self.assertEqual(pi.nodeType,Node.PROCESSING_INSTRUCTION_NODE)
self.assertIsNone(pi.attributes)
self.assertFalse(pi.hasChildNodes())
self.assertEqual(len(pi.childNodes), 0)
self.assertIsNone(pi.firstChild)
self.assertIsNone(pi.lastChild)
self.assertIsNone(pi.localName)
self.assertEqual(pi.namespaceURI, xml.dom.EMPTY_NAMESPACE)

def testProcessingInstructionRepr(self): pass

Expand DownExpand Up@@ -695,19 +693,16 @@ def _testCloneElementCopiesAttributes(self, e1, e2, test):
keys2 = list(attrs2.keys())
keys1.sort()
keys2.sort()
self.assertEqual(keys1, keys2,
"clone of element has same attribute keys")
self.assertEqual(keys1, keys2)
for i in range(len(keys1)):
a1 = attrs1.item(i)
a2 = attrs2.item(i)
self.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")
self.assertIs(a2.ownerElement, e2,
"clone of attribute node correctly owned")
self.assertIsNot(a1, a2)
self.assertEqual(a1.value, a2.value)
self.assertEqual(a1.nodeValue, a2.nodeValue)
self.assertEqual(a1.namespaceURI,a2.namespaceURI)
self.assertEqual(a1.localName, a2.localName)
self.assertIs(a2.ownerElement, e2)

def _setupCloneElement(self, deep):
dom = parseString("<doc attr='value'><foo/></doc>")
Expand All@@ -723,20 +718,19 @@ def _setupCloneElement(self, deep):

def testCloneElementShallow(self):
dom, clone = self._setupCloneElement(0)
self.confirm(len(clone.childNodes) == 0
andclone.childNodes.length == 0
andclone.parentNode is None
andclone.toxml() =='<doc attr="value"/>'
, "testCloneElementShallow")
self.assertEqual(len(clone.childNodes), 0)
self.assertEqual(clone.childNodes.length, 0)
self.assertIsNone(clone.parentNode)
self.assertEqual(clone.toxml(),'<doc attr="value"/>')

dom.unlink()

def testCloneElementDeep(self):
dom, clone = self._setupCloneElement(1)
self.confirm(len(clone.childNodes) == 1
and clone.childNodes.length == 1
and clone.parentNode is None
and clone.toxml() == '<doc attr="value"><foo/></doc>'
, "testCloneElementDeep")
self.assertEqual(len(clone.childNodes), 1)
self.assertEqual(clone.childNodes.length, 1)
self.assertIsNone(clone.parentNode)
self.assertTrue(clone.toxml(), '<doc attr="value"><foo/></doc>')
dom.unlink()

def testCloneDocumentShallow(self):
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp