#!/usr/bin/env python

import coral
from coral.util.search.query import *

prj=coral.loadDocument("testNewQuery.xmi")

target_model=None
query_set=coral.Set()
start_q=None
for root in prj.contents():
    if root.name == "Target":
        target_model=root

    if root.name == "Query":
        for elem in root.ownedElement:
            query_set.append(elem)

assert target_model
assert not query_set.isEmpty()

q2t=search(query_set, target_model)

for map in q2t:
    for t in map.values():
        assert map.values().count(t)==1, "target"+str(t)+"occurs more than once"
