Beispiel #1
0
    def testRemoveChild(self):
        n = Element("foo")
        n1 = Element("n1")
        n2 = Element("n2")
        n3 = Element("n3")
        n4 = Element("n4")

        n.appendChild(n1)
        n.appendChild(n2)
        n.appendChild(n3)
        n.appendChild(n4)
        self.assertEqual(getChildNames(n), ["n1", "n2", "n3", "n4"])

        n.removeChild(n3)
        self.assertEqual(getChildNames(n), ["n1", "n2", "n4"])

        n.removeChild(n4)
        self.assertEqual(getChildNames(n), ["n1", "n2"])

        self.assertIsNone(n.removeChild(n4))
        self.assertEqual(getChildNames(n), ["n1", "n2"])

        n5 = Element("n5")
        self.assertIsNone(n.removeChild(n5))
        self.assertEqual(getChildNames(n), ["n1", "n2"])

        n.removeChild(n1)
        self.assertEqual(getChildNames(n), ["n2"])

        n.removeChild(n2)
        self.assertEqual(getChildNames(n), [])
Beispiel #2
0
 def testChildren(self):
     n1 = Element("foo")
     n2 = Element("bar1")
     n3 = Element("bar2")
     n4 = Element("bar3")
     n1.appendChild(n2)
     n1.appendChild(n3)
     n1.appendChild(n4)
     self.assertEqual(getChildNames(n1), ["bar1", "bar2", "bar3"])
Beispiel #3
0
 def testAppendChild(self):
     doc = Document()
     n1 = Element(doc, "n1")
     n2 = Element(n1, "n2")
     n3 = Element(n2, "n3")
     self.assertEqual(getChildNames(doc), ["n1"])
     self.assertEqual(getChildNames(n1), ["n2"])
     self.assertEqual(getChildNames(n2), ["n3"])
     self.assertEqual(getChildNames(n3), [])
     n1.appendChild(n3)
     self.assertEqual(getChildNames(doc), ["n1"])
     self.assertEqual(getChildNames(n1), ["n2", "n3"])
     self.assertEqual(getChildNames(n2), [])
     self.assertEqual(getChildNames(n3), [])
Beispiel #4
0
    def testDocument(self):
        doc = Document()
        self.assertEqual(doc.document, doc)

        n1 = Element("foo")
        self.assertIsNone(n1.document)

        n2 = Element("bar")
        n1.appendChild(n2)
        self.assertIsNone(n1.document)
        self.assertIsNone(n2.document)

        doc.appendChild(n1)
        self.assertEqual(n1.document, doc)
        self.assertEqual(n2.document, doc)
Beispiel #5
0
    def testParentChildRelationships(self):
        n1 = Element("foo")
        self.assertIsNone(n1.parent)
        self.assertIsNone(n1.firstChild)
        self.assertIsNone(n1.lastChild)
        self.assertIsNone(n1.previousSibling)
        self.assertIsNone(n1.nextSibling)

        n2 = Element("bar")
        n3 = Element("bar")
        n4 = Element("bar")
        n1.appendChild(n2)
        n1.appendChild(n3)
        n1.appendChild(n4)

        self.assertEqual(n1.parent, None)
        self.assertEqual(n1.firstChild, n2)
        self.assertEqual(n1.lastChild, n4)
        self.assertEqual(n1.previousSibling, None)
        self.assertEqual(n1.nextSibling, None)

        self.assertEqual(n2.parent, n1)
        self.assertEqual(n2.firstChild, None)
        self.assertEqual(n2.lastChild, None)
        self.assertEqual(n2.previousSibling, None)
        self.assertEqual(n2.nextSibling, n3)

        self.assertEqual(n3.parent, n1)
        self.assertEqual(n3.firstChild, None)
        self.assertEqual(n3.lastChild, None)
        self.assertEqual(n3.previousSibling, n2)
        self.assertEqual(n3.nextSibling, n4)

        self.assertEqual(n4.parent, n1)
        self.assertEqual(n4.firstChild, None)
        self.assertEqual(n4.lastChild, None)
        self.assertEqual(n4.previousSibling, n3)
        self.assertEqual(n4.nextSibling, None)
Beispiel #6
0
 def testAppendChildDocument(self):
     element = Element("foo")
     document = Document()
     self.assertFalse(element.canAppendChild(document))
     self.assertIsNone(element.appendChild(document))
Beispiel #7
0
 def testAppendChild(self):
     node1 = Element("foo")
     node2 = Element("bar")
     self.assertTrue(node1.canAppendChild(node2))
     self.assertEqual(node1.appendChild(node2), node2)