From 0496125cf1402cc5105754ff04c6b3e5e4ebd0fd Mon Sep 17 00:00:00 2001 From: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> Date: Sat, 26 Apr 2025 21:03:48 +0100 Subject: [PATCH] gh-63882: Implement some `test_minidom` tests (GH-132879) (cherry picked from commit ee033d455577dd7af6c5421f3365eba1c9af1087) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> Co-authored-by: Julian Gindi Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- Lib/test/test_minidom.py | 41 +++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/Lib/test/test_minidom.py b/Lib/test/test_minidom.py index f717fd03ca5662..6679c0a4fbedd9 100644 --- a/Lib/test/test_minidom.py +++ b/Lib/test/test_minidom.py @@ -396,13 +396,28 @@ def testChangeAttr(self): dom.unlink() def testGetAttrList(self): - pass + dom = parseString("") + self.addCleanup(dom.unlink) + el = dom.documentElement + el.setAttribute("spam", "jam") + self.assertEqual(len(el.attributes.items()), 1) + el.setAttribute("foo", "bar") + items = el.attributes.items() + self.assertEqual(len(items), 2) + self.assertIn(('spam', 'jam'), items) + self.assertIn(('foo', 'bar'), items) def testGetAttrValues(self): - pass - - def testGetAttrLength(self): - pass + dom = parseString("") + self.addCleanup(dom.unlink) + el = dom.documentElement + el.setAttribute("spam", "jam") + values = [x.value for x in el.attributes.values()] + self.assertIn("jam", values) + el.setAttribute("foo", "bar") + values = [x.value for x in el.attributes.values()] + self.assertIn("bar", values) + self.assertIn("jam", values) def testGetAttribute(self): dom = Document() @@ -496,8 +511,6 @@ def testAttributeRepr(self): self.assertEqual(str(node), repr(node)) dom.unlink() - def testTextNodeRepr(self): pass - def testWriteXML(self): str = '' dom = parseString(str) @@ -601,9 +614,19 @@ def testProcessingInstruction(self): and pi.localName is None and pi.namespaceURI == xml.dom.EMPTY_NAMESPACE) - def testProcessingInstructionRepr(self): pass + def testProcessingInstructionRepr(self): + dom = parseString('') + pi = dom.documentElement.firstChild + self.assertEqual(str(pi.nodeType), repr(pi.nodeType)) - def testTextRepr(self): pass + def testTextRepr(self): + dom = Document() + self.addCleanup(dom.unlink) + elem = dom.createElement("elem") + elem.appendChild(dom.createTextNode("foo")) + el = elem.firstChild + self.assertEqual(str(el), repr(el)) + self.assertEqual('', str(el)) def testWriteText(self): pass