def checkWholeText(self, node, s):
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):
doc = Document()
with open(tstfile, 'rb') as file:
dom = parse(file)
dom.unlink()
- self.confirm(isinstance(dom, Document))
+ self.assertIsInstance(dom, Document)
def testParseFromTextFile(self):
with open(tstfile, 'r', encoding='iso-8859-1') as file:
dom = parse(file)
dom.unlink()
- self.confirm(isinstance(dom, Document))
+ self.assertIsInstance(dom, Document)
def testAttrModeSetsParamsAsAttrs(self):
attr = Attr("qName", "namespaceURI", "localName", "prefix")
def testGetElementsByTagName(self):
dom = parse(tstfile)
- self.confirm(dom.getElementsByTagName("LI") == \
+ self.assertEqual(dom.getElementsByTagName("LI"),
dom.documentElement.getElementsByTagName("LI"))
dom.unlink()
def testInsertBeforeFragment(self):
dom, orig, c1, c2, c3, frag = self._create_fragment_test_nodes()
dom.documentElement.insertBefore(frag, None)
- self.confirm(tuple(dom.documentElement.childNodes) ==
+ self.assertTupleEqual(tuple(dom.documentElement.childNodes),
(orig, c1, c2, c3),
"insertBefore(<fragment>, None)")
frag.unlink()
dom, orig, c1, c2, c3, frag = self._create_fragment_test_nodes()
dom.documentElement.insertBefore(frag, orig)
- self.confirm(tuple(dom.documentElement.childNodes) ==
+ self.assertTupleEqual(tuple(dom.documentElement.childNodes),
(c1, c2, c3, orig),
"insertBefore(<fragment>, orig)")
frag.unlink()
def testAppendChild(self):
dom = parse(tstfile)
dom.documentElement.appendChild(dom.createComment("Hello"))
- self.confirm(dom.documentElement.childNodes[-1].nodeName == "#comment")
- self.confirm(dom.documentElement.childNodes[-1].data == "Hello")
+ self.assertEqual(dom.documentElement.childNodes[-1].nodeName, "#comment")
+ self.assertEqual(dom.documentElement.childNodes[-1].data, "Hello")
dom.unlink()
def testAppendChildFragment(self):
dom, orig, c1, c2, c3, frag = self._create_fragment_test_nodes()
dom.documentElement.appendChild(frag)
- self.confirm(tuple(dom.documentElement.childNodes) ==
+ self.assertTupleEqual(tuple(dom.documentElement.childNodes),
(orig, c1, c2, c3),
"appendChild(<fragment>)")
frag.unlink()
dom, orig, c1, c2, c3, frag = self._create_fragment_test_nodes()
dom.documentElement.replaceChild(frag, orig)
orig.unlink()
- self.confirm(tuple(dom.documentElement.childNodes) == (c1, c2, c3),
+ self.assertTupleEqual(tuple(dom.documentElement.childNodes), (c1, c2, c3),
"replaceChild(<fragment>)")
frag.unlink()
dom.unlink()
attrs = elem.attributes
attrs["foo"] = "bar"
a = attrs.item(0)
- self.confirm(a.ownerDocument is dom,
+ self.assertIs(a.ownerDocument, dom,
"NamedNodeMap.__setitem__() sets ownerDocument")
- self.confirm(a.ownerElement is elem,
+ self.assertIs(a.ownerElement, elem,
"NamedNodeMap.__setitem__() sets ownerElement")
- self.confirm(a.value == "bar",
+ self.assertEqual(a.value, "bar",
"NamedNodeMap.__setitem__() sets value")
- self.confirm(a.nodeValue == "bar",
+ self.assertEqual(a.nodeValue, "bar",
"NamedNodeMap.__setitem__() sets nodeValue")
elem.unlink()
dom.unlink()
def testNonZero(self):
dom = parse(tstfile)
- self.confirm(dom)# should not be zero
+ self.assertTrue(dom) # should not be zero
dom.appendChild(dom.createComment("foo"))
- self.confirm(not dom.childNodes[-1].childNodes)
+ self.assertFalse(dom.childNodes[-1].childNodes)
dom.unlink()
def testUnlink(self):
def testElement(self):
dom = Document()
dom.appendChild(dom.createElement("abc"))
- self.confirm(dom.documentElement)
+ self.assertTrue(dom.documentElement)
dom.unlink()
def testAAA(self):
dom = parseString("<abc/>")
el = dom.documentElement
el.setAttribute("spam", "jam2")
- self.confirm(el.toxml() == '<abc spam="jam2"/>', "testAAA")
+ self.assertEqual(el.toxml(), '<abc spam="jam2"/>', "testAAA")
a = el.getAttributeNode("spam")
- self.confirm(a.ownerDocument is dom,
+ self.assertIs(a.ownerDocument, dom,
"setAttribute() sets ownerDocument")
- self.confirm(a.ownerElement is dom.documentElement,
+ self.assertIs(a.ownerElement, dom.documentElement,
"setAttribute() sets ownerElement")
dom.unlink()
el = dom.documentElement
el.setAttribute("spam", "jam")
el.setAttribute("spam", "jam2")
- self.confirm(el.toxml() == '<abc spam="jam2"/>', "testAAB")
+ self.assertEqual(el.toxml(), '<abc spam="jam2"/>', "testAAB")
dom.unlink()
def testAddAttr(self):
child = dom.appendChild(dom.createElement("abc"))
child.setAttribute("def", "ghi")
- self.confirm(child.getAttribute("def") == "ghi")
- self.confirm(child.attributes["def"].value == "ghi")
+ self.assertEqual(child.getAttribute("def"), "ghi")
+ self.assertEqual(child.attributes["def"].value, "ghi")
child.setAttribute("jkl", "mno")
- self.confirm(child.getAttribute("jkl") == "mno")
- self.confirm(child.attributes["jkl"].value == "mno")
+ self.assertEqual(child.getAttribute("jkl"), "mno")
+ self.assertEqual(child.attributes["jkl"].value, "mno")
- self.confirm(len(child.attributes) == 2)
+ self.assertEqual(len(child.attributes), 2)
child.setAttribute("def", "newval")
- self.confirm(child.getAttribute("def") == "newval")
- self.confirm(child.attributes["def"].value == "newval")
+ self.assertEqual(child.getAttribute("def"), "newval")
+ self.assertEqual(child.attributes["def"].value, "newval")
- self.confirm(len(child.attributes) == 2)
+ self.assertEqual(len(child.attributes), 2)
dom.unlink()
def testDeleteAttr(self):
dom = Document()
child = dom.appendChild(dom.createElement("abc"))
- self.confirm(len(child.attributes) == 0)
+ self.assertEqual(len(child.attributes), 0)
child.setAttribute("def", "ghi")
- self.confirm(len(child.attributes) == 1)
+ self.assertEqual(len(child.attributes), 1)
del child.attributes["def"]
- self.confirm(len(child.attributes) == 0)
+ self.assertEqual(len(child.attributes), 0)
dom.unlink()
def testRemoveAttr(self):
child = dom.appendChild(dom.createElement("abc"))
child.setAttribute("def", "ghi")
- self.confirm(len(child.attributes) == 1)
+ self.assertEqual(len(child.attributes), 1)
self.assertRaises(xml.dom.NotFoundErr, child.removeAttribute, "foo")
child.removeAttribute("def")
- self.confirm(len(child.attributes) == 0)
+ self.assertEqual(len(child.attributes), 0)
dom.unlink()
def testRemoveAttrNS(self):
child.setAttributeNS("http://www.python.org", "python:abcattr", "foo")
self.assertRaises(xml.dom.NotFoundErr, child.removeAttributeNS,
"foo", "http://www.python.org")
- self.confirm(len(child.attributes) == 2)
+ self.assertEqual(len(child.attributes), 2)
child.removeAttributeNS("http://www.python.org", "abcattr")
- self.confirm(len(child.attributes) == 1)
+ self.assertEqual(len(child.attributes), 1)
dom.unlink()
def testRemoveAttributeNode(self):
dom = Document()
child = dom.appendChild(dom.createElement("foo"))
child.setAttribute("spam", "jam")
- self.confirm(len(child.attributes) == 1)
+ self.assertEqual(len(child.attributes), 1)
node = child.getAttributeNode("spam")
self.assertRaises(xml.dom.NotFoundErr, child.removeAttributeNode,
None)
dom = Document()
child = dom.appendChild(dom.createElement("foo"))
child.setAttribute("spam", "jam")
- self.confirm(child.hasAttribute("spam"))
+ self.assertTrue(child.hasAttribute("spam"))
def testChangeAttr(self):
dom = parseString("<abc/>")
el = dom.documentElement
el.setAttribute("spam", "jam")
- self.confirm(len(el.attributes) == 1)
+ self.assertEqual(len(el.attributes), 1)
el.setAttribute("spam", "bam")
# Set this attribute to be an ID and make sure that doesn't change
# when changing the value:
def get_empty_nodelist_from_elements_by_tagName_ns_helper(self, doc, nsuri,
lname):
nodelist = doc.getElementsByTagNameNS(nsuri, lname)
- self.confirm(len(nodelist) == 0)
+ self.assertEqual(len(nodelist), 0)
def testGetEmptyNodeListFromElementsByTagNameNS(self):
doc = parseString('<doc/>')
el = dom.appendChild(dom.createElement("abc"))
string1 = repr(el)
string2 = str(el)
- self.confirm(string1 == string2)
+ self.assertEqual(string1, string2)
dom.unlink()
def testElementReprAndStrUnicode(self):
el = dom.appendChild(dom.createElement("abc"))
string1 = repr(el)
string2 = str(el)
- self.confirm(string1 == string2)
+ self.assertEqual(string1, string2)
dom.unlink()
def testElementReprAndStrUnicodeNS(self):
dom.createElementNS("http://www.slashdot.org", "slash:abc"))
string1 = repr(el)
string2 = str(el)
- self.confirm(string1 == string2)
- self.confirm("slash:abc" in string1)
+ self.assertEqual(string1, string2)
+ self.assertIn("slash:abc", string1)
dom.unlink()
def testAttributeRepr(self):
dom = Document()
el = dom.appendChild(dom.createElement("abc"))
node = el.setAttribute("abc", "def")
- self.confirm(str(node) == repr(node))
+ self.assertEqual(str(node), repr(node))
dom.unlink()
def testTextNodeRepr(self): pass
dom = parseString(str)
domstr = dom.toxml()
dom.unlink()
- self.confirm(str == domstr)
+ self.assertEqual(str, domstr)
def test_toxml_quote_text(self):
dom = Document()
dom = parseString(str)
domstr = dom.toprettyxml(newl="\r\n")
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):
# see issue #4147, text nodes are not indented
attrs = e.attributes
a1 = e.getAttributeNode("a")
a2 = attrs.removeNamedItem("a")
- self.confirm(a1.isSameNode(a2))
+ self.assertTrue(a1.isSameNode(a2))
self.assertRaises(xml.dom.NotFoundErr, attrs.removeNamedItem, "a")
def testRemoveNamedItemNS(self):
attrs = e.attributes
a1 = e.getAttributeNodeNS("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,
"http://xml.python.org/", "b")
keys2 = list(attrs2.keys())
keys1.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)):
a1 = attrs1.item(i)
a2 = attrs2.item(i)
and a1.namespaceURI == a2.namespaceURI
and a1.localName == a2.localName
, "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")
def _setupCloneElement(self, deep):
"]>\n"
"<doc attr='value'/>")
doc2 = doc.cloneNode(0)
- self.confirm(doc2 is None,
+ self.assertIsNone(doc2,
"testCloneDocumentShallow:"
" shallow cloning of documents makes no sense!")
"]>\n"
"<doc attr='value'/>")
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")
- self.confirm(len(doc.childNodes) == len(doc2.childNodes),
+ self.assertEqual(len(doc.childNodes), len(doc2.childNodes),
"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")
- self.confirm(doc2.documentElement.ownerDocument.isSameNode(doc2),
+ self.assertTrue(doc2.documentElement.ownerDocument.isSameNode(doc2),
"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")
if doc.doctype is not None:
# 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")
- self.confirm(doc2.doctype.ownerDocument.isSameNode(doc2))
- self.confirm(not doc.doctype.isSameNode(doc2.doctype))
+ self.assertTrue(doc2.doctype.ownerDocument.isSameNode(doc2))
+ self.assertFalse(doc.doctype.isSameNode(doc2.doctype))
def testCloneDocumentTypeDeepOk(self):
doctype = create_nonempty_doctype()
def testCloneDocumentTypeDeepNotOk(self):
doc = create_doc_with_doctype()
clone = doc.doctype.cloneNode(1)
- self.confirm(clone is None, "testCloneDocumentTypeDeepNotOk")
+ self.assertIsNone(clone)
def testCloneDocumentTypeShallowOk(self):
doctype = create_nonempty_doctype()
def testCloneDocumentTypeShallowNotOk(self):
doc = create_doc_with_doctype()
clone = doc.doctype.cloneNode(0)
- self.confirm(clone is None, "testCloneDocumentTypeShallowNotOk")
+ self.assertIsNone(clone)
def check_import_document(self, deep, testName):
doc1 = parseString("<doc/>")
def check_clone_attribute(self, deep, testName):
doc = parseString("<doc attr='value'/>")
attr = doc.documentElement.getAttributeNode("attr")
- self.assertNotEqual(attr, None)
+ self.assertIsNotNone(attr)
clone = attr.cloneNode(deep)
- self.confirm(not clone.isSameNode(attr))
- self.confirm(not attr.isSameNode(clone))
- self.confirm(clone.ownerElement is None,
+ self.assertFalse(clone.isSameNode(attr))
+ self.assertFalse(attr.isSameNode(clone))
+ self.assertIsNone(clone.ownerElement,
testName + ": ownerElement should be None")
self.confirm(clone.ownerDocument.isSameNode(attr.ownerDocument),
testName + ": ownerDocument does not match")
node = doc.documentElement
node.childNodes[1].nodeValue = ""
node.normalize()
- self.confirm(node.childNodes[-1].nextSibling is None,
+ self.assertIsNone(node.childNodes[-1].nextSibling,
"Final child's .nextSibling should be None")
def testSiblings(self):
def testUserData(self):
dom = Document()
n = dom.createElement('e')
- self.confirm(n.getUserData("foo") is None)
+ self.assertIsNone(n.getUserData("foo"))
n.setUserData("foo", None, None)
- self.confirm(n.getUserData("foo") is None)
+ self.assertIsNone(n.getUserData("foo"))
n.setUserData("foo", 12, 12)
n.setUserData("bar", 13, 13)
- self.confirm(n.getUserData("foo") == 12)
- self.confirm(n.getUserData("bar") == 13)
+ self.assertEqual(n.getUserData("foo"), 12)
+ self.assertEqual(n.getUserData("bar"), 13)
n.setUserData("foo", None, None)
- self.confirm(n.getUserData("foo") is None)
- self.confirm(n.getUserData("bar") == 13)
+ self.assertIsNone(n.getUserData("foo"))
+ self.assertEqual(n.getUserData("bar"), 13)
handler = self.UserDataHandler()
n.setUserData("bar", 12, handler)
doc = parseString("<doc><e/></doc>")
elem = doc.documentElement
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
elem.replaceChild(e, e)
- self.confirm(e.parentNode is elem, "After replaceChild()")
+ self.assertIs(e.parentNode, elem, "After replaceChild()")
def testReplaceWholeText(self):
def setup():
text = text1.replaceWholeText("new content")
self.checkWholeText(text, "new content")
self.checkWholeText(text2, "d")
- self.confirm(len(elem.childNodes) == 3)
+ self.assertEqual(len(elem.childNodes), 3)
doc, elem, text1, splitter, text2 = setup()
text = text2.replaceWholeText("new content")
self.checkWholeText(text, "new content")
self.checkWholeText(text1, "cab")
- self.confirm(len(elem.childNodes) == 5)
+ self.assertEqual(len(elem.childNodes), 5)
doc, elem, text1, splitter, text2 = setup()
text = text1.replaceWholeText("")
a3 = doc.createAttributeNS(NS1, "a1")
a3.value = "v"
e.setAttributeNode(a3)
- self.confirm(e.isSameNode(doc.getElementById("w")))
- self.confirm(not a1.isId)
- self.confirm(a2.isId)
- self.confirm(not a3.isId)
- self.confirm(doc.getElementById("v") is None)
+ self.assertTrue(e.isSameNode(doc.getElementById("w")))
+ self.assertFalse(a1.isId)
+ self.assertTrue(a2.isId)
+ self.assertFalse(a3.isId)
+ self.assertIsNone(doc.getElementById("v"))
# renaming an attribute should not affect its ID-ness:
doc.renameNode(a2, xml.dom.EMPTY_NAMESPACE, "an")
self.confirm(e.isSameNode(doc.getElementById("w"))
a3 = doc.createAttributeNS(NS1, "a1")
a3.value = "v"
e.setAttributeNode(a3)
- self.confirm(e.isSameNode(doc.getElementById("w")))
- self.confirm(not a1.isId)
- self.confirm(a2.isId)
- self.confirm(not a3.isId)
- self.confirm(doc.getElementById("v") is None)
+ self.assertTrue(e.isSameNode(doc.getElementById("w")))
+ self.assertFalse(a1.isId)
+ self.assertTrue(a2.isId)
+ self.assertFalse(a3.isId)
+ self.assertIsNone(doc.getElementById("v"))
# renaming an attribute should not affect its ID-ness:
doc.renameNode(a2, xml.dom.EMPTY_NAMESPACE, "an")
self.confirm(e.isSameNode(doc.getElementById("w"))
doc = parseString("<element xmlns=''>\n"
"<foo/>\n</element>")
doc2 = parseString(doc.toxml())
- self.confirm(doc2.namespaceURI == xml.dom.EMPTY_NAMESPACE)
+ self.assertEqual(doc2.namespaceURI, xml.dom.EMPTY_NAMESPACE)
def testExceptionOnSpacesInXMLNSValue(self):
with self.assertRaises((ValueError, ExpatError)):
num_children_before = len(doc.childNodes)
doc.removeChild(doc.childNodes[0])
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):
# wrong variable in .nodeValue property will