#!/usr/bin/env python
import coral

# This so dehandlers are activated
from coral.modeler import modeler
MW = modeler.ModelerWindow()
MW.main(loop=0)


L = coral.lang.UML14
DI = coral.lang.XMIDI20

tm = coral.getTransactionManager()
tm.beginModifyCmd()
try:
    p = coral.Project()
    m = L.Model()
    m.__setProject__(p)
    
    from coral.modeler.diagram.xmidi_diagrams import createDiagram
    
    d = createDiagram(p, m, "")
finally:
    tm.endModifyCmd()

MW.getDiagramEditorManager().editorSet.notifyFocusOn(d)

MW.processEvents()

assert len(p.contents()) == 2
assert p.contents()[0] == m
assert p.contents()[1] == d



tm.beginModifyCmd()
try:
    m.__setProject__(None)
    m.__resetAttrs__()
    assert m.__getProject__() is None
    assert m.__getRootsProject__() is None
finally:
    tm.endModifyCmd()

MW.processEvents()

assert d.owner is None

import time
time.sleep(2)
assert len(p.contents()) == 0

