Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 06eef9c

Browse files
committed
Issue 11758: increase xml.dom.minidom test coverage (contributed by mdorn, reviewed by Sandro Tosi).
1 parent 7f48578 commit 06eef9c

1 file changed

Lines changed: 40 additions & 2 deletions

File tree

Lib/test/test_minidom.py

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ def testRemoveAttr(self):
279279

280280
child.setAttribute("def", "ghi")
281281
self.confirm(len(child.attributes) == 1)
282+
self.assertRaises(xml.dom.NotFoundErr, child.removeAttribute, "foo")
282283
child.removeAttribute("def")
283284
self.confirm(len(child.attributes) == 0)
284285
dom.unlink()
@@ -290,6 +291,8 @@ def testRemoveAttrNS(self):
290291
child.setAttributeNS("http://www.w3.org", "xmlns:python",
291292
"http://www.python.org")
292293
child.setAttributeNS("http://www.python.org", "python:abcattr", "foo")
294+
self.assertRaises(xml.dom.NotFoundErr, child.removeAttributeNS,
295+
"foo", "http://www.python.org")
293296
self.confirm(len(child.attributes) == 2)
294297
child.removeAttributeNS("http://www.python.org", "abcattr")
295298
self.confirm(len(child.attributes) == 1)
@@ -301,11 +304,23 @@ def testRemoveAttributeNode(self):
301304
child.setAttribute("spam", "jam")
302305
self.confirm(len(child.attributes) == 1)
303306
node = child.getAttributeNode("spam")
307+
self.assertRaises(xml.dom.NotFoundErr, child.removeAttributeNode,
308+
None)
304309
child.removeAttributeNode(node)
305310
self.confirm(len(child.attributes) == 0
306311
and child.getAttributeNode("spam") is None)
312+
dom2 = Document()
313+
child2 = dom2.appendChild(dom.createElement("foo"))
314+
self.assertRaises(xml.dom.NotFoundErr, child.removeAttributeNode,
315+
node)
307316
dom.unlink()
308317

318+
def testHasAttribute(self):
319+
dom = Document()
320+
child = dom.appendChild(dom.createElement("foo"))
321+
child.setAttribute("spam", "jam")
322+
self.confirm(child.hasAttribute("spam"))
323+
309324
def testChangeAttr(self):
310325
dom = parseString("<abc/>")
311326
el = dom.documentElement
@@ -353,7 +368,16 @@ def testGetAttrLength(self): pass
353368

354369
def testGetAttribute(self): pass
355370

356-
def testGetAttributeNS(self): pass
371+
def testGetAttributeNS(self):
372+
dom = Document()
373+
child = dom.appendChild(
374+
dom.createElementNS("http://www.python.org", "python:abc"))
375+
child.setAttributeNS("http://www.w3.org", "xmlns:python",
376+
"http://www.python.org")
377+
self.assertEqual(child.getAttributeNS("http://www.w3.org", "python"),
378+
'http://www.python.org')
379+
self.assertEqual(child.getAttributeNS("http://www.w3.org", "other"),
380+
'')
357381

358382
def testGetAttributeNode(self): pass
359383

@@ -537,7 +561,13 @@ def testChildNodes(self): pass
537561

538562
def testFirstChild(self): pass
539563

540-
def testHasChildNodes(self): pass
564+
def testHasChildNodes(self):
565+
dom = parseString("<doc><foo/></doc>")
566+
doc = dom.documentElement
567+
self.assertTrue(dom.hasChildNodes())
568+
dom2 = parseString("<doc/>")
569+
doc2 = dom2.documentElement
570+
self.assertFalse(doc2.hasChildNodes())
541571

542572
def _testCloneElementCopiesAttributes(self, e1, e2, test):
543573
attrs1 = e1.attributes
@@ -1439,6 +1469,14 @@ def testEmptyXMLNSValue(self):
14391469
doc2 = parseString(doc.toxml())
14401470
self.confirm(doc2.namespaceURI == xml.dom.EMPTY_NAMESPACE)
14411471

1472+
def testDocRemoveChild(self):
1473+
doc = parse(tstfile)
1474+
title_tag = doc.documentElement.getElementsByTagName("TITLE")[0]
1475+
self.assertRaises( xml.dom.NotFoundErr, doc.removeChild, title_tag)
1476+
num_children_before = len(doc.childNodes)
1477+
doc.removeChild(doc.childNodes[0])
1478+
num_children_after = len(doc.childNodes)
1479+
self.assertTrue(num_children_after == num_children_before - 1)
14421480

14431481
def test_main():
14441482
run_unittest(MinidomTest)

0 commit comments

Comments
 (0)