Annotation of embedaddon/libxml2/python/tests/compareNodes.py, revision 1.1.1.2
1.1 misho 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 Node comparison and Node hash-value
10: #
11: doc = libxml2.parseDoc("""<root><foo/></root>""")
12: root = doc.getRootElement()
13:
14: # Create two different objects which point to foo
15: foonode1 = root.children
16: foonode2 = root.children
17:
18: # Now check that [in]equality tests work ok
19: if not ( foonode1 == foonode2 ):
1.1.1.2 ! misho 20: print("Error comparing nodes with ==, nodes should be equal but are unequal")
1.1 misho 21: sys.exit(1)
22: if not ( foonode1 != root ):
1.1.1.2 ! misho 23: print("Error comparing nodes with ==, nodes should not be equal but are equal")
1.1 misho 24: sys.exit(1)
25: if not ( foonode1 != root ):
1.1.1.2 ! misho 26: print("Error comparing nodes with !=, nodes should not be equal but are equal")
1.1 misho 27: if ( foonode1 != foonode2 ):
1.1.1.2 ! misho 28: print("Error comparing nodes with !=, nodes should be equal but are unequal")
1.1 misho 29:
30: # Next check that the hash function for the objects also works ok
31: if not (hash(foonode1) == hash(foonode2)):
1.1.1.2 ! misho 32: print("Error hash values for two equal nodes are different")
1.1 misho 33: sys.exit(1)
34: if not (hash(foonode1) != hash(root)):
1.1.1.2 ! misho 35: print("Error hash values for two unequal nodes are not different")
1.1 misho 36: sys.exit(1)
37: if hash(foonode1) == hash(root):
1.1.1.2 ! misho 38: print("Error hash values for two unequal nodes are equal")
1.1 misho 39: sys.exit(1)
40:
41: # Basic tests successful
42: doc.freeDoc()
43:
44: # Memory debug specific
45: libxml2.cleanupParser()
46: if libxml2.debugMemory(1) == 0:
1.1.1.2 ! misho 47: print("OK")
1.1 misho 48: else:
1.1.1.2 ! misho 49: print("Memory leak %d bytes" % (libxml2.debugMemory(1)))
1.1 misho 50: libxml2.dumpMemory()
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>