Skip to content

Commit

Permalink
Fix derived union propagation issue in case of one association
Browse files Browse the repository at this point in the history
  • Loading branch information
amolenaar committed Jan 26, 2020
1 parent 86096bc commit 2b8cd14
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 20 deletions.
27 changes: 12 additions & 15 deletions gaphor/UML/properties.py
Expand Up @@ -743,21 +743,18 @@ def _union(self, obj, exclude=None):
"""
Returns a union of all values as a set.
"""
if self.single:
return next(iter(self.subsets)).__get__(obj)
else:
u: Set[T] = set()
for s in self.subsets:
if s is exclude:
continue
tmp = s.__get__(obj)
if tmp:
try:
u.update(tmp)
except TypeError:
# [0..1] property
u.add(tmp)
return collectionlist(u)
u: Set[T] = set()
for s in self.subsets:
if s is exclude:
continue
tmp = s.__get__(obj)
if tmp:
try:
u.update(tmp)
except TypeError:
# [0..1] property
u.add(tmp)
return collectionlist(u)

def propagate(self, event):
"""
Expand Down
30 changes: 25 additions & 5 deletions gaphor/UML/tests/test_properties.py
Expand Up @@ -453,24 +453,44 @@ class A(Element):
assert d in a.u


@pytest.mark.skip
def test_derivedunion_notify():
def test_derivedunion_notify_for_single_derived_property():
class A(Element):
pass

class E(Element):
notified = False

def notify(self, name, pspec):
if name == "u":
def handle(self, event):
if event.property is E.u:
self.notified = True

E.a = association("a", A)
E.u = derivedunion(E, "u", A, 0, "*", E.a)

e = E()
assert e.notified is False
e.a = A()

assert e.notified is True


def test_derivedunion_notify_for_multiple_derived_properties():
class A(Element):
pass

class E(Element):
notified = False

def handle(self, event):
if event.property is E.u:
self.notified = True

E.a = association("a", A)
E.aa = association("aa", A)
E.u = derivedunion(E, "u", A, 0, "*", E.a, E.aa)

e = E()
e.a = A()

assert e.notified is True


Expand Down

0 comments on commit 2b8cd14

Please sign in to comment.