Design a suite of unittest for the MusicXML module.
The suite should check the valid generation of the xml tree. It is not easy
to compare xml trees but can be solved "good enough" with an algorithm
similar to this:
def isEqualElement(a, b):
if a.getName()!=b.getName():
return False
if sorted(a.getAttrs().items())!=sorted(b.getAttrs().items()):
return False
if len(a.getChildren())!=len(b.getChildren()):
return False
if a.getData() and b.getData() and a.getData() != b.getData():
return False
for ac in a.getChildren():
l = []
for bc in b.getChildren():
if ac.getName() == bc.getName():
l.append(bc)
if len(l) == 0:
return False
r = False
for n in l:
if len(ac.kids)==len(n.kids): r = True
if not r:
return False
if ac.getData():
for n in l:
if n.getData()==ac.getData(): r = True
if not r:
return False
if not ac.getData() and (len(ac.kids)>0):
for n in l:
if isEqualElement(ac,n): r = True
if not r:
return False
return True
Original issue reported on code.google.com by jpala...@gmail.com on 7 Jul 2009 at 2:22
Original issue reported on code.google.com by
jpala...@gmail.com
on 7 Jul 2009 at 2:22