MCPcopy Index your code
hub / github.com/python/cpython / testInsertBefore

Method testInsertBefore

Lib/test/test_minidom.py:99–137  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

97 dom.unlink()
98
99 def testInsertBefore(self):
100 dom = parseString("<doc><foo/></doc>")
101 root = dom.documentElement
102 elem = root.childNodes[0]
103 nelem = dom.createElement("element")
104 root.insertBefore(nelem, elem)
105 self.assertEqual(len(root.childNodes), 2)
106 self.assertEqual(root.childNodes.length, 2)
107 self.assertIs(root.childNodes[0], nelem)
108 self.assertIs(root.childNodes.item(0), nelem)
109 self.assertIs(root.childNodes[1], elem)
110 self.assertIs(root.childNodes.item(1), elem)
111 self.assertIs(root.firstChild, nelem)
112 self.assertIs(root.lastChild, elem)
113 self.assertEqual(root.toxml(), "<doc><element/><foo/></doc>")
114 nelem = dom.createElement("element")
115 root.insertBefore(nelem, None)
116 self.assertEqual(len(root.childNodes), 3)
117 self.assertEqual(root.childNodes.length, 3)
118 self.assertIs(root.childNodes[1], elem)
119 self.assertIs(root.childNodes.item(1), elem)
120 self.assertIs(root.childNodes[2], nelem)
121 self.assertIs(root.childNodes.item(2), nelem)
122 self.assertIs(root.lastChild, nelem)
123 self.assertIs(nelem.previousSibling, elem)
124 self.assertEqual(root.toxml(), "<doc><element/><foo/><element/></doc>")
125 nelem2 = dom.createElement("bar")
126 root.insertBefore(nelem2, nelem)
127 self.assertEqual(len(root.childNodes), 4)
128 self.assertEqual(root.childNodes.length, 4)
129 self.assertIs(root.childNodes[2], nelem2)
130 self.assertIs(root.childNodes.item(2), nelem2)
131 self.assertIs(root.childNodes[3], nelem)
132 self.assertIs(root.childNodes.item(3), nelem)
133 self.assertIs(nelem2.nextSibling, nelem)
134 self.assertIs(nelem.previousSibling, nelem2)
135 self.assertEqual(root.toxml(),
136 "<doc><element/><foo/><bar/><element/></doc>")
137 dom.unlink()
138
139 def _create_fragment_test_nodes(self):
140 dom = parseString("<doc/>")

Callers

nothing calls this directly

Calls 8

parseStringFunction · 0.90
createElementMethod · 0.80
toxmlMethod · 0.80
insertBeforeMethod · 0.45
assertEqualMethod · 0.45
assertIsMethod · 0.45
itemMethod · 0.45
unlinkMethod · 0.45

Tested by

no test coverage detected