9 # A document hosting the nodes returned from the extension function
11 mydoc
= libxml2
.newDoc("1.0")
17 # test returning a node set works as expected
19 parent
= mydoc
.newDocNode(None, 'p', None)
20 mydoc
.addChild(parent
)
21 node
= mydoc
.newDocText(str)
25 doc
= libxml2
.parseFile("tst.xml")
26 ctxt
= doc
.xpathNewContext()
27 libxml2
.registerXPathFunction(ctxt
._o
, "foo", None, foo
)
28 res
= ctxt
.xpathEval("foo('hello')")
29 if type(res
) != type([]):
30 print("Failed to return a nodeset")
33 print("Unexpected nodeset size")
37 print("Unexpected nodeset element result")
40 if node
.type != 'text':
41 print("Unexpected nodeset element children type")
43 if node
.content
!= 'hello':
44 print("Unexpected nodeset element children content")
49 ctxt
.xpathFreeContext()
51 #memory debug specific
52 libxml2
.cleanupParser()
53 if libxml2
.debugMemory(1) == 0:
56 print("Memory leak %d bytes" % (libxml2
.debugMemory(1)))