[4suite-checkins] In 4Suite/test/Xml/Core,
files test_domlette_interfaces.py, test_domlette_memory.py,
test_saxlette.py
Jeremy Kloth
jkloth at 4suite.org
Wed Dec 20 23:13:39 MST 2006
Modified Files:
test_domlette_interfaces.py test_domlette_memory.py test_saxlette.py
Log Message:
- Domlette nodes no longer require an ownerDocument. This means now that
ownerDocument may be None for any or all Nodes if they have yet to be
appended to a tree rooted at a Document.
- Also in these changes, DocumentFragments have been removed as the Document
node type supports the same types of children that DocumentFragments did.
- Saxlette now fully supports the EntityResolver interface, and defaults
to the previous behavior of using the InputSource if no resolver has been
registered.
ViewCVS diff:
http://cvs.4suite.org/viewcvs/4Suite/test/Xml/Core/test_domlette_interfaces.py.diff?r1=1.19&r2=1.20
ViewCVS view:
http://cvs.4suite.org/viewcvs/4Suite/test/Xml/Core/test_domlette_interfaces.py?rev=1.20&content-type=text/vnd.viewcvs-markup
Index: test_domlette_interfaces.py
===================================================================
RCS file: /var/local/cvsroot/4Suite/test/Xml/Core/test_domlette_interfaces.py,v
retrieving revision 1.19
retrieving revision 1.20
diff -U2 -r1.19 -r1.20
--- test_domlette_interfaces.py 15 Sep 2006 16:53:29 -0000 1.19
+++ test_domlette_interfaces.py 21 Dec 2006 06:13:39 -0000 1.20
@@ -348,11 +348,11 @@
tester.startTest('createElementNS')
- elem = dom.createElementNS('http://foo.com','foo:bar')
- tester.compare(Node.ELEMENT_NODE,elem.nodeType)
- tester.compare('http://foo.com',elem.namespaceURI)
- tester.compare('foo',elem.prefix)
- tester.compare('bar',elem.localName)
- tester.compare('foo:bar',elem.nodeName)
- tester.compare(dom,elem.ownerDocument)
+ elem = dom.createElementNS('http://foo.com', 'foo:bar')
+ tester.compare(Node.ELEMENT_NODE, elem.nodeType)
+ tester.compare('http://foo.com', elem.namespaceURI)
+ tester.compare('foo', elem.prefix)
+ tester.compare('bar', elem.localName)
+ tester.compare('foo:bar', elem.nodeName)
+ tester.compare(None, elem.ownerDocument)
tester.testDone()
@@ -368,5 +368,5 @@
tester.compare('bar',attr.localName)
tester.compare('foo:bar',attr.nodeName)
- tester.compare(dom,attr.ownerDocument)
+ tester.compare(None, attr.ownerDocument)
tester.testDone()
@@ -379,6 +379,6 @@
text = dom.createTextNode('data')
tester.compare(Node.TEXT_NODE,text.nodeType)
- tester.compare('data',text.data)
- tester.compare(dom,text.ownerDocument)
+ tester.compare('data', text.data)
+ tester.compare(None, text.ownerDocument)
tester.testDone()
@@ -386,22 +386,16 @@
pi = dom.createProcessingInstruction('target','data')
tester.compare(Node.PROCESSING_INSTRUCTION_NODE,pi.nodeType)
- tester.compare('target',pi.target)
- tester.compare('data',pi.data)
- tester.compare(dom,pi.ownerDocument)
+ tester.compare('target', pi.target)
+ tester.compare('data', pi.data)
+ tester.compare(None, pi.ownerDocument)
tester.testDone()
tester.startTest('createComment')
- com = dom.createComment('data')
- tester.compare(Node.COMMENT_NODE,com.nodeType)
- tester.compare('data',com.data)
- tester.compare(dom,com.ownerDocument)
+ comment = dom.createComment('data')
+ tester.compare(Node.COMMENT_NODE, comment.nodeType)
+ tester.compare('data', comment.data)
+ tester.compare(None, comment.ownerDocument)
tester.testDone()
-## tester.startTest('createDocumentFragment')
-## df = dom.createDocumentFragment()
-## tester.compare(Node.DOCUMENT_FRAGMENT_NODE,df.nodeType)
-## tester.compare(dom,df.ownerDocument)
-## tester.testDone()
-
tester.groupDone()
@@ -438,42 +432,4 @@
tester.testDone()
-
-## tester.startTest("Append DF")
-## df = dom.createDocumentFragment()
-## elem3 = dom.createTextNode('data3')
-## elem4 = dom.createTextNode('data4')
-## df.appendChild(elem3)
-## df.appendChild(elem4)
-## child.appendChild(df)
-## tester.compare(4,len(child.childNodes))
-## tester.compare(elem4,child.lastChild)
-## tester.compare(elem2,elem3.previousSibling)
-## tester.compare(elem4,elem3.nextSibling)
-## tester.compare(elem3,elem4.previousSibling)
-## tester.compare(None,elem4.nextSibling)
-## tester.compare(child,elem3.parentNode)
-## tester.compare(child,elem4.parentNode)
-## tester.testDone()
-
-
-## tester.startTest("Append DF to empty")
-## root = dom.createElementNS(None,'foo')
-## df = dom.createDocumentFragment()
-## elem5 = dom.createTextNode('data5')
-## elem6 = dom.createTextNode('data6')
-## df.appendChild(elem5)
-## df.appendChild(elem6)
-## root.appendChild(df)
-## tester.compare(2,len(root.childNodes))
-## tester.compare(elem5,root.firstChild)
-## tester.compare(elem6,root.lastChild)
-## tester.compare(None,elem5.previousSibling)
-## tester.compare(elem6,elem5.nextSibling)
-## tester.compare(elem5,elem6.previousSibling)
-## tester.compare(None,elem6.nextSibling)
-## tester.compare(root,elem5.parentNode)
-## tester.compare(root,elem6.parentNode)
-## tester.testDone()
-
tester.startTest("Append New Element to a new document")
newdoc = dom.implementation.createDocument(None,None,None)
@@ -507,8 +463,8 @@
child.appendChild(t4)
child.normalize()
- tester.compare(5,len(child.childNodes))
- tester.compare("datadata2o",child.childNodes[0].data)
- tester.compare("tg",child.childNodes[2].data)
- tester.compare("h",child.childNodes[4].data)
+ tester.compare(5, len(child.childNodes), repr(child.childNodes))
+ tester.compare("datadata2o", child.childNodes[0].data)
+ tester.compare("tg", child.childNodes[2].data)
+ tester.compare("h", child.childNodes[4].data)
tester.testDone()
@@ -549,47 +505,4 @@
tester.testDone()
-## tester.startTest("DF Insert")
-## df = dom.createDocumentFragment()
-## elem3 = dom.createTextNode('data3')
-## elem4 = dom.createTextNode('data4')
-## df.appendChild(elem3)
-## df.appendChild(elem4)
-## child.insertBefore(df,elem)
-
-## tester.compare(4,len(child.childNodes))
-## tester.compare(child,elem3.parentNode)
-## tester.compare(child,elem4.parentNode)
-## tester.compare(elem2,child.firstChild)
-## tester.compare(elem,child.lastChild)
-
-## tester.compare(None,elem2.previousSibling)
-## tester.compare(elem3,elem2.nextSibling)
-## tester.compare(elem2,elem3.previousSibling)
-## tester.compare(elem4,elem3.nextSibling)
-## tester.compare(elem3,elem4.previousSibling)
-## tester.compare(elem,elem4.nextSibling)
-## tester.compare(elem4,elem.previousSibling)
-## tester.compare(None,elem.nextSibling)
-## tester.testDone()
-
-## tester.startTest("DF Insert on empty")
-## root = dom.createElementNS(None,'foo')
-## df = dom.createDocumentFragment()
-## elem5 = dom.createTextNode('data5')
-## elem6 = dom.createTextNode('data6')
-## df.appendChild(elem5)
-## df.appendChild(elem6)
-## root.insertBefore(df,None)
-## tester.compare(2,len(root.childNodes))
-## tester.compare(elem5,root.firstChild)
-## tester.compare(elem6,root.lastChild)
-## tester.compare(None,elem5.previousSibling)
-## tester.compare(elem6,elem5.nextSibling)
-## tester.compare(elem5,elem6.previousSibling)
-## tester.compare(None,elem6.nextSibling)
-## tester.compare(root,elem5.parentNode)
-## tester.compare(root,elem6.parentNode)
-## tester.testDone()
-
tester.startTest("Insert on empty doc")
newdoc = dom.implementation.createDocument(None,None,None)
@@ -928,13 +841,29 @@
doc = Domlette.implementation.createDocument(None,None,None)
- root = doc.createElementNS("http://foo.com","foo:import-root")
- root.setAttributeNS(None,"ID","15")
+ elem = doc.createElementNS("http://foo.com","foo:import-root")
+ attr = elem.setAttributeNS(None,"ID","15")
text = doc.createTextNode("Imported Text")
- root.appendChild(text)
+ elem.appendChild(text)
+
+ newElem = dom.importNode(elem, True)
- newRoot = dom.importNode(root,1)
+ tester.compare(None, newElem.ownerDocument)
+ tester.compare(elem.namespaceURI, newElem.namespaceURI, 'namespaceURI')
+ tester.compare(elem.tagName, newElem.tagName, 'tagName')
+ tester.compare(elem.prefix, newElem.prefix, 'prefix')
+ tester.compare(elem.localName, newElem.localName, 'localName')
+
+ tester.compare(len(elem.attributes), len(newElem.attributes), 'attributes')
+ newAttr = newElem.getAttributeNodeNS(None, 'ID')
+ tester.compare(attr.namespaceURI, newAttr.namespaceURI, 'namespaceURI')
+ tester.compare(attr.name, newAttr.name, 'name')
+ tester.compare(attr.prefix, newAttr.prefix, 'prefix')
+ tester.compare(attr.localName, newAttr.localName, 'localName')
+ tester.compare(attr.value, newAttr.value, 'value')
+
+ tester.compare(len(elem.childNodes), len(newElem.childNodes), 'childNodes')
+ newText = newElem.firstChild
+ tester.compare(text.data, newText.data, 'data')
- tester.compare(dom,newRoot.ownerDocument)
- tester.compare(dom,newRoot.childNodes[0].ownerDocument)
tester.testDone()
return
ViewCVS diff:
http://cvs.4suite.org/viewcvs/4Suite/test/Xml/Core/test_domlette_memory.py.diff?r1=1.7&r2=1.8
ViewCVS view:
http://cvs.4suite.org/viewcvs/4Suite/test/Xml/Core/test_domlette_memory.py?rev=1.8&content-type=text/vnd.viewcvs-markup
Index: test_domlette_memory.py
===================================================================
RCS file: /var/local/cvsroot/4Suite/test/Xml/Core/test_domlette_memory.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -U2 -r1.7 -r1.8
--- test_domlette_memory.py 15 Sep 2006 16:53:29 -0000 1.7
+++ test_domlette_memory.py 21 Dec 2006 06:13:39 -0000 1.8
@@ -22,5 +22,5 @@
class TestElement(Domlette.Element, TestNode):
def setAttributeNS(self, namespaceURI, qualifiedName, value):
- attr = TestAttr(self.ownerDocument, namespaceURI, qualifiedName)
+ attr = TestAttr(namespaceURI, qualifiedName)
self.setAttributeNodeNS(attr)
attr.value = value
@@ -39,7 +39,4 @@
pass
-class TestDocumentFragment(Domlette.DocumentFragment, TestNode):
- pass
-
def test_empty_node(tester,domMod):
tester.startTest("Empty Document")
@@ -54,5 +51,5 @@
StartNodeCounting()
doc = TestDocument()
- text = TestText(doc, "Foo")
+ text = TestText("Foo")
tester.compare(2, GetNodeCount())
del text
@@ -62,5 +59,5 @@
tester.startTest("Empty Element")
StartNodeCounting()
- elem = TestElement(doc, None,"Foo")
+ elem = TestElement(None,"Foo")
tester.compare(1, GetNodeCount())
del elem
@@ -70,5 +67,5 @@
tester.startTest("Empty Attribute")
StartNodeCounting()
- attr = TestAttr(doc, None,"Foo")
+ attr = TestAttr(None,"Foo")
tester.compare(1, GetNodeCount())
del attr
@@ -78,5 +75,5 @@
tester.startTest("Empty Comment")
StartNodeCounting()
- com = TestComment(doc, "Foo")
+ com = TestComment("Foo")
tester.compare(1, GetNodeCount())
del com
@@ -86,18 +83,10 @@
tester.startTest("Empty Processing Instruction")
StartNodeCounting()
- pi = TestProcessingInstruction(doc, "Foo", "Bar")
+ pi = TestProcessingInstruction("Foo", "Bar")
tester.compare(1, GetNodeCount())
del pi
tester.compare(0, GetNodeCount())
tester.testDone()
-
- tester.startTest("Empty Document Fragment")
- StartNodeCounting()
- df = TestDocumentFragment(doc)
- tester.compare(1, GetNodeCount())
- del df
- tester.compare(0, GetNodeCount())
- tester.testDone()
-
+ return
def test_small_tree(tester,domMod):
@@ -106,6 +95,6 @@
doc = TestDocument()
StartNodeCounting()
- elem = TestElement(doc, None, "Foo")
- elem2 = TestElement(doc, None, "Foo2")
+ elem = TestElement(None, "Foo")
+ elem2 = TestElement(None, "Foo2")
elem.appendChild(elem2)
tester.compare(2, GetNodeCount())
@@ -120,5 +109,5 @@
StartNodeCounting()
doc = TestDocument()
- elem = TestElement(doc, None, "Foo")
+ elem = TestElement(None, "Foo")
doc.appendChild(elem)
tester.compare(2, GetNodeCount())
@@ -132,5 +121,5 @@
StartNodeCounting()
doc = TestDocument()
- text = TestText(doc, "Foo")
+ text = TestText("Foo")
doc.appendChild(text)
tester.compare(2, GetNodeCount())
@@ -144,5 +133,5 @@
StartNodeCounting()
doc = TestDocument()
- pi = TestProcessingInstruction(doc, "Foo", "Bar")
+ pi = TestProcessingInstruction("Foo", "Bar")
doc.appendChild(pi)
tester.compare(2, GetNodeCount())
@@ -156,5 +145,5 @@
StartNodeCounting()
doc = TestDocument()
- com = TestComment(doc, "Foo")
+ com = TestComment("Foo")
doc.appendChild(com)
tester.compare(2, GetNodeCount())
@@ -165,23 +154,4 @@
tester.testDone()
-def test_df_tree(tester,domMod):
- gc.collect() #Force to clean everything up
- tester.startTest("Document Fragment Tree")
- doc = TestDocument()
- StartNodeCounting()
- df = TestDocumentFragment(doc)
- elem = TestElement(doc, None, "Foo")
- elem2 = TestElement(doc, None, "Foo2")
- df.appendChild(elem)
- df.appendChild(elem2)
- tester.compare(3, GetNodeCount())
- del elem
- del elem2
- del df
- gc.collect() #Force collection
- tester.compare(0, GetNodeCount())
- tester.testDone()
-
-
def test_attributes(tester,domMod):
gc.collect() #Force to clean everything up
@@ -189,6 +159,6 @@
doc = TestDocument()
StartNodeCounting()
- elem = TestElement(doc, None, "Foo")
- attr = TestAttr(doc, None, "Foo")
+ elem = TestElement(None, "Foo")
+ attr = TestAttr(None, "Foo")
elem.setAttributeNodeNS(attr)
tester.compare(2, GetNodeCount())
@@ -202,5 +172,5 @@
doc = TestDocument()
StartNodeCounting()
- elem = TestElement(doc, None, "Foo")
+ elem = TestElement(None, "Foo")
elem.setAttributeNS(None, "Foo", "Bar")
tester.compare(2, GetNodeCount())
@@ -216,5 +186,4 @@
test_empty_node(tester,domMod)
test_small_tree(tester,domMod)
- test_df_tree(tester,domMod)
test_attributes(tester,domMod)
tester.groupDone()
@@ -224,12 +193,5 @@
def TestRefCounts(tester, document):
from sys import getrefcount
- def node_refcounts(node, expected):
- if isinstance(node, Domlette.Element):
- # test element's children
- for child in node:
- expected = node_refcounts(child, expected)
- # test element's attributes
- for attr in node.attributes.itervalues():
- expected = node_refcounts(attr, expected)
+ def node_refcounts(node):
# Reference count:
# +1 for getrefcount() argument
@@ -238,7 +200,17 @@
# +1 for outer binding
# +1 for local binding
+ expected = 5
+ if isinstance(node, Domlette.Element):
+ # test the element's children
+ for child in node:
+ node_refcounts(child)
+ expected += 1
+ # test the element's attributes
+ for attr in node.attributes.itervalues():
+ node_refcounts(attr)
+ expected += 1
msg = node.__class__.__name__ + ' refcounts'
- tester.compare(5, getrefcount(node), msg)
- return expected + 1
+ tester.compare(expected, getrefcount(node), msg)
+ return
# Reference count:
@@ -249,5 +221,6 @@
expected = 4
for node in document:
- expected = node_refcounts(node, expected)
+ node_refcounts(node)
+ expected += 1
msg = document.__class__.__name__ + ' refcounts'
tester.compare(expected, getrefcount(document), msg)
@@ -274,16 +247,16 @@
doc = TestDocument()
- elem = TestElement(doc, 'http://foo.com', 'foo:root')
+ elem = TestElement('http://foo.com', 'foo:root')
doc.appendChild(elem)
- text = TestText(doc, "Data1")
+ text = TestText("Data1")
elem.appendChild(text)
del text
- pi = TestProcessingInstruction(doc, "tar", "Data3")
+ pi = TestProcessingInstruction("tar", "Data3")
doc.insertBefore(pi, elem)
del pi
- comment = TestComment(doc, "Data2")
+ comment = TestComment("Data2")
doc.appendChild(comment)
del comment
- elem2 = TestElement(doc, 'http://foo2.com', 'foo2:child')
+ elem2 = TestElement('http://foo2.com', 'foo2:child')
elem2.setAttributeNS('http://foo2.com', 'foo2:attr', 'value')
elem.appendChild(elem2)
ViewCVS diff:
http://cvs.4suite.org/viewcvs/4Suite/test/Xml/Core/test_saxlette.py.diff?r1=1.4&r2=1.5
ViewCVS view:
http://cvs.4suite.org/viewcvs/4Suite/test/Xml/Core/test_saxlette.py?rev=1.5&content-type=text/vnd.viewcvs-markup
Index: test_saxlette.py
===================================================================
RCS file: /var/local/cvsroot/4Suite/test/Xml/Core/test_saxlette.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -U2 -r1.4 -r1.5
--- test_saxlette.py 2 Jan 2006 18:53:02 -0000 1.4
+++ test_saxlette.py 21 Dec 2006 06:13:39 -0000 1.5
@@ -442,4 +442,34 @@
return
+### EntityResolver Interface ###########################################
+
+class TestEntityResolver:
+
+ def resolveEntity(self, publicId, systemId):
+ inpsrc = InputSource()
+ inpsrc.setByteStream(StringIO("<entity/>"))
+ return inpsrc
+
+def test_entity_resolver():
+ parser = create_parser()
+ parser.setEntityResolver(TestEntityResolver())
+ result = StringIO()
+ parser.setContentHandler(XMLGenerator(result))
+
+ parser.feed('<!DOCTYPE doc [\n')
+ parser.feed(' <!ENTITY test SYSTEM "whatever">\n')
+ parser.feed(']>\n')
+ parser.feed('<doc>&test;</doc>')
+ parser.close()
+
+ return result.getvalue() == start + "<doc><entity></entity></doc>"
+
+def test_entity_resolver(tester):
+ tester.startGroup("EntityResolver")
+ test_errors_incomplete(tester)
+ tester.groupDone()
+ return
+
+
### Error Reporting ####################################################
@@ -489,4 +519,5 @@
test_attributes(tester)
test_locator(tester)
+ test_entity_resolver(tester)
test_errors(tester)
return
More information about the 4suite-checkins
mailing list