summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_minidom.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_minidom.py')
-rw-r--r--Lib/test/test_minidom.py41
1 files changed, 26 insertions, 15 deletions
diff --git a/Lib/test/test_minidom.py b/Lib/test/test_minidom.py
index c58d17d..4c2b34a 100644
--- a/Lib/test/test_minidom.py
+++ b/Lib/test/test_minidom.py
@@ -1,9 +1,7 @@
# test for xml.dom.minidom
-import os
-import sys
import pickle
-from test.support import verbose, run_unittest
+from test.support import verbose, run_unittest, findfile
import unittest
import xml.dom
@@ -14,12 +12,8 @@ from xml.dom.minidom import parse, Node, Document, parseString
from xml.dom.minidom import getDOMImplementation
-if __name__ == "__main__":
- base = sys.argv[0]
-else:
- base = __file__
-tstfile = os.path.join(os.path.dirname(base), "test.xml")
-del base
+tstfile = findfile("test.xml", subdir="xmltestdata")
+
# The tests of DocumentType importing use these helpers to construct
# the documents to work with, since not all DOM builders actually
@@ -79,9 +73,10 @@ class MinidomTest(unittest.TestCase):
self.confirm(t == s, "looking for %s, found %s" % (repr(s), repr(t)))
def testParseFromFile(self):
- dom = parse(open(tstfile))
- dom.unlink()
- self.confirm(isinstance(dom, Document))
+ with open(tstfile) as file:
+ dom = parse(file)
+ dom.unlink()
+ self.confirm(isinstance(dom, Document))
def testGetElementsByTagName(self):
dom = parse(tstfile)
@@ -234,7 +229,14 @@ class MinidomTest(unittest.TestCase):
def testUnlink(self):
dom = parse(tstfile)
+ self.assertTrue(dom.childNodes)
dom.unlink()
+ self.assertFalse(dom.childNodes)
+
+ def testContext(self):
+ with parse(tstfile) as dom:
+ self.assertTrue(dom.childNodes)
+ self.assertFalse(dom.childNodes)
def testElement(self):
dom = Document()
@@ -438,7 +440,7 @@ class MinidomTest(unittest.TestCase):
string1 = repr(el)
string2 = str(el)
self.confirm(string1 == string2)
- self.confirm(string1.find("slash:abc") != -1)
+ self.confirm("slash:abc" in string1)
dom.unlink()
def testAttributeRepr(self):
@@ -950,12 +952,20 @@ class MinidomTest(unittest.TestCase):
doc.unlink()
+ def testBug0777884(self):
+ doc = parseString("<o>text</o>")
+ text = doc.documentElement.childNodes[0]
+ self.assertEqual(text.nodeType, Node.TEXT_NODE)
+ # Should run quietly, doing nothing.
+ text.normalize()
+ doc.unlink()
+
def testBug1433694(self):
doc = parseString("<o><i/>t</o>")
node = doc.documentElement
node.childNodes[1].nodeValue = ""
node.normalize()
- self.confirm(node.childNodes[-1].nextSibling == None,
+ self.confirm(node.childNodes[-1].nextSibling is None,
"Final child's .nextSibling should be None")
def testSiblings(self):
@@ -1455,12 +1465,13 @@ class MinidomTest(unittest.TestCase):
self.confirm(len(n1.entities) == len(n2.entities)
and len(n1.notations) == len(n2.notations))
for i in range(len(n1.notations)):
+ # XXX this loop body doesn't seem to be executed?
no1 = n1.notations.item(i)
no2 = n1.notations.item(i)
self.confirm(no1.name == no2.name
and no1.publicId == no2.publicId
and no1.systemId == no2.systemId)
- statck.append((no1, no2))
+ stack.append((no1, no2))
for i in range(len(n1.entities)):
e1 = n1.entities.item(i)
e2 = n2.entities.item(i)