#!/usr/bin/env python
import coral
from coral import exceptions

def wfrCanNotGeneralizeItself(self):
    checked = []
    parents = []
    for i in self.generalization:
        parents.append(i)

    while len(parents) > 0:
        p = parents.pop()
        checked.append(p)
        p = p.parent
        if p == self:
            return 0
        addthese = p.generalization
        for i in addthese:
            if not i in checked and not i in parents:
                parents.append(i)
    return 1

L = coral.Language.__getLanguage__("UML", 1, 4)

op = coral.PyOperation(wfrCanNotGeneralizeItself, "python", "", 1)
L.getElement("Class").__addOperation__(op)

c1 = L.getElement("Class")()
c2 = L.getElement("Class")()
g1 = L.getElement("Generalization")()
g1.parent = c1
g1.child = c2
g2 = L.getElement("Generalization")()
g2.parent = c2
g2.child = c1



wfr = 0
try:
    coral.isWellFormed(c1)
except exceptions.WFRException:
    wfr = 1
    pass

assert wfr == 1
