From 908f54898790b8e290ca85dff4f5a72a2c7929a8 Mon Sep 17 00:00:00 2001 From: huyenngn Date: Thu, 9 May 2024 07:21:24 +0200 Subject: [PATCH] fix: Fix owner label placing for hierarchical exchanges --- .../collectors/default.py | 11 ++++--- tests/test_context_diagrams.py | 33 ++++++++++++++++--- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/capellambse_context_diagrams/collectors/default.py b/capellambse_context_diagrams/collectors/default.py index b714e993..cd249264 100644 --- a/capellambse_context_diagrams/collectors/default.py +++ b/capellambse_context_diagrams/collectors/default.py @@ -39,10 +39,13 @@ def collector( ex_datas: list[generic.ExchangeData] = [] edges: common.ElementList[fa.AbstractExchange] for ex in (edges := list(chain.from_iterable(connections.values()))): - if ( - is_hierarchical := exchanges.is_hierarchical(ex, centerbox) - ) and not diagram.include_inner_objects: - continue + if is_hierarchical := exchanges.is_hierarchical(ex, centerbox): + if diagram.display_parent_relation: + centerbox["labels"][0][ + "layoutOptions" + ] = makers.DEFAULT_LABEL_LAYOUT_OPTIONS + if not diagram.include_inner_objects: + continue if not is_hierarchical or not diagram.display_parent_relation: elkdata = data else: diff --git a/tests/test_context_diagrams.py b/tests/test_context_diagrams.py index a19a34ef..2b6db5e1 100644 --- a/tests/test_context_diagrams.py +++ b/tests/test_context_diagrams.py @@ -140,7 +140,6 @@ def test_include_inner_objects_in_context_diagram( model: capellambse.MelodyModel, ) -> None: obj = model.by_uuid(TEST_HIERARCHY_UUID) - expected_children = TEST_HIERARCHY_CHILDREN_UUIDS adiag = obj.context_diagram.render(None, include_inner_objects=True) obj.context_diagram.render("svgdiagram", include_inner_objects=True).save( @@ -149,7 +148,7 @@ def test_include_inner_objects_in_context_diagram( children = {obj.uuid for obj in adiag[TEST_HIERARCHY_UUID].children} - for uuid in expected_children: + for uuid in TEST_HIERARCHY_CHILDREN_UUIDS: assert uuid in children @@ -157,7 +156,6 @@ def test_exclude_inner_objects_in_context_diagram( model: capellambse.MelodyModel, ) -> None: obj = model.by_uuid(TEST_HIERARCHY_UUID) - expected_children = TEST_HIERARCHY_CHILDREN_UUIDS adiag = obj.context_diagram.render(None, include_inner_objects=False) obj.context_diagram.render("svgdiagram", include_inner_objects=False).save( @@ -166,10 +164,37 @@ def test_exclude_inner_objects_in_context_diagram( children = {obj.uuid for obj in adiag[TEST_HIERARCHY_UUID].children} - for uuid in expected_children: + for uuid in TEST_HIERARCHY_CHILDREN_UUIDS: assert uuid not in children +def test_exclude_inner_objects_and_hide_parent_relation_in_context_diagram( + model: capellambse.MelodyModel, +) -> None: + obj = model.by_uuid(TEST_HIERARCHY_UUID) + + adiag = obj.context_diagram.render( + None, + display_parent_relation=False, + include_inner_objects=False, + depth=2, + ) + obj.context_diagram.render( + "svgdiagram", + display_parent_relation=False, + include_inner_objects=False, + depth=2, + ).save(pretty=True) + + for uuid in TEST_HIERARCHY_CHILDREN_UUIDS: + with pytest.raises(KeyError): + adiag[uuid] # pylint: disable=pointless-statement + + for uuid in TEST_HIERARCHY_PARENTS_UUIDS: + with pytest.raises(KeyError): + adiag[uuid] # pylint: disable=pointless-statement + + def test_parent_relation_in_context_diagram( model: capellambse.MelodyModel, ) -> None: