#!/usr/bin/env python
import coral


m = coral.lang.UML14.Model()
c = coral.lang.UML14.Class()

m.ownedElement = [ c ]

c2 = coral.ModelCopy_One(c, coral.MODELCOPY_DONT_CREATE_NEW_UUIDS)
assert c2.__XMIid__() == c.__XMIid__()

c3 = coral.ModelCopy_One(c)
assert c3.__XMIid__() != c.__XMIid__()

m.ownedElement = [ c ]

c2 = coral.ModelCopy_One(c, coral.MODELCOPY_DONT_ATTACH_TO_PARENTS)
assert c2.namespace is None
assert m.ownedElement.size() == 1
assert m.ownedElement[0] == c

c3 = coral.ModelCopy_One(c)
assert c3.namespace == m
assert m.ownedElement.size() == 2
assert c in m.ownedElement
assert c3 in m.ownedElement

# Check PyObject copying

DI = coral.lang.XMIDI20
g = DI.GraphNode()
g.position.x = 200
x = "any python object"
g.widget.__setPyValue__(x)
g2 = coral.ModelCopy_One(g)
assert g2 != g
assert g2.position.x == g.position.x
assert g2.widget.__getPyValue__() is None

g3 = coral.ModelCopy_One(g, coral.MODELCOPY_DONT_SKIP_PYOBJECTS)
assert g3 != g
assert g3.position.x == g.position.x
assert g3.widget.__getPyValue__() is not None
assert g3.widget.__getPyValue__() == g.widget.__getPyValue__()


# Check attach to parents

p0 = coral.lang.UML14.Package()
p1 = coral.lang.UML14.Package()
p2 = coral.lang.UML14.Package()
p3 = coral.lang.UML14.Package()
p3.namespace = p2
p2.namespace = p1
p1.namespace = p0

copy_of_p1 = coral.ModelCopy_One(p1, coral.MODELCOPY_DONT_ATTACH_TO_PARENTS)
assert copy_of_p1.namespace is None
copy_of_p2 = copy_of_p1.ownedElement[0]
assert copy_of_p2.namespace == copy_of_p1
copy_of_p3 = copy_of_p2.ownedElement[0]
assert copy_of_p3.namespace == copy_of_p2
