Lines Matching refs:self
56 def confirm(self, test, testname = "Test"):
57 self.assertTrue(test, testname)
59 def checkWholeText(self, node, s):
61 self.confirm(t == s, "looking for %r, found %r" % (s, t))
63 def testDocumentAsyncAttr(self):
65 self.assertFalse(doc.async_)
66 self.assertFalse(Document.async_)
68 def testParseFromBinaryFile(self):
72 self.confirm(isinstance(dom, Document))
74 def testParseFromTextFile(self):
78 self.confirm(isinstance(dom, Document))
80 def testAttrModeSetsParamsAsAttrs(self):
82 self.assertEqual(attr.name, "qName")
83 self.assertEqual(attr.namespaceURI, "namespaceURI")
84 self.assertEqual(attr.prefix, "prefix")
85 self.assertEqual(attr.localName, "localName")
87 def testAttrModeSetsNonOptionalAttrs(self):
89 self.assertEqual(attr.name, "qName")
90 self.assertEqual(attr.namespaceURI, "namespaceURI")
91 self.assertEqual(attr.prefix, "prefix")
92 self.assertEqual(attr.localName, attr.name)
94 def testGetElementsByTagName(self):
96 self.confirm(dom.getElementsByTagName("LI") == \
100 def testInsertBefore(self):
106 self.confirm(len(root.childNodes) == 2
118 self.confirm(len(root.childNodes) == 3
130 self.confirm(len(root.childNodes) == 4
143 def _create_fragment_test_nodes(self):
156 def testInsertBeforeFragment(self):
157 dom, orig, c1, c2, c3, frag = self._create_fragment_test_nodes()
159 self.confirm(tuple(dom.documentElement.childNodes) ==
165 dom, orig, c1, c2, c3, frag = self._create_fragment_test_nodes()
167 self.confirm(tuple(dom.documentElement.childNodes) ==
173 def testAppendChild(self):
176 self.confirm(dom.documentElement.childNodes[-1].nodeName == "#comment")
177 self.confirm(dom.documentElement.childNodes[-1].data == "Hello")
180 def testAppendChildFragment(self):
181 dom, orig, c1, c2, c3, frag = self._create_fragment_test_nodes()
183 self.confirm(tuple(dom.documentElement.childNodes) ==
189 def testReplaceChildFragment(self):
190 dom, orig, c1, c2, c3, frag = self._create_fragment_test_nodes()
193 self.confirm(tuple(dom.documentElement.childNodes) == (c1, c2, c3),
198 def testLegalChildren(self):
202 self.assertRaises(xml.dom.HierarchyRequestErr, dom.appendChild, text)
205 self.assertRaises(xml.dom.HierarchyRequestErr, dom.insertBefore, text,
207 self.assertRaises(xml.dom.HierarchyRequestErr, dom.replaceChild, text,
211 self.assertRaises(xml.dom.HierarchyRequestErr, nodemap.setNamedItem,
213 self.assertRaises(xml.dom.HierarchyRequestErr, nodemap.setNamedItemNS,
219 def testNamedNodeMapSetItem(self):
225 self.confirm(a.ownerDocument is dom,
227 self.confirm(a.ownerElement is elem,
229 self.confirm(a.value == "bar",
231 self.confirm(a.nodeValue == "bar",
236 def testNonZero(self):
238 self.confirm(dom)# should not be zero
240 self.confirm(not dom.childNodes[-1].childNodes)
243 def testUnlink(self):
245 self.assertTrue(dom.childNodes)
247 self.assertFalse(dom.childNodes)
249 def testContext(self):
251 self.assertTrue(dom.childNodes)
252 self.assertFalse(dom.childNodes)
254 def testElement(self):
257 self.confirm(dom.documentElement)
260 def testAAA(self):
264 self.confirm(el.toxml() == '<abc spam="jam2"/>', "testAAA")
266 self.confirm(a.ownerDocument is dom,
268 self.confirm(a.ownerElement is dom.documentElement,
272 def testAAB(self):
277 self.confirm(el.toxml() == '<abc spam="jam2"/>', "testAAB")
280 def testAddAttr(self):
285 self.confirm(child.getAttribute("def") == "ghi")
286 self.confirm(child.attributes["def"].value == "ghi")
289 self.confirm(child.getAttribute("jkl") == "mno")
290 self.confirm(child.attributes["jkl"].value == "mno")
292 self.confirm(len(child.attributes) == 2)
295 self.confirm(child.getAttribute("def") == "newval")
296 self.confirm(child.attributes["def"].value == "newval")
298 self.confirm(len(child.attributes) == 2)
301 def testDeleteAttr(self):
305 self.confirm(len(child.attributes) == 0)
307 self.confirm(len(child.attributes) == 1)
309 self.confirm(len(child.attributes) == 0)
312 def testRemoveAttr(self):
317 self.confirm(len(child.attributes) == 1)
318 self.assertRaises(xml.dom.NotFoundErr, child.removeAttribute, "foo")
320 self.confirm(len(child.attributes) == 0)
323 def testRemoveAttrNS(self):
330 self.assertRaises(xml.dom.NotFoundErr, child.removeAttributeNS,
332 self.confirm(len(child.attributes) == 2)
334 self.confirm(len(child.attributes) == 1)
337 def testRemoveAttributeNode(self):
341 self.confirm(len(child.attributes) == 1)
343 self.assertRaises(xml.dom.NotFoundErr, child.removeAttributeNode,
345 self.assertIs(node, child.removeAttributeNode(node))
346 self.confirm(len(child.attributes) == 0
351 self.assertRaises(xml.dom.NotFoundErr, child2.removeAttributeNode,
355 def testHasAttribute(self):
359 self.confirm(child.hasAttribute("spam"))
361 def testChangeAttr(self):
365 self.confirm(len(el.attributes) == 1)
370 self.confirm(len(el.attributes) == 1
376 self.confirm(len(el.attributes) == 1
382 self.confirm(len(el.attributes) == 2
390 self.confirm(len(el.attributes) == 2
399 def testGetAttrList(self):
402 def testGetAttrValues(self):
405 def testGetAttrLength(self):
408 def testGetAttribute(self):
412 self.assertEqual(child.getAttribute('missing'), '')
414 def testGetAttributeNS(self):
420 self.assertEqual(child.getAttributeNS("http://www.w3.org", "python"),
422 self.assertEqual(child.getAttributeNS("http://www.w3.org", "other"),
425 self.assertEqual(child2.getAttributeNS("http://www.python.org", "missing"),
428 def testGetAttributeNode(self): pass
430 def testGetElementsByTagNameNS(self):
437 self.confirm(len(elems) == 1
445 def get_empty_nodelist_from_elements_by_tagName_ns_helper(self, doc, nsuri,
448 self.confirm(len(nodelist) == 0)
450 def testGetEmptyNodeListFromElementsByTagNameNS(self):
452 self.get_empty_nodelist_from_elements_by_tagName_ns_helper(
454 self.get_empty_nodelist_from_elements_by_tagName_ns_helper(
456 self.get_empty_nodelist_from_elements_by_tagName_ns_helper(
460 self.get_empty_nodelist_from_elements_by_tagName_ns_helper(
462 self.get_empty_nodelist_from_elements_by_tagName_ns_helper(
464 self.get_empty_nodelist_from_elements_by_tagName_ns_helper(
467 def testElementReprAndStr(self):
472 self.confirm(string1 == string2)
475 def testElementReprAndStrUnicode(self):
480 self.confirm(string1 == string2)
483 def testElementReprAndStrUnicodeNS(self):
489 self.confirm(string1 == string2)
490 self.confirm("slash:abc" in string1)
493 def testAttributeRepr(self):
497 self.confirm(str(node) == repr(node))
500 def testTextNodeRepr(self): pass
502 def testWriteXML(self):
507 self.confirm(str == domstr)
509 def testAltNewline(self):
514 self.confirm(domstr == str.replace("\n", "\r\n"))
516 def test_toprettyxml_with_text_nodes(self):
519 self.assertEqual(parseString('<B>A</B>').toprettyxml(),
521 self.assertEqual(parseString('<C>A<B>A</B></C>').toprettyxml(),
523 self.assertEqual(parseString('<C><B>A</B>A</C>').toprettyxml(),
525 self.assertEqual(parseString('<C><B>A</B><B>A</B></C>').toprettyxml(),
527 self.assertEqual(parseString('<C><B>A</B>A<B>A</B></C>').toprettyxml(),
530 def test_toprettyxml_with_adjacent_text_nodes(self):
538 self.assertEqual(dom.toprettyxml(),
541 def test_toprettyxml_preserves_content_of_text_node(self):
546 self.assertEqual(
550 def testProcessingInstruction(self):
553 self.confirm(pi.target == "mypi"
565 def testProcessingInstructionRepr(self): pass
567 def testTextRepr(self): pass
569 def testWriteText(self): pass
571 def testDocumentElement(self): pass
573 def testTooManyDocumentElements(self):
577 self.assertRaises(xml.dom.HierarchyRequestErr, doc.appendChild, elem)
581 def testCreateElementNS(self): pass
583 def testCreateAttributeNS(self): pass
585 def testParse(self): pass
587 def testParseString(self): pass
589 def testComment(self): pass
591 def testAttrListItem(self): pass
593 def testAttrListItems(self): pass
595 def testAttrListItemNS(self): pass
597 def testAttrListKeys(self): pass
599 def testAttrListKeysNS(self): pass
601 def testRemoveNamedItem(self):
607 self.confirm(a1.isSameNode(a2))
608 self.assertRaises(xml.dom.NotFoundErr, attrs.removeNamedItem, "a")
610 def testRemoveNamedItemNS(self):
616 self.confirm(a1.isSameNode(a2))
617 self.assertRaises(xml.dom.NotFoundErr, attrs.removeNamedItemNS,
620 def testAttrListValues(self): pass
622 def testAttrListLength(self): pass
624 def testAttrList__getitem__(self): pass
626 def testAttrList__setitem__(self): pass
628 def testSetAttrValueandNodeValue(self): pass
630 def testParseElement(self): pass
632 def testParseAttributes(self): pass
634 def testParseElementNamespaces(self): pass
636 def testParseAttributeNamespaces(self): pass
638 def testParseProcessingInstructions(self): pass
640 def testChildNodes(self): pass
642 def testFirstChild(self): pass
644 def testHasChildNodes(self):
647 self.assertTrue(doc.hasChildNodes())
650 self.assertFalse(doc2.hasChildNodes())
652 def _testCloneElementCopiesAttributes(self, e1, e2, test):
659 self.confirm(keys1 == keys2, "clone of element has same attribute keys")
663 self.confirm(a1 is not a2
669 self.confirm(a2.ownerElement is e2,
672 def _setupCloneElement(self, deep):
676 self._testCloneElementCopiesAttributes(
684 def testCloneElementShallow(self):
685 dom, clone = self._setupCloneElement(0)
686 self.confirm(len(clone.childNodes) == 0
693 def testCloneElementDeep(self):
694 dom, clone = self._setupCloneElement(1)
695 self.confirm(len(clone.childNodes) == 1
702 def testCloneDocumentShallow(self):
710 self.confirm(doc2 is None,
714 def testCloneDocumentDeep(self):
722 self.confirm(not (doc.isSameNode(doc2) or doc2.isSameNode(doc)),
724 self.confirm(len(doc.childNodes) == len(doc2.childNodes),
726 self.confirm(doc2.documentElement.nodeType == Node.ELEMENT_NODE,
728 self.confirm(doc2.documentElement.ownerDocument.isSameNode(doc2),
730 self.confirm(not doc.documentElement.isSameNode(doc2.documentElement),
734 self.confirm(doc2.doctype.nodeType == Node.DOCUMENT_TYPE_NODE,
736 self.confirm(doc2.doctype.ownerDocument.isSameNode(doc2))
737 self.confirm(not doc.doctype.isSameNode(doc2.doctype))
739 def testCloneDocumentTypeDeepOk(self):
742 self.confirm(clone is not None
755 self.confirm((not se.isSameNode(ce))
767 self.confirm((not sn.isSameNode(cn))
773 def testCloneDocumentTypeDeepNotOk(self):
776 self.confirm(clone is None, "testCloneDocumentTypeDeepNotOk")
778 def testCloneDocumentTypeShallowOk(self):
781 self.confirm(clone is not None
792 def testCloneDocumentTypeShallowNotOk(self):
795 self.confirm(clone is None, "testCloneDocumentTypeShallowNotOk")
797 def check_import_document(self, deep, testName):
800 self.assertRaises(xml.dom.NotSupportedErr, doc1.importNode, doc2, deep)
802 def testImportDocumentShallow(self):
803 self.check_import_document(0, "testImportDocumentShallow")
805 def testImportDocumentDeep(self):
806 self.check_import_document(1, "testImportDocumentDeep")
808 def testImportDocumentTypeShallow(self):
811 self.assertRaises(xml.dom.NotSupportedErr, target.importNode,
814 def testImportDocumentTypeDeep(self):
817 self.assertRaises(xml.dom.NotSupportedErr, target.importNode,
822 def check_clone_attribute(self, deep, testName):
825 self.assertNotEqual(attr, None)
827 self.confirm(not clone.isSameNode(attr))
828 self.confirm(not attr.isSameNode(clone))
829 self.confirm(clone.ownerElement is None,
831 self.confirm(clone.ownerDocument.isSameNode(attr.ownerDocument),
833 self.confirm(clone.specified,
836 def testCloneAttributeShallow(self):
837 self.check_clone_attribute(0, "testCloneAttributeShallow")
839 def testCloneAttributeDeep(self):
840 self.check_clone_attribute(1, "testCloneAttributeDeep")
842 def check_clone_pi(self, deep, testName):
845 self.assertEqual(pi.nodeType, Node.PROCESSING_INSTRUCTION_NODE)
847 self.confirm(clone.target == pi.target
850 def testClonePIShallow(self):
851 self.check_clone_pi(0, "testClonePIShallow")
853 def testClonePIDeep(self):
854 self.check_clone_pi(1, "testClonePIDeep")
856 def check_clone_node_entity(self, clone_document):
869 def handle(self, operation, key, data, src, dst):
870 self.operation = operation
871 self.key = key
872 self.data = data
873 self.src = src
874 self.dst = dst
885 self.assertEqual(clone.documentElement.firstChild.wholeText,
897 self.assertEqual(handler.operation, operation)
898 self.assertEqual(handler.key, "key")
899 self.assertEqual(handler.data, "data")
900 self.assertIs(handler.src, entity)
901 self.assertIs(handler.dst, dst)
903 def testCloneNodeEntity(self):
904 self.check_clone_node_entity(False)
905 self.check_clone_node_entity(True)
907 def testNormalize(self):
912 self.confirm(len(root.childNodes) == 2
916 self.confirm(len(root.childNodes) == 1
927 self.confirm(len(root.childNodes) == 0
932 def testNormalizeCombineAndNextSibling(self):
938 self.confirm(len(root.childNodes) == 3
942 self.confirm(len(root.childNodes) == 2
953 def testNormalizeDeleteWithPrevSibling(self):
958 self.confirm(len(root.childNodes) == 2
962 self.confirm(len(root.childNodes) == 1
971 def testNormalizeDeleteWithNextSibling(self):
976 self.confirm(len(root.childNodes) == 2
980 self.confirm(len(root.childNodes) == 1
989 def testNormalizeDeleteWithTwoNonTextSiblings(self):
995 self.confirm(len(root.childNodes) == 3
999 self.confirm(len(root.childNodes) == 2
1009 def testNormalizeDeleteAndCombine(self):
1017 self.confirm(len(root.childNodes) == 5
1021 self.confirm(len(root.childNodes) == 1
1030 def testNormalizeRecursion(self):
1054 self.confirm(len(root.childNodes) == 3
1064 self.confirm(len(root.childNodes) == 2
1073 self.confirm(root.childNodes[0].childNodes[1].data == "tx"
1077 self.confirm(root.childNodes[0].childNodes[1].nextSibling is None
1093 def testBug0777884(self):
1096 self.assertEqual(text.nodeType, Node.TEXT_NODE)
1101 def testBug1433694(self):
1106 self.confirm(node.childNodes[-1].nextSibling is None,
1109 def testSiblings(self):
1114 self.confirm(pi.nextSibling is text and
1123 def testParents(self):
1131 self.confirm(root.parentNode is doc and
1138 def testNodeListItem(self):
1142 self.confirm(children[0] is children.item(0)
1150 def testEncodings(self):
1152 self.assertEqual(doc.toxml(),
1154 self.assertEqual(doc.toxml('utf-8'),
1156 self.assertEqual(doc.toxml('iso-8859-15'),
1158 self.assertEqual(doc.toxml('us-ascii'),
1160 self.assertEqual(doc.toxml('utf-16'),
1167 self.assertRaises(ExpatError, parseString,
1169 self.assertRaises(ExpatError, parseString,
1172 self.assertRaises(UnicodeDecodeError, parseString,
1177 def testStandalone(self):
1179 self.assertEqual(doc.toxml(),
1181 self.assertEqual(doc.toxml(standalone=None),
1183 self.assertEqual(doc.toxml(standalone=True),
1185 self.assertEqual(doc.toxml(standalone=False),
1187 self.assertEqual(doc.toxml('utf-8', True),
1195 def handle(self, operation, key, data, src, dst):
1196 dst.setUserData(key, data + 1, self)
1198 self.called = 1
1200 def testUserData(self):
1203 self.confirm(n.getUserData("foo") is None)
1205 self.confirm(n.getUserData("foo") is None)
1208 self.confirm(n.getUserData("foo") == 12)
1209 self.confirm(n.getUserData("bar") == 13)
1211 self.confirm(n.getUserData("foo") is None)
1212 self.confirm(n.getUserData("bar") == 13)
1214 handler = self.UserDataHandler()
1217 self.confirm(handler.called
1224 def checkRenameNodeSharedConstraints(self, doc, node):
1226 self.assertRaises(xml.dom.NamespaceErr, doc.renameNode, node,
1229 self.assertRaises(xml.dom.WrongDocumentErr, doc2.renameNode, node,
1232 def testRenameAttribute(self):
1240 self.confirm(attr.name == "b"
1254 self.confirm(attr.name == "c"
1270 self.confirm(attr.name == "p:d"
1289 self.confirm(attr.name == "e"
1304 self.assertRaises(xml.dom.NamespaceErr, doc.renameNode, attr,
1306 self.checkRenameNodeSharedConstraints(doc, attr)
1309 def testRenameElement(self):
1315 self.confirm(elem.tagName == "a"
1324 self.confirm(elem.tagName == "b"
1333 self.confirm(elem.tagName == "p:c"
1342 self.confirm(elem.tagName == "d"
1349 self.checkRenameNodeSharedConstraints(doc, elem)
1352 def testRenameOther(self):
1358 self.assertRaises(xml.dom.NotSupportedErr, doc.renameNode, node,
1362 def testWholeText(self):
1366 self.assertEqual(text.nodeType, Node.TEXT_NODE)
1368 self.checkWholeText(text, "a")
1370 self.checkWholeText(text, "ab")
1372 self.checkWholeText(text, "cab")
1379 self.checkWholeText(text, "cab")
1380 self.checkWholeText(text2, "d")
1385 self.checkWholeText(text, "cab")
1386 self.checkWholeText(text2, "d")
1391 self.checkWholeText(text, "cab")
1392 self.checkWholeText(text2, "d")
1395 self.checkWholeText(text, "cabd")
1396 self.checkWholeText(text2, "cabd")
1398 def testPatch1094164(self):
1402 self.confirm(e.parentNode is elem, "Before replaceChild()")
1405 self.confirm(e.parentNode is elem, "After replaceChild()")
1407 def testReplaceWholeText(self):
1420 self.checkWholeText(text, "new content")
1421 self.checkWholeText(text2, "d")
1422 self.confirm(len(elem.childNodes) == 3)
1426 self.checkWholeText(text, "new content")
1427 self.checkWholeText(text1, "cab")
1428 self.confirm(len(elem.childNodes) == 5)
1432 self.checkWholeText(text2, "d")
1433 self.confirm(text is None
1436 def testSchemaType(self):
1460 self.confirm(t.name is None
1466 self.confirm(hasattr(t, "name")
1469 def testSetIdAttribute(self):
1474 self.confirm(doc.getElementById("v") is None
1478 self.confirm(e.isSameNode(doc.getElementById("v"))
1482 self.confirm(e.isSameNode(doc.getElementById("v"))
1490 self.confirm(doc.getElementById("v") is None
1497 self.confirm(e.isSameNode(doc.getElementById("w"))
1500 def testSetIdAttributeNS(self):
1510 self.confirm(doc.getElementById("v") is None
1514 self.confirm(e.isSameNode(doc.getElementById("v"))
1518 self.confirm(e.isSameNode(doc.getElementById("v"))
1526 self.confirm(e.isSameNode(doc.getElementById("w")))
1527 self.confirm(not a1.isId)
1528 self.confirm(a2.isId)
1529 self.confirm(not a3.isId)
1530 self.confirm(doc.getElementById("v") is None)
1533 self.confirm(e.isSameNode(doc.getElementById("w"))
1536 def testSetIdAttributeNode(self):
1546 self.confirm(doc.getElementById("v") is None
1550 self.confirm(e.isSameNode(doc.getElementById("v"))
1554 self.confirm(e.isSameNode(doc.getElementById("v"))
1562 self.confirm(e.isSameNode(doc.getElementById("w")))
1563 self.confirm(not a1.isId)
1564 self.confirm(a2.isId)
1565 self.confirm(not a3.isId)
1566 self.confirm(doc.getElementById("v") is None)
1569 self.confirm(e.isSameNode(doc.getElementById("w"))
1572 def assert_recursive_equal(self, doc, doc2):
1576 self.assertEqual(n1.nodeType, n2.nodeType)
1577 self.assertEqual(len(n1.childNodes), len(n2.childNodes))
1578 self.assertEqual(n1.nodeName, n2.nodeName)
1579 self.assertFalse(n1.isSameNode(n2))
1580 self.assertFalse(n2.isSameNode(n1))
1586 self.assertEqual(len(n1.entities), len(n2.entities))
1587 self.assertEqual(len(n1.notations), len(n2.notations))
1592 self.assertEqual(no1.name, no2.name)
1593 self.assertEqual(no1.publicId, no2.publicId)
1594 self.assertEqual(no1.systemId, no2.systemId)
1599 self.assertEqual(e1.notationName, e2.notationName)
1600 self.assertEqual(e1.publicId, e2.publicId)
1601 self.assertEqual(e1.systemId, e2.systemId)
1604 self.assertTrue(n1.ownerDocument.isSameNode(doc))
1605 self.assertTrue(n2.ownerDocument.isSameNode(doc2))
1609 def testPickledDocument(self):
1614 self.assert_recursive_equal(doc, doc2)
1616 def testDeepcopiedDocument(self):
1619 self.assert_recursive_equal(doc, doc2)
1621 def testSerializeCommentNodeWithDoubleHyphen(self):
1624 self.assertRaises(ValueError, doc.toxml)
1627 def testEmptyXMLNSValue(self):
1631 self.confirm(doc2.namespaceURI == xml.dom.EMPTY_NAMESPACE)
1633 def testExceptionOnSpacesInXMLNSValue(self):
1635 context = self.assertRaisesRegex(ExpatError, 'syntax error')
1637 context = self.assertRaisesRegex(ValueError, 'Unsupported syntax')
1642 def testDocRemoveChild(self):
1645 self.assertRaises( xml.dom.NotFoundErr, doc.removeChild, title_tag)
1649 self.assertTrue(num_children_after == num_children_before - 1)
1651 def testProcessingInstructionNameError(self):
1658 def test_minidom_attribute_order(self):
1663 self.assertEqual(output.getvalue(), xml_str)
1665 def test_toxml_with_attributes_ordered(self):
1668 self.assertEqual(doc.toxml(), xml_str)
1670 def test_toprettyxml_with_attributes_ordered(self):
1673 self.assertEqual(doc.toprettyxml(),
1677 def test_toprettyxml_with_cdata(self):
1680 self.assertEqual(doc.toprettyxml(),
1686 def test_cdata_parsing(self):
1689 self.checkWholeText(dom1.getElementsByTagName('node')[0].firstChild, '</data>')
1691 self.checkWholeText(dom2.getElementsByTagName('node')[0].firstChild, '</data>')