Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(23)

Side by Side Diff: Lib/test/test_minidom.py

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_marshal.py ('k') | Lib/test/test_mmap.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # test for xml.dom.minidom 1 # test for xml.dom.minidom
2 2
3 import pickle 3 import pickle
4 from test.support import verbose, run_unittest, findfile 4 from test.support import verbose, run_unittest, findfile
5 import unittest 5 import unittest
6 6
7 import xml.dom.minidom 7 import xml.dom.minidom
8 8
9 from xml.dom.minidom import parse, Node, Document, parseString 9 from xml.dom.minidom import parse, Node, Document, parseString
10 from xml.dom.minidom import getDOMImplementation 10 from xml.dom.minidom import getDOMImplementation
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 del child.attributes["def"] 272 del child.attributes["def"]
273 self.confirm(len(child.attributes) == 0) 273 self.confirm(len(child.attributes) == 0)
274 dom.unlink() 274 dom.unlink()
275 275
276 def testRemoveAttr(self): 276 def testRemoveAttr(self):
277 dom = Document() 277 dom = Document()
278 child = dom.appendChild(dom.createElement("abc")) 278 child = dom.appendChild(dom.createElement("abc"))
279 279
280 child.setAttribute("def", "ghi") 280 child.setAttribute("def", "ghi")
281 self.confirm(len(child.attributes) == 1) 281 self.confirm(len(child.attributes) == 1)
282 self.assertRaises(xml.dom.NotFoundErr, child.removeAttribute, "foo")
283 child.removeAttribute("def") 282 child.removeAttribute("def")
284 self.confirm(len(child.attributes) == 0) 283 self.confirm(len(child.attributes) == 0)
285 dom.unlink() 284 dom.unlink()
286 285
287 def testRemoveAttrNS(self): 286 def testRemoveAttrNS(self):
288 dom = Document() 287 dom = Document()
289 child = dom.appendChild( 288 child = dom.appendChild(
290 dom.createElementNS("http://www.python.org", "python:abc")) 289 dom.createElementNS("http://www.python.org", "python:abc"))
291 child.setAttributeNS("http://www.w3.org", "xmlns:python", 290 child.setAttributeNS("http://www.w3.org", "xmlns:python",
292 "http://www.python.org") 291 "http://www.python.org")
293 child.setAttributeNS("http://www.python.org", "python:abcattr", "foo") 292 child.setAttributeNS("http://www.python.org", "python:abcattr", "foo")
294 self.assertRaises(xml.dom.NotFoundErr, child.removeAttributeNS,
295 "foo", "http://www.python.org")
296 self.confirm(len(child.attributes) == 2) 293 self.confirm(len(child.attributes) == 2)
297 child.removeAttributeNS("http://www.python.org", "abcattr") 294 child.removeAttributeNS("http://www.python.org", "abcattr")
298 self.confirm(len(child.attributes) == 1) 295 self.confirm(len(child.attributes) == 1)
299 dom.unlink() 296 dom.unlink()
300 297
301 def testRemoveAttributeNode(self): 298 def testRemoveAttributeNode(self):
302 dom = Document() 299 dom = Document()
303 child = dom.appendChild(dom.createElement("foo")) 300 child = dom.appendChild(dom.createElement("foo"))
304 child.setAttribute("spam", "jam") 301 child.setAttribute("spam", "jam")
305 self.confirm(len(child.attributes) == 1) 302 self.confirm(len(child.attributes) == 1)
306 node = child.getAttributeNode("spam") 303 node = child.getAttributeNode("spam")
307 self.assertRaises(xml.dom.NotFoundErr, child.removeAttributeNode,
308 None)
309 child.removeAttributeNode(node) 304 child.removeAttributeNode(node)
310 self.confirm(len(child.attributes) == 0 305 self.confirm(len(child.attributes) == 0
311 and child.getAttributeNode("spam") is None) 306 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)
316 dom.unlink() 307 dom.unlink()
317
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 308
324 def testChangeAttr(self): 309 def testChangeAttr(self):
325 dom = parseString("<abc/>") 310 dom = parseString("<abc/>")
326 el = dom.documentElement 311 el = dom.documentElement
327 el.setAttribute("spam", "jam") 312 el.setAttribute("spam", "jam")
328 self.confirm(len(el.attributes) == 1) 313 self.confirm(len(el.attributes) == 1)
329 el.setAttribute("spam", "bam") 314 el.setAttribute("spam", "bam")
330 # Set this attribute to be an ID and make sure that doesn't change 315 # Set this attribute to be an ID and make sure that doesn't change
331 # when changing the value: 316 # when changing the value:
332 el.setIdAttribute("spam") 317 el.setIdAttribute("spam")
(...skipping 28 matching lines...) Expand all
361 346
362 def testGetAttrList(self): 347 def testGetAttrList(self):
363 pass 348 pass
364 349
365 def testGetAttrValues(self): pass 350 def testGetAttrValues(self): pass
366 351
367 def testGetAttrLength(self): pass 352 def testGetAttrLength(self): pass
368 353
369 def testGetAttribute(self): pass 354 def testGetAttribute(self): pass
370 355
371 def testGetAttributeNS(self): 356 def testGetAttributeNS(self): pass
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 '')
381 357
382 def testGetAttributeNode(self): pass 358 def testGetAttributeNode(self): pass
383 359
384 def testGetElementsByTagNameNS(self): 360 def testGetElementsByTagNameNS(self):
385 d="""<foo xmlns:minidom='http://pyxml.sf.net/minidom'> 361 d="""<foo xmlns:minidom='http://pyxml.sf.net/minidom'>
386 <minidom:myelem/> 362 <minidom:myelem/>
387 </foo>""" 363 </foo>"""
388 dom = parseString(d) 364 dom = parseString(d)
389 elems = dom.getElementsByTagNameNS("http://pyxml.sf.net/minidom", 365 elems = dom.getElementsByTagNameNS("http://pyxml.sf.net/minidom",
390 "myelem") 366 "myelem")
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 def testParseElementNamespaces(self): pass 530 def testParseElementNamespaces(self): pass
555 531
556 def testParseAttributeNamespaces(self): pass 532 def testParseAttributeNamespaces(self): pass
557 533
558 def testParseProcessingInstructions(self): pass 534 def testParseProcessingInstructions(self): pass
559 535
560 def testChildNodes(self): pass 536 def testChildNodes(self): pass
561 537
562 def testFirstChild(self): pass 538 def testFirstChild(self): pass
563 539
564 def testHasChildNodes(self): 540 def testHasChildNodes(self): pass
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())
571 541
572 def _testCloneElementCopiesAttributes(self, e1, e2, test): 542 def _testCloneElementCopiesAttributes(self, e1, e2, test):
573 attrs1 = e1.attributes 543 attrs1 = e1.attributes
574 attrs2 = e2.attributes 544 attrs2 = e2.attributes
575 keys1 = list(attrs1.keys()) 545 keys1 = list(attrs1.keys())
576 keys2 = list(attrs2.keys()) 546 keys2 = list(attrs2.keys())
577 keys1.sort() 547 keys1.sort()
578 keys2.sort() 548 keys2.sort()
579 self.confirm(keys1 == keys2, "clone of element has same attribute keys") 549 self.confirm(keys1 == keys2, "clone of element has same attribute keys")
580 for i in range(len(keys1)): 550 for i in range(len(keys1)):
(...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after
1462 doc.appendChild(doc.createComment("foo--bar")) 1432 doc.appendChild(doc.createComment("foo--bar"))
1463 self.assertRaises(ValueError, doc.toxml) 1433 self.assertRaises(ValueError, doc.toxml)
1464 1434
1465 1435
1466 def testEmptyXMLNSValue(self): 1436 def testEmptyXMLNSValue(self):
1467 doc = parseString("<element xmlns=''>\n" 1437 doc = parseString("<element xmlns=''>\n"
1468 "<foo/>\n</element>") 1438 "<foo/>\n</element>")
1469 doc2 = parseString(doc.toxml()) 1439 doc2 = parseString(doc.toxml())
1470 self.confirm(doc2.namespaceURI == xml.dom.EMPTY_NAMESPACE) 1440 self.confirm(doc2.namespaceURI == xml.dom.EMPTY_NAMESPACE)
1471 1441
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)
1480 1442
1481 def test_main(): 1443 def test_main():
1482 run_unittest(MinidomTest) 1444 run_unittest(MinidomTest)
1483 1445
1484 if __name__ == "__main__": 1446 if __name__ == "__main__":
1485 test_main() 1447 test_main()
OLDNEW
« no previous file with comments | « Lib/test/test_marshal.py ('k') | Lib/test/test_mmap.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+