mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
gh-63882: Use self.assert*
methods in test_minidom
(#133000)
This commit is contained in:
parent
0eb0e70ca0
commit
56c88e4e8d
1 changed files with 90 additions and 89 deletions
|
@ -57,7 +57,7 @@ class MinidomTest(unittest.TestCase):
|
||||||
|
|
||||||
def checkWholeText(self, node, s):
|
def checkWholeText(self, node, s):
|
||||||
t = node.wholeText
|
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):
|
def testDocumentAsyncAttr(self):
|
||||||
doc = Document()
|
doc = Document()
|
||||||
|
@ -68,13 +68,13 @@ class MinidomTest(unittest.TestCase):
|
||||||
with open(tstfile, 'rb') as file:
|
with open(tstfile, 'rb') as file:
|
||||||
dom = parse(file)
|
dom = parse(file)
|
||||||
dom.unlink()
|
dom.unlink()
|
||||||
self.confirm(isinstance(dom, Document))
|
self.assertIsInstance(dom, Document)
|
||||||
|
|
||||||
def testParseFromTextFile(self):
|
def testParseFromTextFile(self):
|
||||||
with open(tstfile, 'r', encoding='iso-8859-1') as file:
|
with open(tstfile, 'r', encoding='iso-8859-1') as file:
|
||||||
dom = parse(file)
|
dom = parse(file)
|
||||||
dom.unlink()
|
dom.unlink()
|
||||||
self.confirm(isinstance(dom, Document))
|
self.assertIsInstance(dom, Document)
|
||||||
|
|
||||||
def testAttrModeSetsParamsAsAttrs(self):
|
def testAttrModeSetsParamsAsAttrs(self):
|
||||||
attr = Attr("qName", "namespaceURI", "localName", "prefix")
|
attr = Attr("qName", "namespaceURI", "localName", "prefix")
|
||||||
|
@ -92,7 +92,7 @@ class MinidomTest(unittest.TestCase):
|
||||||
|
|
||||||
def testGetElementsByTagName(self):
|
def testGetElementsByTagName(self):
|
||||||
dom = parse(tstfile)
|
dom = parse(tstfile)
|
||||||
self.confirm(dom.getElementsByTagName("LI") == \
|
self.assertEqual(dom.getElementsByTagName("LI"),
|
||||||
dom.documentElement.getElementsByTagName("LI"))
|
dom.documentElement.getElementsByTagName("LI"))
|
||||||
dom.unlink()
|
dom.unlink()
|
||||||
|
|
||||||
|
@ -155,7 +155,7 @@ class MinidomTest(unittest.TestCase):
|
||||||
def testInsertBeforeFragment(self):
|
def testInsertBeforeFragment(self):
|
||||||
dom, orig, c1, c2, c3, frag = self._create_fragment_test_nodes()
|
dom, orig, c1, c2, c3, frag = self._create_fragment_test_nodes()
|
||||||
dom.documentElement.insertBefore(frag, None)
|
dom.documentElement.insertBefore(frag, None)
|
||||||
self.confirm(tuple(dom.documentElement.childNodes) ==
|
self.assertTupleEqual(tuple(dom.documentElement.childNodes),
|
||||||
(orig, c1, c2, c3),
|
(orig, c1, c2, c3),
|
||||||
"insertBefore(<fragment>, None)")
|
"insertBefore(<fragment>, None)")
|
||||||
frag.unlink()
|
frag.unlink()
|
||||||
|
@ -163,7 +163,7 @@ class MinidomTest(unittest.TestCase):
|
||||||
|
|
||||||
dom, orig, c1, c2, c3, frag = self._create_fragment_test_nodes()
|
dom, orig, c1, c2, c3, frag = self._create_fragment_test_nodes()
|
||||||
dom.documentElement.insertBefore(frag, orig)
|
dom.documentElement.insertBefore(frag, orig)
|
||||||
self.confirm(tuple(dom.documentElement.childNodes) ==
|
self.assertTupleEqual(tuple(dom.documentElement.childNodes),
|
||||||
(c1, c2, c3, orig),
|
(c1, c2, c3, orig),
|
||||||
"insertBefore(<fragment>, orig)")
|
"insertBefore(<fragment>, orig)")
|
||||||
frag.unlink()
|
frag.unlink()
|
||||||
|
@ -172,14 +172,14 @@ class MinidomTest(unittest.TestCase):
|
||||||
def testAppendChild(self):
|
def testAppendChild(self):
|
||||||
dom = parse(tstfile)
|
dom = parse(tstfile)
|
||||||
dom.documentElement.appendChild(dom.createComment("Hello"))
|
dom.documentElement.appendChild(dom.createComment("Hello"))
|
||||||
self.confirm(dom.documentElement.childNodes[-1].nodeName == "#comment")
|
self.assertEqual(dom.documentElement.childNodes[-1].nodeName, "#comment")
|
||||||
self.confirm(dom.documentElement.childNodes[-1].data == "Hello")
|
self.assertEqual(dom.documentElement.childNodes[-1].data, "Hello")
|
||||||
dom.unlink()
|
dom.unlink()
|
||||||
|
|
||||||
def testAppendChildFragment(self):
|
def testAppendChildFragment(self):
|
||||||
dom, orig, c1, c2, c3, frag = self._create_fragment_test_nodes()
|
dom, orig, c1, c2, c3, frag = self._create_fragment_test_nodes()
|
||||||
dom.documentElement.appendChild(frag)
|
dom.documentElement.appendChild(frag)
|
||||||
self.confirm(tuple(dom.documentElement.childNodes) ==
|
self.assertTupleEqual(tuple(dom.documentElement.childNodes),
|
||||||
(orig, c1, c2, c3),
|
(orig, c1, c2, c3),
|
||||||
"appendChild(<fragment>)")
|
"appendChild(<fragment>)")
|
||||||
frag.unlink()
|
frag.unlink()
|
||||||
|
@ -189,7 +189,7 @@ class MinidomTest(unittest.TestCase):
|
||||||
dom, orig, c1, c2, c3, frag = self._create_fragment_test_nodes()
|
dom, orig, c1, c2, c3, frag = self._create_fragment_test_nodes()
|
||||||
dom.documentElement.replaceChild(frag, orig)
|
dom.documentElement.replaceChild(frag, orig)
|
||||||
orig.unlink()
|
orig.unlink()
|
||||||
self.confirm(tuple(dom.documentElement.childNodes) == (c1, c2, c3),
|
self.assertTupleEqual(tuple(dom.documentElement.childNodes), (c1, c2, c3),
|
||||||
"replaceChild(<fragment>)")
|
"replaceChild(<fragment>)")
|
||||||
frag.unlink()
|
frag.unlink()
|
||||||
dom.unlink()
|
dom.unlink()
|
||||||
|
@ -221,22 +221,22 @@ class MinidomTest(unittest.TestCase):
|
||||||
attrs = elem.attributes
|
attrs = elem.attributes
|
||||||
attrs["foo"] = "bar"
|
attrs["foo"] = "bar"
|
||||||
a = attrs.item(0)
|
a = attrs.item(0)
|
||||||
self.confirm(a.ownerDocument is dom,
|
self.assertIs(a.ownerDocument, dom,
|
||||||
"NamedNodeMap.__setitem__() sets ownerDocument")
|
"NamedNodeMap.__setitem__() sets ownerDocument")
|
||||||
self.confirm(a.ownerElement is elem,
|
self.assertIs(a.ownerElement, elem,
|
||||||
"NamedNodeMap.__setitem__() sets ownerElement")
|
"NamedNodeMap.__setitem__() sets ownerElement")
|
||||||
self.confirm(a.value == "bar",
|
self.assertEqual(a.value, "bar",
|
||||||
"NamedNodeMap.__setitem__() sets value")
|
"NamedNodeMap.__setitem__() sets value")
|
||||||
self.confirm(a.nodeValue == "bar",
|
self.assertEqual(a.nodeValue, "bar",
|
||||||
"NamedNodeMap.__setitem__() sets nodeValue")
|
"NamedNodeMap.__setitem__() sets nodeValue")
|
||||||
elem.unlink()
|
elem.unlink()
|
||||||
dom.unlink()
|
dom.unlink()
|
||||||
|
|
||||||
def testNonZero(self):
|
def testNonZero(self):
|
||||||
dom = parse(tstfile)
|
dom = parse(tstfile)
|
||||||
self.confirm(dom)# should not be zero
|
self.assertTrue(dom) # should not be zero
|
||||||
dom.appendChild(dom.createComment("foo"))
|
dom.appendChild(dom.createComment("foo"))
|
||||||
self.confirm(not dom.childNodes[-1].childNodes)
|
self.assertFalse(dom.childNodes[-1].childNodes)
|
||||||
dom.unlink()
|
dom.unlink()
|
||||||
|
|
||||||
def testUnlink(self):
|
def testUnlink(self):
|
||||||
|
@ -253,18 +253,18 @@ class MinidomTest(unittest.TestCase):
|
||||||
def testElement(self):
|
def testElement(self):
|
||||||
dom = Document()
|
dom = Document()
|
||||||
dom.appendChild(dom.createElement("abc"))
|
dom.appendChild(dom.createElement("abc"))
|
||||||
self.confirm(dom.documentElement)
|
self.assertTrue(dom.documentElement)
|
||||||
dom.unlink()
|
dom.unlink()
|
||||||
|
|
||||||
def testAAA(self):
|
def testAAA(self):
|
||||||
dom = parseString("<abc/>")
|
dom = parseString("<abc/>")
|
||||||
el = dom.documentElement
|
el = dom.documentElement
|
||||||
el.setAttribute("spam", "jam2")
|
el.setAttribute("spam", "jam2")
|
||||||
self.confirm(el.toxml() == '<abc spam="jam2"/>', "testAAA")
|
self.assertEqual(el.toxml(), '<abc spam="jam2"/>', "testAAA")
|
||||||
a = el.getAttributeNode("spam")
|
a = el.getAttributeNode("spam")
|
||||||
self.confirm(a.ownerDocument is dom,
|
self.assertIs(a.ownerDocument, dom,
|
||||||
"setAttribute() sets ownerDocument")
|
"setAttribute() sets ownerDocument")
|
||||||
self.confirm(a.ownerElement is dom.documentElement,
|
self.assertIs(a.ownerElement, dom.documentElement,
|
||||||
"setAttribute() sets ownerElement")
|
"setAttribute() sets ownerElement")
|
||||||
dom.unlink()
|
dom.unlink()
|
||||||
|
|
||||||
|
@ -273,7 +273,7 @@ class MinidomTest(unittest.TestCase):
|
||||||
el = dom.documentElement
|
el = dom.documentElement
|
||||||
el.setAttribute("spam", "jam")
|
el.setAttribute("spam", "jam")
|
||||||
el.setAttribute("spam", "jam2")
|
el.setAttribute("spam", "jam2")
|
||||||
self.confirm(el.toxml() == '<abc spam="jam2"/>', "testAAB")
|
self.assertEqual(el.toxml(), '<abc spam="jam2"/>', "testAAB")
|
||||||
dom.unlink()
|
dom.unlink()
|
||||||
|
|
||||||
def testAddAttr(self):
|
def testAddAttr(self):
|
||||||
|
@ -281,31 +281,31 @@ class MinidomTest(unittest.TestCase):
|
||||||
child = dom.appendChild(dom.createElement("abc"))
|
child = dom.appendChild(dom.createElement("abc"))
|
||||||
|
|
||||||
child.setAttribute("def", "ghi")
|
child.setAttribute("def", "ghi")
|
||||||
self.confirm(child.getAttribute("def") == "ghi")
|
self.assertEqual(child.getAttribute("def"), "ghi")
|
||||||
self.confirm(child.attributes["def"].value == "ghi")
|
self.assertEqual(child.attributes["def"].value, "ghi")
|
||||||
|
|
||||||
child.setAttribute("jkl", "mno")
|
child.setAttribute("jkl", "mno")
|
||||||
self.confirm(child.getAttribute("jkl") == "mno")
|
self.assertEqual(child.getAttribute("jkl"), "mno")
|
||||||
self.confirm(child.attributes["jkl"].value == "mno")
|
self.assertEqual(child.attributes["jkl"].value, "mno")
|
||||||
|
|
||||||
self.confirm(len(child.attributes) == 2)
|
self.assertEqual(len(child.attributes), 2)
|
||||||
|
|
||||||
child.setAttribute("def", "newval")
|
child.setAttribute("def", "newval")
|
||||||
self.confirm(child.getAttribute("def") == "newval")
|
self.assertEqual(child.getAttribute("def"), "newval")
|
||||||
self.confirm(child.attributes["def"].value == "newval")
|
self.assertEqual(child.attributes["def"].value, "newval")
|
||||||
|
|
||||||
self.confirm(len(child.attributes) == 2)
|
self.assertEqual(len(child.attributes), 2)
|
||||||
dom.unlink()
|
dom.unlink()
|
||||||
|
|
||||||
def testDeleteAttr(self):
|
def testDeleteAttr(self):
|
||||||
dom = Document()
|
dom = Document()
|
||||||
child = dom.appendChild(dom.createElement("abc"))
|
child = dom.appendChild(dom.createElement("abc"))
|
||||||
|
|
||||||
self.confirm(len(child.attributes) == 0)
|
self.assertEqual(len(child.attributes), 0)
|
||||||
child.setAttribute("def", "ghi")
|
child.setAttribute("def", "ghi")
|
||||||
self.confirm(len(child.attributes) == 1)
|
self.assertEqual(len(child.attributes), 1)
|
||||||
del child.attributes["def"]
|
del child.attributes["def"]
|
||||||
self.confirm(len(child.attributes) == 0)
|
self.assertEqual(len(child.attributes), 0)
|
||||||
dom.unlink()
|
dom.unlink()
|
||||||
|
|
||||||
def testRemoveAttr(self):
|
def testRemoveAttr(self):
|
||||||
|
@ -313,10 +313,10 @@ class MinidomTest(unittest.TestCase):
|
||||||
child = dom.appendChild(dom.createElement("abc"))
|
child = dom.appendChild(dom.createElement("abc"))
|
||||||
|
|
||||||
child.setAttribute("def", "ghi")
|
child.setAttribute("def", "ghi")
|
||||||
self.confirm(len(child.attributes) == 1)
|
self.assertEqual(len(child.attributes), 1)
|
||||||
self.assertRaises(xml.dom.NotFoundErr, child.removeAttribute, "foo")
|
self.assertRaises(xml.dom.NotFoundErr, child.removeAttribute, "foo")
|
||||||
child.removeAttribute("def")
|
child.removeAttribute("def")
|
||||||
self.confirm(len(child.attributes) == 0)
|
self.assertEqual(len(child.attributes), 0)
|
||||||
dom.unlink()
|
dom.unlink()
|
||||||
|
|
||||||
def testRemoveAttrNS(self):
|
def testRemoveAttrNS(self):
|
||||||
|
@ -328,16 +328,16 @@ class MinidomTest(unittest.TestCase):
|
||||||
child.setAttributeNS("http://www.python.org", "python:abcattr", "foo")
|
child.setAttributeNS("http://www.python.org", "python:abcattr", "foo")
|
||||||
self.assertRaises(xml.dom.NotFoundErr, child.removeAttributeNS,
|
self.assertRaises(xml.dom.NotFoundErr, child.removeAttributeNS,
|
||||||
"foo", "http://www.python.org")
|
"foo", "http://www.python.org")
|
||||||
self.confirm(len(child.attributes) == 2)
|
self.assertEqual(len(child.attributes), 2)
|
||||||
child.removeAttributeNS("http://www.python.org", "abcattr")
|
child.removeAttributeNS("http://www.python.org", "abcattr")
|
||||||
self.confirm(len(child.attributes) == 1)
|
self.assertEqual(len(child.attributes), 1)
|
||||||
dom.unlink()
|
dom.unlink()
|
||||||
|
|
||||||
def testRemoveAttributeNode(self):
|
def testRemoveAttributeNode(self):
|
||||||
dom = Document()
|
dom = Document()
|
||||||
child = dom.appendChild(dom.createElement("foo"))
|
child = dom.appendChild(dom.createElement("foo"))
|
||||||
child.setAttribute("spam", "jam")
|
child.setAttribute("spam", "jam")
|
||||||
self.confirm(len(child.attributes) == 1)
|
self.assertEqual(len(child.attributes), 1)
|
||||||
node = child.getAttributeNode("spam")
|
node = child.getAttributeNode("spam")
|
||||||
self.assertRaises(xml.dom.NotFoundErr, child.removeAttributeNode,
|
self.assertRaises(xml.dom.NotFoundErr, child.removeAttributeNode,
|
||||||
None)
|
None)
|
||||||
|
@ -355,13 +355,13 @@ class MinidomTest(unittest.TestCase):
|
||||||
dom = Document()
|
dom = Document()
|
||||||
child = dom.appendChild(dom.createElement("foo"))
|
child = dom.appendChild(dom.createElement("foo"))
|
||||||
child.setAttribute("spam", "jam")
|
child.setAttribute("spam", "jam")
|
||||||
self.confirm(child.hasAttribute("spam"))
|
self.assertTrue(child.hasAttribute("spam"))
|
||||||
|
|
||||||
def testChangeAttr(self):
|
def testChangeAttr(self):
|
||||||
dom = parseString("<abc/>")
|
dom = parseString("<abc/>")
|
||||||
el = dom.documentElement
|
el = dom.documentElement
|
||||||
el.setAttribute("spam", "jam")
|
el.setAttribute("spam", "jam")
|
||||||
self.confirm(len(el.attributes) == 1)
|
self.assertEqual(len(el.attributes), 1)
|
||||||
el.setAttribute("spam", "bam")
|
el.setAttribute("spam", "bam")
|
||||||
# Set this attribute to be an ID and make sure that doesn't change
|
# Set this attribute to be an ID and make sure that doesn't change
|
||||||
# when changing the value:
|
# when changing the value:
|
||||||
|
@ -444,7 +444,7 @@ class MinidomTest(unittest.TestCase):
|
||||||
def get_empty_nodelist_from_elements_by_tagName_ns_helper(self, doc, nsuri,
|
def get_empty_nodelist_from_elements_by_tagName_ns_helper(self, doc, nsuri,
|
||||||
lname):
|
lname):
|
||||||
nodelist = doc.getElementsByTagNameNS(nsuri, lname)
|
nodelist = doc.getElementsByTagNameNS(nsuri, lname)
|
||||||
self.confirm(len(nodelist) == 0)
|
self.assertEqual(len(nodelist), 0)
|
||||||
|
|
||||||
def testGetEmptyNodeListFromElementsByTagNameNS(self):
|
def testGetEmptyNodeListFromElementsByTagNameNS(self):
|
||||||
doc = parseString('<doc/>')
|
doc = parseString('<doc/>')
|
||||||
|
@ -468,7 +468,7 @@ class MinidomTest(unittest.TestCase):
|
||||||
el = dom.appendChild(dom.createElement("abc"))
|
el = dom.appendChild(dom.createElement("abc"))
|
||||||
string1 = repr(el)
|
string1 = repr(el)
|
||||||
string2 = str(el)
|
string2 = str(el)
|
||||||
self.confirm(string1 == string2)
|
self.assertEqual(string1, string2)
|
||||||
dom.unlink()
|
dom.unlink()
|
||||||
|
|
||||||
def testElementReprAndStrUnicode(self):
|
def testElementReprAndStrUnicode(self):
|
||||||
|
@ -476,7 +476,7 @@ class MinidomTest(unittest.TestCase):
|
||||||
el = dom.appendChild(dom.createElement("abc"))
|
el = dom.appendChild(dom.createElement("abc"))
|
||||||
string1 = repr(el)
|
string1 = repr(el)
|
||||||
string2 = str(el)
|
string2 = str(el)
|
||||||
self.confirm(string1 == string2)
|
self.assertEqual(string1, string2)
|
||||||
dom.unlink()
|
dom.unlink()
|
||||||
|
|
||||||
def testElementReprAndStrUnicodeNS(self):
|
def testElementReprAndStrUnicodeNS(self):
|
||||||
|
@ -485,15 +485,15 @@ class MinidomTest(unittest.TestCase):
|
||||||
dom.createElementNS("http://www.slashdot.org", "slash:abc"))
|
dom.createElementNS("http://www.slashdot.org", "slash:abc"))
|
||||||
string1 = repr(el)
|
string1 = repr(el)
|
||||||
string2 = str(el)
|
string2 = str(el)
|
||||||
self.confirm(string1 == string2)
|
self.assertEqual(string1, string2)
|
||||||
self.confirm("slash:abc" in string1)
|
self.assertIn("slash:abc", string1)
|
||||||
dom.unlink()
|
dom.unlink()
|
||||||
|
|
||||||
def testAttributeRepr(self):
|
def testAttributeRepr(self):
|
||||||
dom = Document()
|
dom = Document()
|
||||||
el = dom.appendChild(dom.createElement("abc"))
|
el = dom.appendChild(dom.createElement("abc"))
|
||||||
node = el.setAttribute("abc", "def")
|
node = el.setAttribute("abc", "def")
|
||||||
self.confirm(str(node) == repr(node))
|
self.assertEqual(str(node), repr(node))
|
||||||
dom.unlink()
|
dom.unlink()
|
||||||
|
|
||||||
def testTextNodeRepr(self): pass
|
def testTextNodeRepr(self): pass
|
||||||
|
@ -503,7 +503,7 @@ class MinidomTest(unittest.TestCase):
|
||||||
dom = parseString(str)
|
dom = parseString(str)
|
||||||
domstr = dom.toxml()
|
domstr = dom.toxml()
|
||||||
dom.unlink()
|
dom.unlink()
|
||||||
self.confirm(str == domstr)
|
self.assertEqual(str, domstr)
|
||||||
|
|
||||||
def test_toxml_quote_text(self):
|
def test_toxml_quote_text(self):
|
||||||
dom = Document()
|
dom = Document()
|
||||||
|
@ -550,7 +550,7 @@ class MinidomTest(unittest.TestCase):
|
||||||
dom = parseString(str)
|
dom = parseString(str)
|
||||||
domstr = dom.toprettyxml(newl="\r\n")
|
domstr = dom.toprettyxml(newl="\r\n")
|
||||||
dom.unlink()
|
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):
|
def test_toprettyxml_with_text_nodes(self):
|
||||||
# see issue #4147, text nodes are not indented
|
# see issue #4147, text nodes are not indented
|
||||||
|
@ -643,7 +643,7 @@ class MinidomTest(unittest.TestCase):
|
||||||
attrs = e.attributes
|
attrs = e.attributes
|
||||||
a1 = e.getAttributeNode("a")
|
a1 = e.getAttributeNode("a")
|
||||||
a2 = attrs.removeNamedItem("a")
|
a2 = attrs.removeNamedItem("a")
|
||||||
self.confirm(a1.isSameNode(a2))
|
self.assertTrue(a1.isSameNode(a2))
|
||||||
self.assertRaises(xml.dom.NotFoundErr, attrs.removeNamedItem, "a")
|
self.assertRaises(xml.dom.NotFoundErr, attrs.removeNamedItem, "a")
|
||||||
|
|
||||||
def testRemoveNamedItemNS(self):
|
def testRemoveNamedItemNS(self):
|
||||||
|
@ -652,7 +652,7 @@ class MinidomTest(unittest.TestCase):
|
||||||
attrs = e.attributes
|
attrs = e.attributes
|
||||||
a1 = e.getAttributeNodeNS("http://xml.python.org/", "b")
|
a1 = e.getAttributeNodeNS("http://xml.python.org/", "b")
|
||||||
a2 = attrs.removeNamedItemNS("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,
|
self.assertRaises(xml.dom.NotFoundErr, attrs.removeNamedItemNS,
|
||||||
"http://xml.python.org/", "b")
|
"http://xml.python.org/", "b")
|
||||||
|
|
||||||
|
@ -695,7 +695,8 @@ class MinidomTest(unittest.TestCase):
|
||||||
keys2 = list(attrs2.keys())
|
keys2 = list(attrs2.keys())
|
||||||
keys1.sort()
|
keys1.sort()
|
||||||
keys2.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)):
|
for i in range(len(keys1)):
|
||||||
a1 = attrs1.item(i)
|
a1 = attrs1.item(i)
|
||||||
a2 = attrs2.item(i)
|
a2 = attrs2.item(i)
|
||||||
|
@ -705,7 +706,7 @@ class MinidomTest(unittest.TestCase):
|
||||||
and a1.namespaceURI == a2.namespaceURI
|
and a1.namespaceURI == a2.namespaceURI
|
||||||
and a1.localName == a2.localName
|
and a1.localName == a2.localName
|
||||||
, "clone of attribute node has proper attribute values")
|
, "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")
|
"clone of attribute node correctly owned")
|
||||||
|
|
||||||
def _setupCloneElement(self, deep):
|
def _setupCloneElement(self, deep):
|
||||||
|
@ -746,7 +747,7 @@ class MinidomTest(unittest.TestCase):
|
||||||
"]>\n"
|
"]>\n"
|
||||||
"<doc attr='value'/>")
|
"<doc attr='value'/>")
|
||||||
doc2 = doc.cloneNode(0)
|
doc2 = doc.cloneNode(0)
|
||||||
self.confirm(doc2 is None,
|
self.assertIsNone(doc2,
|
||||||
"testCloneDocumentShallow:"
|
"testCloneDocumentShallow:"
|
||||||
" shallow cloning of documents makes no sense!")
|
" shallow cloning of documents makes no sense!")
|
||||||
|
|
||||||
|
@ -758,22 +759,22 @@ class MinidomTest(unittest.TestCase):
|
||||||
"]>\n"
|
"]>\n"
|
||||||
"<doc attr='value'/>")
|
"<doc attr='value'/>")
|
||||||
doc2 = doc.cloneNode(1)
|
doc2 = doc.cloneNode(1)
|
||||||
self.confirm(not (doc.isSameNode(doc2) or doc2.isSameNode(doc)),
|
self.assertFalse((doc.isSameNode(doc2) or doc2.isSameNode(doc)),
|
||||||
"testCloneDocumentDeep: document objects not distinct")
|
"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")
|
"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")
|
"testCloneDocumentDeep: documentElement not an ELEMENT_NODE")
|
||||||
self.confirm(doc2.documentElement.ownerDocument.isSameNode(doc2),
|
self.assertTrue(doc2.documentElement.ownerDocument.isSameNode(doc2),
|
||||||
"testCloneDocumentDeep: documentElement owner is not new document")
|
"testCloneDocumentDeep: documentElement owner is not new document")
|
||||||
self.confirm(not doc.documentElement.isSameNode(doc2.documentElement),
|
self.assertFalse(doc.documentElement.isSameNode(doc2.documentElement),
|
||||||
"testCloneDocumentDeep: documentElement should not be shared")
|
"testCloneDocumentDeep: documentElement should not be shared")
|
||||||
if doc.doctype is not None:
|
if doc.doctype is not None:
|
||||||
# check the doctype iff the original DOM maintained it
|
# 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")
|
"testCloneDocumentDeep: doctype not a DOCUMENT_TYPE_NODE")
|
||||||
self.confirm(doc2.doctype.ownerDocument.isSameNode(doc2))
|
self.assertTrue(doc2.doctype.ownerDocument.isSameNode(doc2))
|
||||||
self.confirm(not doc.doctype.isSameNode(doc2.doctype))
|
self.assertFalse(doc.doctype.isSameNode(doc2.doctype))
|
||||||
|
|
||||||
def testCloneDocumentTypeDeepOk(self):
|
def testCloneDocumentTypeDeepOk(self):
|
||||||
doctype = create_nonempty_doctype()
|
doctype = create_nonempty_doctype()
|
||||||
|
@ -812,7 +813,7 @@ class MinidomTest(unittest.TestCase):
|
||||||
def testCloneDocumentTypeDeepNotOk(self):
|
def testCloneDocumentTypeDeepNotOk(self):
|
||||||
doc = create_doc_with_doctype()
|
doc = create_doc_with_doctype()
|
||||||
clone = doc.doctype.cloneNode(1)
|
clone = doc.doctype.cloneNode(1)
|
||||||
self.confirm(clone is None, "testCloneDocumentTypeDeepNotOk")
|
self.assertIsNone(clone)
|
||||||
|
|
||||||
def testCloneDocumentTypeShallowOk(self):
|
def testCloneDocumentTypeShallowOk(self):
|
||||||
doctype = create_nonempty_doctype()
|
doctype = create_nonempty_doctype()
|
||||||
|
@ -831,7 +832,7 @@ class MinidomTest(unittest.TestCase):
|
||||||
def testCloneDocumentTypeShallowNotOk(self):
|
def testCloneDocumentTypeShallowNotOk(self):
|
||||||
doc = create_doc_with_doctype()
|
doc = create_doc_with_doctype()
|
||||||
clone = doc.doctype.cloneNode(0)
|
clone = doc.doctype.cloneNode(0)
|
||||||
self.confirm(clone is None, "testCloneDocumentTypeShallowNotOk")
|
self.assertIsNone(clone)
|
||||||
|
|
||||||
def check_import_document(self, deep, testName):
|
def check_import_document(self, deep, testName):
|
||||||
doc1 = parseString("<doc/>")
|
doc1 = parseString("<doc/>")
|
||||||
|
@ -861,11 +862,11 @@ class MinidomTest(unittest.TestCase):
|
||||||
def check_clone_attribute(self, deep, testName):
|
def check_clone_attribute(self, deep, testName):
|
||||||
doc = parseString("<doc attr='value'/>")
|
doc = parseString("<doc attr='value'/>")
|
||||||
attr = doc.documentElement.getAttributeNode("attr")
|
attr = doc.documentElement.getAttributeNode("attr")
|
||||||
self.assertNotEqual(attr, None)
|
self.assertIsNotNone(attr)
|
||||||
clone = attr.cloneNode(deep)
|
clone = attr.cloneNode(deep)
|
||||||
self.confirm(not clone.isSameNode(attr))
|
self.assertFalse(clone.isSameNode(attr))
|
||||||
self.confirm(not attr.isSameNode(clone))
|
self.assertFalse(attr.isSameNode(clone))
|
||||||
self.confirm(clone.ownerElement is None,
|
self.assertIsNone(clone.ownerElement,
|
||||||
testName + ": ownerElement should be None")
|
testName + ": ownerElement should be None")
|
||||||
self.confirm(clone.ownerDocument.isSameNode(attr.ownerDocument),
|
self.confirm(clone.ownerDocument.isSameNode(attr.ownerDocument),
|
||||||
testName + ": ownerDocument does not match")
|
testName + ": ownerDocument does not match")
|
||||||
|
@ -1142,7 +1143,7 @@ class MinidomTest(unittest.TestCase):
|
||||||
node = doc.documentElement
|
node = doc.documentElement
|
||||||
node.childNodes[1].nodeValue = ""
|
node.childNodes[1].nodeValue = ""
|
||||||
node.normalize()
|
node.normalize()
|
||||||
self.confirm(node.childNodes[-1].nextSibling is None,
|
self.assertIsNone(node.childNodes[-1].nextSibling,
|
||||||
"Final child's .nextSibling should be None")
|
"Final child's .nextSibling should be None")
|
||||||
|
|
||||||
def testSiblings(self):
|
def testSiblings(self):
|
||||||
|
@ -1235,16 +1236,16 @@ class MinidomTest(unittest.TestCase):
|
||||||
def testUserData(self):
|
def testUserData(self):
|
||||||
dom = Document()
|
dom = Document()
|
||||||
n = dom.createElement('e')
|
n = dom.createElement('e')
|
||||||
self.confirm(n.getUserData("foo") is None)
|
self.assertIsNone(n.getUserData("foo"))
|
||||||
n.setUserData("foo", None, None)
|
n.setUserData("foo", None, None)
|
||||||
self.confirm(n.getUserData("foo") is None)
|
self.assertIsNone(n.getUserData("foo"))
|
||||||
n.setUserData("foo", 12, 12)
|
n.setUserData("foo", 12, 12)
|
||||||
n.setUserData("bar", 13, 13)
|
n.setUserData("bar", 13, 13)
|
||||||
self.confirm(n.getUserData("foo") == 12)
|
self.assertEqual(n.getUserData("foo"), 12)
|
||||||
self.confirm(n.getUserData("bar") == 13)
|
self.assertEqual(n.getUserData("bar"), 13)
|
||||||
n.setUserData("foo", None, None)
|
n.setUserData("foo", None, None)
|
||||||
self.confirm(n.getUserData("foo") is None)
|
self.assertIsNone(n.getUserData("foo"))
|
||||||
self.confirm(n.getUserData("bar") == 13)
|
self.assertEqual(n.getUserData("bar"), 13)
|
||||||
|
|
||||||
handler = self.UserDataHandler()
|
handler = self.UserDataHandler()
|
||||||
n.setUserData("bar", 12, handler)
|
n.setUserData("bar", 12, handler)
|
||||||
|
@ -1434,10 +1435,10 @@ class MinidomTest(unittest.TestCase):
|
||||||
doc = parseString("<doc><e/></doc>")
|
doc = parseString("<doc><e/></doc>")
|
||||||
elem = doc.documentElement
|
elem = doc.documentElement
|
||||||
e = elem.firstChild
|
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
|
# Check that replacing a child with itself leaves the tree unchanged
|
||||||
elem.replaceChild(e, e)
|
elem.replaceChild(e, e)
|
||||||
self.confirm(e.parentNode is elem, "After replaceChild()")
|
self.assertIs(e.parentNode, elem, "After replaceChild()")
|
||||||
|
|
||||||
def testReplaceWholeText(self):
|
def testReplaceWholeText(self):
|
||||||
def setup():
|
def setup():
|
||||||
|
@ -1454,13 +1455,13 @@ class MinidomTest(unittest.TestCase):
|
||||||
text = text1.replaceWholeText("new content")
|
text = text1.replaceWholeText("new content")
|
||||||
self.checkWholeText(text, "new content")
|
self.checkWholeText(text, "new content")
|
||||||
self.checkWholeText(text2, "d")
|
self.checkWholeText(text2, "d")
|
||||||
self.confirm(len(elem.childNodes) == 3)
|
self.assertEqual(len(elem.childNodes), 3)
|
||||||
|
|
||||||
doc, elem, text1, splitter, text2 = setup()
|
doc, elem, text1, splitter, text2 = setup()
|
||||||
text = text2.replaceWholeText("new content")
|
text = text2.replaceWholeText("new content")
|
||||||
self.checkWholeText(text, "new content")
|
self.checkWholeText(text, "new content")
|
||||||
self.checkWholeText(text1, "cab")
|
self.checkWholeText(text1, "cab")
|
||||||
self.confirm(len(elem.childNodes) == 5)
|
self.assertEqual(len(elem.childNodes), 5)
|
||||||
|
|
||||||
doc, elem, text1, splitter, text2 = setup()
|
doc, elem, text1, splitter, text2 = setup()
|
||||||
text = text1.replaceWholeText("")
|
text = text1.replaceWholeText("")
|
||||||
|
@ -1558,11 +1559,11 @@ class MinidomTest(unittest.TestCase):
|
||||||
a3 = doc.createAttributeNS(NS1, "a1")
|
a3 = doc.createAttributeNS(NS1, "a1")
|
||||||
a3.value = "v"
|
a3.value = "v"
|
||||||
e.setAttributeNode(a3)
|
e.setAttributeNode(a3)
|
||||||
self.confirm(e.isSameNode(doc.getElementById("w")))
|
self.assertTrue(e.isSameNode(doc.getElementById("w")))
|
||||||
self.confirm(not a1.isId)
|
self.assertFalse(a1.isId)
|
||||||
self.confirm(a2.isId)
|
self.assertTrue(a2.isId)
|
||||||
self.confirm(not a3.isId)
|
self.assertFalse(a3.isId)
|
||||||
self.confirm(doc.getElementById("v") is None)
|
self.assertIsNone(doc.getElementById("v"))
|
||||||
# renaming an attribute should not affect its ID-ness:
|
# renaming an attribute should not affect its ID-ness:
|
||||||
doc.renameNode(a2, xml.dom.EMPTY_NAMESPACE, "an")
|
doc.renameNode(a2, xml.dom.EMPTY_NAMESPACE, "an")
|
||||||
self.confirm(e.isSameNode(doc.getElementById("w"))
|
self.confirm(e.isSameNode(doc.getElementById("w"))
|
||||||
|
@ -1594,11 +1595,11 @@ class MinidomTest(unittest.TestCase):
|
||||||
a3 = doc.createAttributeNS(NS1, "a1")
|
a3 = doc.createAttributeNS(NS1, "a1")
|
||||||
a3.value = "v"
|
a3.value = "v"
|
||||||
e.setAttributeNode(a3)
|
e.setAttributeNode(a3)
|
||||||
self.confirm(e.isSameNode(doc.getElementById("w")))
|
self.assertTrue(e.isSameNode(doc.getElementById("w")))
|
||||||
self.confirm(not a1.isId)
|
self.assertFalse(a1.isId)
|
||||||
self.confirm(a2.isId)
|
self.assertTrue(a2.isId)
|
||||||
self.confirm(not a3.isId)
|
self.assertFalse(a3.isId)
|
||||||
self.confirm(doc.getElementById("v") is None)
|
self.assertIsNone(doc.getElementById("v"))
|
||||||
# renaming an attribute should not affect its ID-ness:
|
# renaming an attribute should not affect its ID-ness:
|
||||||
doc.renameNode(a2, xml.dom.EMPTY_NAMESPACE, "an")
|
doc.renameNode(a2, xml.dom.EMPTY_NAMESPACE, "an")
|
||||||
self.confirm(e.isSameNode(doc.getElementById("w"))
|
self.confirm(e.isSameNode(doc.getElementById("w"))
|
||||||
|
@ -1663,7 +1664,7 @@ class MinidomTest(unittest.TestCase):
|
||||||
doc = parseString("<element xmlns=''>\n"
|
doc = parseString("<element xmlns=''>\n"
|
||||||
"<foo/>\n</element>")
|
"<foo/>\n</element>")
|
||||||
doc2 = parseString(doc.toxml())
|
doc2 = parseString(doc.toxml())
|
||||||
self.confirm(doc2.namespaceURI == xml.dom.EMPTY_NAMESPACE)
|
self.assertEqual(doc2.namespaceURI, xml.dom.EMPTY_NAMESPACE)
|
||||||
|
|
||||||
def testExceptionOnSpacesInXMLNSValue(self):
|
def testExceptionOnSpacesInXMLNSValue(self):
|
||||||
with self.assertRaises((ValueError, ExpatError)):
|
with self.assertRaises((ValueError, ExpatError)):
|
||||||
|
@ -1679,7 +1680,7 @@ class MinidomTest(unittest.TestCase):
|
||||||
num_children_before = len(doc.childNodes)
|
num_children_before = len(doc.childNodes)
|
||||||
doc.removeChild(doc.childNodes[0])
|
doc.removeChild(doc.childNodes[0])
|
||||||
num_children_after = len(doc.childNodes)
|
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):
|
def testProcessingInstructionNameError(self):
|
||||||
# wrong variable in .nodeValue property will
|
# wrong variable in .nodeValue property will
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue