#!/usr/bin/env python

import coral
import coral.modeler
import coral.modeler.modeler
import coral.addins.constraint.engine as E

prj=coral.loadDocument("testFaultyConstraints.xml")


model=None
cmodel=None
for part in prj.contents():
    if part.oclIsKindOf(coral.lang.CONSTRAINT10.Package):
        for CM in part.__getAllParts__().select(lambda p: p.oclIsKindOf(coral.lang.CONSTRAINT10.ConstraintModel)):
            E.loadConstraintModel(CM)
            E.activateCM(CM)
            assert E.isActive(CM)
            assert len(CM.result.select(lambda p:p.constraint.name == "HasName")) == 1

for part in prj.contents():
    if part.oclIsKindOf(coral.lang.CONSTRAINT10.Package):
        for CM in part.__getAllParts__().select(lambda p: p.oclIsKindOf(coral.lang.CONSTRAINT10.ConstraintModel)):
            CM.target = None
            E.activateCM(CM)
            E.reEvaluateAll(CM)
            assert not E.isActive(CM)
            assert len(CM.result) == 1
