From 0b49e9df74bbc7358a40f329ce65845e557146d2 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Sat, 26 Apr 2025 12:42:31 +0100 Subject: [PATCH 1/6] Use self.assert* --- Lib/test/test_minidom.py | 200 +++++++++++++++++++-------------------- 1 file changed, 100 insertions(+), 100 deletions(-) diff --git a/Lib/test/test_minidom.py b/Lib/test/test_minidom.py index 3ecd1af31eea77..ebe7315f0cbf52 100644 --- a/Lib/test/test_minidom.py +++ b/Lib/test/test_minidom.py @@ -57,7 +57,7 @@ def confirm(self, test, testname = "Test"): def checkWholeText(self, node, s): t = node.wholeText - self.confirm(t == s, "looking for %r, found %r" % (s, t)) + self.assertEqual(t, s, "looking for %r, found %r" % (s, t)) def testDocumentAsyncAttr(self): doc = Document() @@ -68,13 +68,13 @@ def testParseFromBinaryFile(self): with open(tstfile, 'rb') as file: dom = parse(file) dom.unlink() - self.confirm(isinstance(dom, Document)) + self.assertIsInstance(dom, Document) def testParseFromTextFile(self): with open(tstfile, 'r', encoding='iso-8859-1') as file: dom = parse(file) dom.unlink() - self.confirm(isinstance(dom, Document)) + self.assertIsInstance(dom, Document) def testAttrModeSetsParamsAsAttrs(self): attr = Attr("qName", "namespaceURI", "localName", "prefix") @@ -92,7 +92,7 @@ def testAttrModeSetsNonOptionalAttrs(self): def testGetElementsByTagName(self): dom = parse(tstfile) - self.confirm(dom.getElementsByTagName("LI") == \ + self.assertEqual(dom.getElementsByTagName("LI"), dom.documentElement.getElementsByTagName("LI")) dom.unlink() @@ -102,32 +102,32 @@ 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 + 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() == "" + and root.toxml(), "" , "testInsertBefore -- node properly placed in tree") nelem = dom.createElement("element") root.insertBefore(nelem, None) - self.confirm(len(root.childNodes) == 3 - and root.childNodes.length == 3 + 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() == "" + and root.toxml(), "" , "testInsertBefore -- node properly placed in tree") nelem2 = dom.createElement("bar") root.insertBefore(nelem2, nelem) - self.confirm(len(root.childNodes) == 4 - and root.childNodes.length == 4 + 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 @@ -155,7 +155,7 @@ def _create_fragment_test_nodes(self): def testInsertBeforeFragment(self): dom, orig, c1, c2, c3, frag = self._create_fragment_test_nodes() dom.documentElement.insertBefore(frag, None) - self.confirm(tuple(dom.documentElement.childNodes) == + self.assertEqual(tuple(dom.documentElement.childNodes), (orig, c1, c2, c3), "insertBefore(, None)") frag.unlink() @@ -163,7 +163,7 @@ def testInsertBeforeFragment(self): dom, orig, c1, c2, c3, frag = self._create_fragment_test_nodes() dom.documentElement.insertBefore(frag, orig) - self.confirm(tuple(dom.documentElement.childNodes) == + self.assertEqual(tuple(dom.documentElement.childNodes), (c1, c2, c3, orig), "insertBefore(, orig)") frag.unlink() @@ -172,14 +172,14 @@ def testInsertBeforeFragment(self): def testAppendChild(self): dom = parse(tstfile) dom.documentElement.appendChild(dom.createComment("Hello")) - self.confirm(dom.documentElement.childNodes[-1].nodeName == "#comment") - self.confirm(dom.documentElement.childNodes[-1].data == "Hello") + self.assertEqual(dom.documentElement.childNodes[-1].nodeName, "#comment") + self.assertEqual(dom.documentElement.childNodes[-1].data, "Hello") dom.unlink() def testAppendChildFragment(self): dom, orig, c1, c2, c3, frag = self._create_fragment_test_nodes() dom.documentElement.appendChild(frag) - self.confirm(tuple(dom.documentElement.childNodes) == + self.assertEqual(tuple(dom.documentElement.childNodes), (orig, c1, c2, c3), "appendChild()") frag.unlink() @@ -189,7 +189,7 @@ def testReplaceChildFragment(self): dom, orig, c1, c2, c3, frag = self._create_fragment_test_nodes() dom.documentElement.replaceChild(frag, orig) orig.unlink() - self.confirm(tuple(dom.documentElement.childNodes) == (c1, c2, c3), + self.assertEqual(tuple(dom.documentElement.childNodes), (c1, c2, c3), "replaceChild()") frag.unlink() dom.unlink() @@ -221,22 +221,22 @@ def testNamedNodeMapSetItem(self): attrs = elem.attributes attrs["foo"] = "bar" a = attrs.item(0) - self.confirm(a.ownerDocument is dom, + self.assertTrue(a.ownerDocument is dom, "NamedNodeMap.__setitem__() sets ownerDocument") - self.confirm(a.ownerElement is elem, + self.assertTrue(a.ownerElement is elem, "NamedNodeMap.__setitem__() sets ownerElement") - self.confirm(a.value == "bar", + self.assertEqual(a.value, "bar", "NamedNodeMap.__setitem__() sets value") - self.confirm(a.nodeValue == "bar", + self.assertEqual(a.nodeValue, "bar", "NamedNodeMap.__setitem__() sets nodeValue") elem.unlink() dom.unlink() def testNonZero(self): dom = parse(tstfile) - self.confirm(dom)# should not be zero + self.assertTrue(dom)# should not be zero dom.appendChild(dom.createComment("foo")) - self.confirm(not dom.childNodes[-1].childNodes) + self.assertTrue(not dom.childNodes[-1].childNodes) dom.unlink() def testUnlink(self): @@ -253,18 +253,18 @@ def testContext(self): def testElement(self): dom = Document() dom.appendChild(dom.createElement("abc")) - self.confirm(dom.documentElement) + self.assertTrue(dom.documentElement) dom.unlink() def testAAA(self): dom = parseString("") el = dom.documentElement el.setAttribute("spam", "jam2") - self.confirm(el.toxml() == '', "testAAA") + self.assertEqual(el.toxml(), '', "testAAA") a = el.getAttributeNode("spam") - self.confirm(a.ownerDocument is dom, + self.assertTrue(a.ownerDocument is dom, "setAttribute() sets ownerDocument") - self.confirm(a.ownerElement is dom.documentElement, + self.assertTrue(a.ownerElement is dom.documentElement, "setAttribute() sets ownerElement") dom.unlink() @@ -273,7 +273,7 @@ def testAAB(self): el = dom.documentElement el.setAttribute("spam", "jam") el.setAttribute("spam", "jam2") - self.confirm(el.toxml() == '', "testAAB") + self.assertEqual(el.toxml(), '', "testAAB") dom.unlink() def testAddAttr(self): @@ -281,31 +281,31 @@ def testAddAttr(self): child = dom.appendChild(dom.createElement("abc")) child.setAttribute("def", "ghi") - self.confirm(child.getAttribute("def") == "ghi") - self.confirm(child.attributes["def"].value == "ghi") + self.assertEqual(child.getAttribute("def"),"ghi") + self.assertEqual(child.attributes["def"].value, "ghi") child.setAttribute("jkl", "mno") - self.confirm(child.getAttribute("jkl") == "mno") - self.confirm(child.attributes["jkl"].value == "mno") + self.assertEqual(child.getAttribute("jkl"), "mno") + self.assertEqual(child.attributes["jkl"].value, "mno") - self.confirm(len(child.attributes) == 2) + self.assertEqual(len(child.attributes), 2) child.setAttribute("def", "newval") - self.confirm(child.getAttribute("def") == "newval") - self.confirm(child.attributes["def"].value == "newval") + self.assertEqual(child.getAttribute("def"), "newval") + self.assertEqual(child.attributes["def"].value, "newval") - self.confirm(len(child.attributes) == 2) + self.assertEqual(len(child.attributes), 2) dom.unlink() def testDeleteAttr(self): dom = Document() child = dom.appendChild(dom.createElement("abc")) - self.confirm(len(child.attributes) == 0) + self.assertEqual(len(child.attributes), 0) child.setAttribute("def", "ghi") - self.confirm(len(child.attributes) == 1) + self.assertEqual(len(child.attributes), 1) del child.attributes["def"] - self.confirm(len(child.attributes) == 0) + self.assertEqual(len(child.attributes), 0) dom.unlink() def testRemoveAttr(self): @@ -313,10 +313,10 @@ def testRemoveAttr(self): child = dom.appendChild(dom.createElement("abc")) child.setAttribute("def", "ghi") - self.confirm(len(child.attributes) == 1) + self.assertEqual(len(child.attributes), 1) self.assertRaises(xml.dom.NotFoundErr, child.removeAttribute, "foo") child.removeAttribute("def") - self.confirm(len(child.attributes) == 0) + self.assertEqual(len(child.attributes), 0) dom.unlink() def testRemoveAttrNS(self): @@ -328,21 +328,21 @@ def testRemoveAttrNS(self): child.setAttributeNS("http://www.python.org", "python:abcattr", "foo") self.assertRaises(xml.dom.NotFoundErr, child.removeAttributeNS, "foo", "http://www.python.org") - self.confirm(len(child.attributes) == 2) + self.assertEqual(len(child.attributes), 2) child.removeAttributeNS("http://www.python.org", "abcattr") - self.confirm(len(child.attributes) == 1) + self.assertEqual(len(child.attributes), 1) dom.unlink() def testRemoveAttributeNode(self): dom = Document() child = dom.appendChild(dom.createElement("foo")) child.setAttribute("spam", "jam") - self.confirm(len(child.attributes) == 1) + self.assertEqual(len(child.attributes), 1) node = child.getAttributeNode("spam") self.assertRaises(xml.dom.NotFoundErr, child.removeAttributeNode, None) self.assertIs(node, child.removeAttributeNode(node)) - self.confirm(len(child.attributes) == 0 + self.assertEqual(len(child.attributes), 0 and child.getAttributeNode("spam") is None) dom2 = Document() child2 = dom2.appendChild(dom2.createElement("foo")) @@ -355,13 +355,13 @@ def testHasAttribute(self): dom = Document() child = dom.appendChild(dom.createElement("foo")) child.setAttribute("spam", "jam") - self.confirm(child.hasAttribute("spam")) + self.assertTrue(child.hasAttribute("spam")) def testChangeAttr(self): dom = parseString("") el = dom.documentElement el.setAttribute("spam", "jam") - self.confirm(len(el.attributes) == 1) + self.assertEqual(len(el.attributes), 1) el.setAttribute("spam", "bam") # Set this attribute to be an ID and make sure that doesn't change # when changing the value: @@ -444,7 +444,7 @@ def testGetElementsByTagNameNS(self): def get_empty_nodelist_from_elements_by_tagName_ns_helper(self, doc, nsuri, lname): nodelist = doc.getElementsByTagNameNS(nsuri, lname) - self.confirm(len(nodelist) == 0) + self.assertEqual(len(nodelist), 0) def testGetEmptyNodeListFromElementsByTagNameNS(self): doc = parseString('') @@ -468,7 +468,7 @@ def testElementReprAndStr(self): el = dom.appendChild(dom.createElement("abc")) string1 = repr(el) string2 = str(el) - self.confirm(string1 == string2) + self.assertEqual(string1, string2) dom.unlink() def testElementReprAndStrUnicode(self): @@ -476,7 +476,7 @@ def testElementReprAndStrUnicode(self): el = dom.appendChild(dom.createElement("abc")) string1 = repr(el) string2 = str(el) - self.confirm(string1 == string2) + self.assertEqual(string1, string2) dom.unlink() def testElementReprAndStrUnicodeNS(self): @@ -485,15 +485,15 @@ def testElementReprAndStrUnicodeNS(self): dom.createElementNS("http://www.slashdot.org", "slash:abc")) string1 = repr(el) string2 = str(el) - self.confirm(string1 == string2) - self.confirm("slash:abc" in string1) + self.assertEqual(string1, string2) + self.assertIn("slash:abc", string1) dom.unlink() def testAttributeRepr(self): dom = Document() el = dom.appendChild(dom.createElement("abc")) node = el.setAttribute("abc", "def") - self.confirm(str(node) == repr(node)) + self.assertEqual(str(node), repr(node)) dom.unlink() def testTextNodeRepr(self): pass @@ -503,7 +503,7 @@ def testWriteXML(self): dom = parseString(str) domstr = dom.toxml() dom.unlink() - self.confirm(str == domstr) + self.assertEqual(str, domstr) def test_toxml_quote_text(self): dom = Document() @@ -550,7 +550,7 @@ def testAltNewline(self): dom = parseString(str) domstr = dom.toprettyxml(newl="\r\n") dom.unlink() - self.confirm(domstr == str.replace("\n", "\r\n")) + self.assertEqual(domstr, str.replace("\n", "\r\n")) def test_toprettyxml_with_text_nodes(self): # see issue #4147, text nodes are not indented @@ -643,7 +643,7 @@ def testRemoveNamedItem(self): attrs = e.attributes a1 = e.getAttributeNode("a") a2 = attrs.removeNamedItem("a") - self.confirm(a1.isSameNode(a2)) + self.assertEqual(a1.isSameNode(a2)) self.assertRaises(xml.dom.NotFoundErr, attrs.removeNamedItem, "a") def testRemoveNamedItemNS(self): @@ -652,7 +652,7 @@ def testRemoveNamedItemNS(self): attrs = e.attributes a1 = e.getAttributeNodeNS("http://xml.python.org/", "b") a2 = attrs.removeNamedItemNS("http://xml.python.org/", "b") - self.confirm(a1.isSameNode(a2)) + self.assertTrue(a1.isSameNode(a2)) self.assertRaises(xml.dom.NotFoundErr, attrs.removeNamedItemNS, "http://xml.python.org/", "b") @@ -695,7 +695,7 @@ def _testCloneElementCopiesAttributes(self, e1, e2, test): keys2 = list(attrs2.keys()) keys1.sort() keys2.sort() - self.confirm(keys1 == keys2, "clone of element has same attribute keys") + self.assertEqual(keys1, keys2, "clone of element has same attribute keys") for i in range(len(keys1)): a1 = attrs1.item(i) a2 = attrs2.item(i) @@ -705,7 +705,7 @@ def _testCloneElementCopiesAttributes(self, e1, e2, test): and a1.namespaceURI == a2.namespaceURI and a1.localName == a2.localName , "clone of attribute node has proper attribute values") - self.confirm(a2.ownerElement is e2, + self.assertIs(a2.ownerElement, e2, "clone of attribute node correctly owned") def _setupCloneElement(self, deep): @@ -746,7 +746,7 @@ def testCloneDocumentShallow(self): "]>\n" "") doc2 = doc.cloneNode(0) - self.confirm(doc2 is None, + self.assertIs(doc2, None, "testCloneDocumentShallow:" " shallow cloning of documents makes no sense!") @@ -758,22 +758,22 @@ def testCloneDocumentDeep(self): "]>\n" "") doc2 = doc.cloneNode(1) - self.confirm(not (doc.isSameNode(doc2) or doc2.isSameNode(doc)), + self.assertTrue(not (doc.isSameNode(doc2) or doc2.isSameNode(doc)), "testCloneDocumentDeep: document objects not distinct") - self.confirm(len(doc.childNodes) == len(doc2.childNodes), + self.assertEqual(len(doc.childNodes), len(doc2.childNodes), "testCloneDocumentDeep: wrong number of Document children") - self.confirm(doc2.documentElement.nodeType == Node.ELEMENT_NODE, + self.assertEqual(doc2.documentElement.nodeType, Node.ELEMENT_NODE, "testCloneDocumentDeep: documentElement not an ELEMENT_NODE") - self.confirm(doc2.documentElement.ownerDocument.isSameNode(doc2), + self.assertEqual(doc2.documentElement.ownerDocument.isSameNode(doc2), "testCloneDocumentDeep: documentElement owner is not new document") - self.confirm(not doc.documentElement.isSameNode(doc2.documentElement), + self.assertTrue(not doc.documentElement.isSameNode(doc2.documentElement), "testCloneDocumentDeep: documentElement should not be shared") if doc.doctype is not None: # check the doctype iff the original DOM maintained it - self.confirm(doc2.doctype.nodeType == Node.DOCUMENT_TYPE_NODE, + self.assertEqual(doc2.doctype.nodeType, Node.DOCUMENT_TYPE_NODE, "testCloneDocumentDeep: doctype not a DOCUMENT_TYPE_NODE") - self.confirm(doc2.doctype.ownerDocument.isSameNode(doc2)) - self.confirm(not doc.doctype.isSameNode(doc2.doctype)) + self.assertTrue(doc2.doctype.ownerDocument.isSameNode(doc2)) + self.assertTrue(not doc.doctype.isSameNode(doc2.doctype)) def testCloneDocumentTypeDeepOk(self): doctype = create_nonempty_doctype() @@ -812,7 +812,7 @@ def testCloneDocumentTypeDeepOk(self): def testCloneDocumentTypeDeepNotOk(self): doc = create_doc_with_doctype() clone = doc.doctype.cloneNode(1) - self.confirm(clone is None, "testCloneDocumentTypeDeepNotOk") + self.assertIs(clone, None, "testCloneDocumentTypeDeepNotOk") def testCloneDocumentTypeShallowOk(self): doctype = create_nonempty_doctype() @@ -831,7 +831,7 @@ def testCloneDocumentTypeShallowOk(self): def testCloneDocumentTypeShallowNotOk(self): doc = create_doc_with_doctype() clone = doc.doctype.cloneNode(0) - self.confirm(clone is None, "testCloneDocumentTypeShallowNotOk") + self.assertIs(clone, None, "testCloneDocumentTypeShallowNotOk") def check_import_document(self, deep, testName): doc1 = parseString("") @@ -863,14 +863,14 @@ def check_clone_attribute(self, deep, testName): attr = doc.documentElement.getAttributeNode("attr") self.assertNotEqual(attr, None) clone = attr.cloneNode(deep) - self.confirm(not clone.isSameNode(attr)) - self.confirm(not attr.isSameNode(clone)) - self.confirm(clone.ownerElement is None, + self.assertTrue(not clone.isSameNode(attr)) + self.assertTrue(not attr.isSameNode(clone)) + self.assertIs(clone.ownerElement, None, testName + ": ownerElement should be None") - self.confirm(clone.ownerDocument.isSameNode(attr.ownerDocument), + self.assertEqual(clone.ownerDocument.isSameNode(attr.ownerDocument), testName + ": ownerDocument does not match") - self.confirm(clone.specified, - testName + ": cloned attribute must have specified == True") + self.assertEqual(clone.specified, + testName + ": cloned attribute must have specified, True") def testCloneAttributeShallow(self): self.check_clone_attribute(0, "testCloneAttributeShallow") @@ -1142,7 +1142,7 @@ def testBug1433694(self): node = doc.documentElement node.childNodes[1].nodeValue = "" node.normalize() - self.confirm(node.childNodes[-1].nextSibling is None, + self.assertIS(node.childNodes[-1].nextSibling, None, "Final child's .nextSibling should be None") def testSiblings(self): @@ -1235,16 +1235,16 @@ def handle(self, operation, key, data, src, dst): def testUserData(self): dom = Document() n = dom.createElement('e') - self.confirm(n.getUserData("foo") is None) + self.assertIs(n.getUserData("foo"), None) n.setUserData("foo", None, None) - self.confirm(n.getUserData("foo") is None) + self.assertIs(n.getUserData("foo"), None) n.setUserData("foo", 12, 12) n.setUserData("bar", 13, 13) - self.confirm(n.getUserData("foo") == 12) - self.confirm(n.getUserData("bar") == 13) + self.assertEqual(n.getUserData("foo"), 12) + self.assertEqual(n.getUserData("bar"), 13) n.setUserData("foo", None, None) - self.confirm(n.getUserData("foo") is None) - self.confirm(n.getUserData("bar") == 13) + self.assertIs(n.getUserData("foo"), None) + self.assertEqual(n.getUserData("bar"), 13) handler = self.UserDataHandler() n.setUserData("bar", 12, handler) @@ -1434,10 +1434,10 @@ def testPatch1094164(self): doc = parseString("") elem = doc.documentElement e = elem.firstChild - self.confirm(e.parentNode is elem, "Before replaceChild()") + self.assertIs(e.parentNode, elem, "Before replaceChild()") # Check that replacing a child with itself leaves the tree unchanged elem.replaceChild(e, e) - self.confirm(e.parentNode is elem, "After replaceChild()") + self.assertIs(e.parentNode, elem, "After replaceChild()") def testReplaceWholeText(self): def setup(): @@ -1454,13 +1454,13 @@ def setup(): text = text1.replaceWholeText("new content") self.checkWholeText(text, "new content") self.checkWholeText(text2, "d") - self.confirm(len(elem.childNodes) == 3) + self.assertEqual(len(elem.childNodes), 3) doc, elem, text1, splitter, text2 = setup() text = text2.replaceWholeText("new content") self.checkWholeText(text, "new content") self.checkWholeText(text1, "cab") - self.confirm(len(elem.childNodes) == 5) + self.assertEqual(len(elem.childNodes), 5) doc, elem, text1, splitter, text2 = setup() text = text1.replaceWholeText("") @@ -1558,11 +1558,11 @@ def testSetIdAttributeNS(self): a3 = doc.createAttributeNS(NS1, "a1") a3.value = "v" e.setAttributeNode(a3) - self.confirm(e.isSameNode(doc.getElementById("w"))) - self.confirm(not a1.isId) - self.confirm(a2.isId) - self.confirm(not a3.isId) - self.confirm(doc.getElementById("v") is None) + self.assertTrue(e.isSameNode(doc.getElementById("w"))) + self.assertTrue(not a1.isId) + self.assertTrue(a2.isId) + self.assertTrue(not a3.isId) + self.assertIs(doc.getElementById("v"), None) # renaming an attribute should not affect its ID-ness: doc.renameNode(a2, xml.dom.EMPTY_NAMESPACE, "an") self.confirm(e.isSameNode(doc.getElementById("w")) @@ -1594,11 +1594,11 @@ def testSetIdAttributeNode(self): a3 = doc.createAttributeNS(NS1, "a1") a3.value = "v" e.setAttributeNode(a3) - self.confirm(e.isSameNode(doc.getElementById("w"))) - self.confirm(not a1.isId) - self.confirm(a2.isId) - self.confirm(not a3.isId) - self.confirm(doc.getElementById("v") is None) + self.assertTrue(e.isSameNode(doc.getElementById("w"))) + self.assertTrue(not a1.isId) + self.assertTrue(a2.isId) + self.assertTrue(not a3.isId) + self.assertIs(doc.getElementById("v"), None) # renaming an attribute should not affect its ID-ness: doc.renameNode(a2, xml.dom.EMPTY_NAMESPACE, "an") self.confirm(e.isSameNode(doc.getElementById("w")) @@ -1663,7 +1663,7 @@ def testEmptyXMLNSValue(self): doc = parseString("\n" "\n") doc2 = parseString(doc.toxml()) - self.confirm(doc2.namespaceURI == xml.dom.EMPTY_NAMESPACE) + self.assertEqual(doc2.namespaceURI, xml.dom.EMPTY_NAMESPACE) def testExceptionOnSpacesInXMLNSValue(self): with self.assertRaises((ValueError, ExpatError)): @@ -1679,7 +1679,7 @@ def testDocRemoveChild(self): num_children_before = len(doc.childNodes) doc.removeChild(doc.childNodes[0]) num_children_after = len(doc.childNodes) - self.assertTrue(num_children_after == num_children_before - 1) + self.assertEqual(num_children_after, num_children_before - 1) def testProcessingInstructionNameError(self): # wrong variable in .nodeValue property will From 9b0b74fbd5e61c32510db5ad4ce2401409bd5d0d Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Sat, 26 Apr 2025 12:51:15 +0100 Subject: [PATCH 2/6] Fixup --- Lib/test/test_minidom.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Lib/test/test_minidom.py b/Lib/test/test_minidom.py index ebe7315f0cbf52..88bfba53054b93 100644 --- a/Lib/test/test_minidom.py +++ b/Lib/test/test_minidom.py @@ -102,32 +102,32 @@ 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 + 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(), "" + and root.toxml() == "" , "testInsertBefore -- node properly placed in tree") nelem = dom.createElement("element") root.insertBefore(nelem, None) - self.confirm(len(root.childNodes), 3 - and root.childNodes.length, 3 + 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(), "" + and root.toxml() == "" , "testInsertBefore -- node properly placed in tree") nelem2 = dom.createElement("bar") root.insertBefore(nelem2, nelem) - self.confirm(len(root.childNodes), 4 - and root.childNodes.length, 4 + 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 @@ -643,7 +643,7 @@ def testRemoveNamedItem(self): attrs = e.attributes a1 = e.getAttributeNode("a") a2 = attrs.removeNamedItem("a") - self.assertEqual(a1.isSameNode(a2)) + self.assertTrue(a1.isSameNode(a2)) self.assertRaises(xml.dom.NotFoundErr, attrs.removeNamedItem, "a") def testRemoveNamedItemNS(self): @@ -764,7 +764,7 @@ def testCloneDocumentDeep(self): "testCloneDocumentDeep: wrong number of Document children") self.assertEqual(doc2.documentElement.nodeType, Node.ELEMENT_NODE, "testCloneDocumentDeep: documentElement not an ELEMENT_NODE") - self.assertEqual(doc2.documentElement.ownerDocument.isSameNode(doc2), + self.assertTrue(doc2.documentElement.ownerDocument.isSameNode(doc2), "testCloneDocumentDeep: documentElement owner is not new document") self.assertTrue(not doc.documentElement.isSameNode(doc2.documentElement), "testCloneDocumentDeep: documentElement should not be shared") @@ -867,10 +867,10 @@ def check_clone_attribute(self, deep, testName): self.assertTrue(not attr.isSameNode(clone)) self.assertIs(clone.ownerElement, None, testName + ": ownerElement should be None") - self.assertEqual(clone.ownerDocument.isSameNode(attr.ownerDocument), + self.confirm(clone.ownerDocument.isSameNode(attr.ownerDocument), testName + ": ownerDocument does not match") - self.assertEqual(clone.specified, - testName + ": cloned attribute must have specified, True") + self.confirm(clone.specified, + testName + ": cloned attribute must have specified == True") def testCloneAttributeShallow(self): self.check_clone_attribute(0, "testCloneAttributeShallow") @@ -1142,7 +1142,7 @@ def testBug1433694(self): node = doc.documentElement node.childNodes[1].nodeValue = "" node.normalize() - self.assertIS(node.childNodes[-1].nextSibling, None, + self.assertIs(node.childNodes[-1].nextSibling, None, "Final child's .nextSibling should be None") def testSiblings(self): From 746752667e9f847f260dcb3461f074c0b6140e7a Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Sat, 26 Apr 2025 12:55:31 +0100 Subject: [PATCH 3/6] assertFalse --- Lib/test/test_minidom.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Lib/test/test_minidom.py b/Lib/test/test_minidom.py index 88bfba53054b93..cd3e4c3ac8d627 100644 --- a/Lib/test/test_minidom.py +++ b/Lib/test/test_minidom.py @@ -155,7 +155,7 @@ def _create_fragment_test_nodes(self): def testInsertBeforeFragment(self): dom, orig, c1, c2, c3, frag = self._create_fragment_test_nodes() dom.documentElement.insertBefore(frag, None) - self.assertEqual(tuple(dom.documentElement.childNodes), + self.assertTupleEqual(tuple(dom.documentElement.childNodes), (orig, c1, c2, c3), "insertBefore(, None)") frag.unlink() @@ -221,9 +221,9 @@ def testNamedNodeMapSetItem(self): attrs = elem.attributes attrs["foo"] = "bar" a = attrs.item(0) - self.assertTrue(a.ownerDocument is dom, + self.assertIs(a.ownerDocument, dom, "NamedNodeMap.__setitem__() sets ownerDocument") - self.assertTrue(a.ownerElement is elem, + self.assertIs(a.ownerElement, elem, "NamedNodeMap.__setitem__() sets ownerElement") self.assertEqual(a.value, "bar", "NamedNodeMap.__setitem__() sets value") @@ -234,9 +234,9 @@ def testNamedNodeMapSetItem(self): def testNonZero(self): dom = parse(tstfile) - self.assertTrue(dom)# should not be zero + self.assertTrue(dom) # should not be zero dom.appendChild(dom.createComment("foo")) - self.assertTrue(not dom.childNodes[-1].childNodes) + self.assertFalse(dom.childNodes[-1].childNodes) dom.unlink() def testUnlink(self): @@ -758,7 +758,7 @@ def testCloneDocumentDeep(self): "]>\n" "") doc2 = doc.cloneNode(1) - self.assertTrue(not (doc.isSameNode(doc2) or doc2.isSameNode(doc)), + self.assertFalse((doc.isSameNode(doc2) or doc2.isSameNode(doc)), "testCloneDocumentDeep: document objects not distinct") self.assertEqual(len(doc.childNodes), len(doc2.childNodes), "testCloneDocumentDeep: wrong number of Document children") @@ -766,14 +766,14 @@ def testCloneDocumentDeep(self): "testCloneDocumentDeep: documentElement not an ELEMENT_NODE") self.assertTrue(doc2.documentElement.ownerDocument.isSameNode(doc2), "testCloneDocumentDeep: documentElement owner is not new document") - self.assertTrue(not doc.documentElement.isSameNode(doc2.documentElement), + self.assertFalse(doc.documentElement.isSameNode(doc2.documentElement), "testCloneDocumentDeep: documentElement should not be shared") if doc.doctype is not None: # check the doctype iff the original DOM maintained it self.assertEqual(doc2.doctype.nodeType, Node.DOCUMENT_TYPE_NODE, "testCloneDocumentDeep: doctype not a DOCUMENT_TYPE_NODE") self.assertTrue(doc2.doctype.ownerDocument.isSameNode(doc2)) - self.assertTrue(not doc.doctype.isSameNode(doc2.doctype)) + self.assertFalse(doc.doctype.isSameNode(doc2.doctype)) def testCloneDocumentTypeDeepOk(self): doctype = create_nonempty_doctype() @@ -863,8 +863,8 @@ def check_clone_attribute(self, deep, testName): attr = doc.documentElement.getAttributeNode("attr") self.assertNotEqual(attr, None) clone = attr.cloneNode(deep) - self.assertTrue(not clone.isSameNode(attr)) - self.assertTrue(not attr.isSameNode(clone)) + self.assertFalse(clone.isSameNode(attr)) + self.assertFalse(attr.isSameNode(clone)) self.assertIs(clone.ownerElement, None, testName + ": ownerElement should be None") self.confirm(clone.ownerDocument.isSameNode(attr.ownerDocument), @@ -1559,9 +1559,9 @@ def testSetIdAttributeNS(self): a3.value = "v" e.setAttributeNode(a3) self.assertTrue(e.isSameNode(doc.getElementById("w"))) - self.assertTrue(not a1.isId) + self.assertFalse(a1.isId) self.assertTrue(a2.isId) - self.assertTrue(not a3.isId) + self.assertFalse(a3.isId) self.assertIs(doc.getElementById("v"), None) # renaming an attribute should not affect its ID-ness: doc.renameNode(a2, xml.dom.EMPTY_NAMESPACE, "an") @@ -1595,9 +1595,9 @@ def testSetIdAttributeNode(self): a3.value = "v" e.setAttributeNode(a3) self.assertTrue(e.isSameNode(doc.getElementById("w"))) - self.assertTrue(not a1.isId) + self.assertFalse(a1.isId) self.assertTrue(a2.isId) - self.assertTrue(not a3.isId) + self.assertFalse(a3.isId) self.assertIs(doc.getElementById("v"), None) # renaming an attribute should not affect its ID-ness: doc.renameNode(a2, xml.dom.EMPTY_NAMESPACE, "an") From 5dfbc511214361ab3416d5db4b16879dfc8fa569 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> Date: Sat, 26 Apr 2025 13:08:29 +0100 Subject: [PATCH 4/6] Final fixup --- Lib/test/test_minidom.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_minidom.py b/Lib/test/test_minidom.py index cd3e4c3ac8d627..c6c78af5102ae7 100644 --- a/Lib/test/test_minidom.py +++ b/Lib/test/test_minidom.py @@ -163,7 +163,7 @@ def testInsertBeforeFragment(self): dom, orig, c1, c2, c3, frag = self._create_fragment_test_nodes() dom.documentElement.insertBefore(frag, orig) - self.assertEqual(tuple(dom.documentElement.childNodes), + self.assertTupleEqual(tuple(dom.documentElement.childNodes), (c1, c2, c3, orig), "insertBefore(, orig)") frag.unlink() @@ -179,7 +179,7 @@ def testAppendChild(self): def testAppendChildFragment(self): dom, orig, c1, c2, c3, frag = self._create_fragment_test_nodes() dom.documentElement.appendChild(frag) - self.assertEqual(tuple(dom.documentElement.childNodes), + self.assertTupleEqual(tuple(dom.documentElement.childNodes), (orig, c1, c2, c3), "appendChild()") frag.unlink() @@ -189,7 +189,7 @@ def testReplaceChildFragment(self): dom, orig, c1, c2, c3, frag = self._create_fragment_test_nodes() dom.documentElement.replaceChild(frag, orig) orig.unlink() - self.assertEqual(tuple(dom.documentElement.childNodes), (c1, c2, c3), + self.assertTupleEqual(tuple(dom.documentElement.childNodes), (c1, c2, c3), "replaceChild()") frag.unlink() dom.unlink() @@ -262,9 +262,9 @@ def testAAA(self): el.setAttribute("spam", "jam2") self.assertEqual(el.toxml(), '', "testAAA") a = el.getAttributeNode("spam") - self.assertTrue(a.ownerDocument is dom, + self.assertIs(a.ownerDocument, dom, "setAttribute() sets ownerDocument") - self.assertTrue(a.ownerElement is dom.documentElement, + self.assertIs(a.ownerElement, dom.documentElement, "setAttribute() sets ownerElement") dom.unlink() From 91e51cf986190ae083a96ec6d75a252008f47240 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Sat, 26 Apr 2025 18:46:37 +0100 Subject: [PATCH 5/6] assertIsNone --- Lib/test/test_minidom.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/Lib/test/test_minidom.py b/Lib/test/test_minidom.py index c6c78af5102ae7..ee6c342b3faaf0 100644 --- a/Lib/test/test_minidom.py +++ b/Lib/test/test_minidom.py @@ -281,7 +281,7 @@ def testAddAttr(self): child = dom.appendChild(dom.createElement("abc")) child.setAttribute("def", "ghi") - self.assertEqual(child.getAttribute("def"),"ghi") + self.assertEqual(child.getAttribute("def"), "ghi") self.assertEqual(child.attributes["def"].value, "ghi") child.setAttribute("jkl", "mno") @@ -342,7 +342,7 @@ def testRemoveAttributeNode(self): self.assertRaises(xml.dom.NotFoundErr, child.removeAttributeNode, None) self.assertIs(node, child.removeAttributeNode(node)) - self.assertEqual(len(child.attributes), 0 + self.confirm(len(child.attributes) == 0 and child.getAttributeNode("spam") is None) dom2 = Document() child2 = dom2.appendChild(dom2.createElement("foo")) @@ -695,7 +695,8 @@ 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, + "clone of element has same attribute keys") for i in range(len(keys1)): a1 = attrs1.item(i) a2 = attrs2.item(i) @@ -746,7 +747,7 @@ def testCloneDocumentShallow(self): "]>\n" "") doc2 = doc.cloneNode(0) - self.assertIs(doc2, None, + self.assertIsNone(doc2, "testCloneDocumentShallow:" " shallow cloning of documents makes no sense!") @@ -812,7 +813,7 @@ def testCloneDocumentTypeDeepOk(self): def testCloneDocumentTypeDeepNotOk(self): doc = create_doc_with_doctype() clone = doc.doctype.cloneNode(1) - self.assertIs(clone, None, "testCloneDocumentTypeDeepNotOk") + self.assertIsNone(clone, "testCloneDocumentTypeDeepNotOk") def testCloneDocumentTypeShallowOk(self): doctype = create_nonempty_doctype() @@ -831,7 +832,7 @@ def testCloneDocumentTypeShallowOk(self): def testCloneDocumentTypeShallowNotOk(self): doc = create_doc_with_doctype() clone = doc.doctype.cloneNode(0) - self.assertIs(clone, None, "testCloneDocumentTypeShallowNotOk") + self.assertIsNone(clone) def check_import_document(self, deep, testName): doc1 = parseString("") @@ -861,11 +862,11 @@ def testImportDocumentTypeDeep(self): def check_clone_attribute(self, deep, testName): doc = parseString("") attr = doc.documentElement.getAttributeNode("attr") - self.assertNotEqual(attr, None) + self.assertIsNotNone(attr) clone = attr.cloneNode(deep) self.assertFalse(clone.isSameNode(attr)) self.assertFalse(attr.isSameNode(clone)) - self.assertIs(clone.ownerElement, None, + self.assertIsNone(clone.ownerElement, testName + ": ownerElement should be None") self.confirm(clone.ownerDocument.isSameNode(attr.ownerDocument), testName + ": ownerDocument does not match") @@ -1142,7 +1143,7 @@ def testBug1433694(self): node = doc.documentElement node.childNodes[1].nodeValue = "" node.normalize() - self.assertIs(node.childNodes[-1].nextSibling, None, + self.assertIsNone(node.childNodes[-1].nextSibling, "Final child's .nextSibling should be None") def testSiblings(self): @@ -1235,15 +1236,15 @@ def handle(self, operation, key, data, src, dst): def testUserData(self): dom = Document() n = dom.createElement('e') - self.assertIs(n.getUserData("foo"), None) + self.assertIsNone(n.getUserData("foo")) n.setUserData("foo", None, None) - self.assertIs(n.getUserData("foo"), None) + self.assertIsNone(n.getUserData("foo")) n.setUserData("foo", 12, 12) n.setUserData("bar", 13, 13) self.assertEqual(n.getUserData("foo"), 12) self.assertEqual(n.getUserData("bar"), 13) n.setUserData("foo", None, None) - self.assertIs(n.getUserData("foo"), None) + self.assertIsNone(n.getUserData("foo")) self.assertEqual(n.getUserData("bar"), 13) handler = self.UserDataHandler() @@ -1562,7 +1563,7 @@ def testSetIdAttributeNS(self): self.assertFalse(a1.isId) self.assertTrue(a2.isId) self.assertFalse(a3.isId) - self.assertIs(doc.getElementById("v"), None) + self.assertIsNone(doc.getElementById("v")) # renaming an attribute should not affect its ID-ness: doc.renameNode(a2, xml.dom.EMPTY_NAMESPACE, "an") self.confirm(e.isSameNode(doc.getElementById("w")) @@ -1598,7 +1599,7 @@ def testSetIdAttributeNode(self): self.assertFalse(a1.isId) self.assertTrue(a2.isId) self.assertFalse(a3.isId) - self.assertIs(doc.getElementById("v"), None) + self.assertIsNone(doc.getElementById("v")) # renaming an attribute should not affect its ID-ness: doc.renameNode(a2, xml.dom.EMPTY_NAMESPACE, "an") self.confirm(e.isSameNode(doc.getElementById("w")) From 044354fe3000760a75e3248f81c6510d502e6149 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Sat, 26 Apr 2025 19:59:25 +0200 Subject: [PATCH 6/6] Update Lib/test/test_minidom.py --- Lib/test/test_minidom.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_minidom.py b/Lib/test/test_minidom.py index ee6c342b3faaf0..f717fd03ca5662 100644 --- a/Lib/test/test_minidom.py +++ b/Lib/test/test_minidom.py @@ -813,7 +813,7 @@ def testCloneDocumentTypeDeepOk(self): def testCloneDocumentTypeDeepNotOk(self): doc = create_doc_with_doctype() clone = doc.doctype.cloneNode(1) - self.assertIsNone(clone, "testCloneDocumentTypeDeepNotOk") + self.assertIsNone(clone) def testCloneDocumentTypeShallowOk(self): doctype = create_nonempty_doctype()