Skip to content

Commit

Permalink
MARelationDescription>>reference half-fix
Browse files Browse the repository at this point in the history
I don't understand why `self.assertIsInstance(self.inst1.reference, MAStringDescription)`
Same for `self.assertIsInstance(self.inst1.commonClass(), MAPriorityContainer)`

It's a half-fix, because `reference is None` condition never met - supercalss always returns non-nill, see magritte-metamodel/magritte#334
  • Loading branch information
Assargadon committed Sep 8, 2023
1 parent fe8bb79 commit f2c7f62
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
8 changes: 5 additions & 3 deletions Magritte/MARelationDescriptionTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from MANullAccessor_class import MANullAccessor
from MAStringDescription_class import MAStringDescription
from MADescription_class import MADescription
from MAContainer_class import MAContainer
import MAReferenceDescriptionTest


Expand Down Expand Up @@ -38,10 +39,11 @@ def test_classes(self):
self.inst1.classes = [int, bool, str]
self.assertEqual(self.inst1.classes, [int, bool, str])

def test_commonClass(self):
self.assertIsInstance(self.inst1.commonClass(), MAPriorityContainer)
def test_commonClass(self):
self.assertIsNone(self.inst1.commonClass())

self.inst1.classes = [MADictAccessor, MAAccessor, MANullAccessor]
self.assertEqual(self.inst1.commonClass(), MAAccessor)

def test_reference(self):
self.assertIsInstance(self.inst1.reference, MAStringDescription)
self.assertIsInstance(self.inst1.reference, MAContainer)
19 changes: 14 additions & 5 deletions Magritte/MARelationDescription_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ def classes(self, aCollection):

def commonClass(self):
if len(self._classes) == 0:
descriptionContainer = MAPriorityContainer()
descriptionContainer.label = self.label
return descriptionContainer
return None

current = next(iter(self.classes))
for item in self.classes:
while not issubclass(item, current):
Expand All @@ -42,8 +41,15 @@ def commonClass(self):
def reference(self):
reference = super().reference
if reference is None:
reference = self.commonClass().magritteTemplate.magritteDescription
return reference
commonClass = self.commonClass()
if commonClass is None:
descriptionContainer = self.defaultReference()
descriptionContainer.label = self.label
return descriptionContainer
else:
return commonClass.magritteTemplate.magritteDescription
else:
return reference

@reference.setter
def reference(self, aDescription):
Expand All @@ -52,6 +58,9 @@ def reference(self, aDescription):
def _reference(self, aDescription):
super().reference(aDescription)

@classmethod
def defaultReference(cls):
return MAPriorityContainer()

def acceptMagritte(self, aVisitor):
aVisitor.visitRelationDescription(self)

0 comments on commit f2c7f62

Please sign in to comment.