hkmogul / mingus

Automatically exported from code.google.com/p/mingus
GNU General Public License v3.0
0 stars 0 forks source link

MusicXML unittests #86

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago

Original comment by Rhijnauwen@gmail.com on 18 May 2011 at 7:32