~ubuntu-branches/ubuntu/wily/opencollada/wily-proposed

« back to all changes in this revision

Viewing changes to Externals/LibXML/python/tests/cutnpaste.py

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2015-05-14 17:23:27 UTC
  • Revision ID: package-import@ubuntu.com-20150514172327-f862u8envms01fra
Tags: upstream-0.1.0~20140703.ddf8f47+dfsg1
ImportĀ upstreamĀ versionĀ 0.1.0~20140703.ddf8f47+dfsg1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python -u
 
2
import sys
 
3
import libxml2
 
4
 
 
5
# Memory debug specific
 
6
libxml2.debugMemory(1)
 
7
 
 
8
#
 
9
# Testing XML document serialization
 
10
#
 
11
source = libxml2.parseDoc("""<?xml version="1.0"?>
 
12
<root xmlns:foo="http://example.org/foo"
 
13
      xmlns:bar="http://example.org/bar">
 
14
<include xmlns="http://example.org/include">
 
15
<fragment><foo:elem bar="tricky"/></fragment>
 
16
</include>
 
17
</root>
 
18
""")
 
19
 
 
20
target = libxml2.parseDoc("""<?xml version="1.0"?>
 
21
<root xmlns:foobar="http://example.org/bar"/>""")
 
22
 
 
23
fragment = source.xpathEval("//*[name()='fragment']")[0]
 
24
dest = target.getRootElement()
 
25
 
 
26
# do a cut and paste operation
 
27
fragment.unlinkNode()
 
28
dest.addChild(fragment)
 
29
# do the namespace fixup
 
30
dest.reconciliateNs(target)
 
31
 
 
32
# The source tree can be freed at that point
 
33
source.freeDoc()
 
34
 
 
35
# check the resulting tree
 
36
str = dest.serialize()
 
37
if str != """<root xmlns:foobar="http://example.org/bar" xmlns:default="http://example.org/include" xmlns:foo="http://example.org/foo"><default:fragment><foo:elem bar="tricky"/></default:fragment></root>""":
 
38
    print "reconciliateNs() failed"
 
39
    sys.exit(1)
 
40
target.freeDoc()
 
41
 
 
42
# Memory debug specific
 
43
libxml2.cleanupParser()
 
44
if libxml2.debugMemory(1) == 0:
 
45
    print "OK"
 
46
else:
 
47
    print "Memory leak %d bytes" % (libxml2.debugMemory(1))
 
48
    libxml2.dumpMemory()