Skip to content

Commit

Permalink
fix(metrics): Don't crash if there are no diagrams or semantic objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Wuestengecko committed Oct 25, 2023
1 parent 630954c commit 1c19b83
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion capellambse/extensions/metrics/composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ def draw_labeled_bar(
) -> str:
"""Construct a bar with label and icon (SVG string)."""
total = sum(segments)
normalized_segments = [x / total for x in segments]
if total:
normalized_segments = [x / total for x in segments]
else:
normalized_segments = [0 for _ in segments]
return (
draw_icon(x, y)
+ draw_text(x + 5, y + 3, f"{total}")
Expand Down
9 changes: 9 additions & 0 deletions tests/test_aird_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
import capellambse
from capellambse import aird, diagram, loader

EMPTY_MODEL = pathlib.Path(__file__).parent.joinpath(
"data/decl/empty_project_52/empty_project_52.aird"
)


class TestAIRDBasicFunctionality:
test_model = (
Expand Down Expand Up @@ -81,6 +85,11 @@ def test_python_code_representation_matches_expected_output(
actual = repr(diagram_under_test)
assert actual == expected

def test_enumerate_diagrams_doesnt_crash_if_there_are_no_diagrams(self):
model = loader.MelodyLoader(EMPTY_MODEL)
for _ in aird.enumerate_diagrams(model):
pass


def test_airdparser_msm_produces_valid_json_without_error(
model: capellambse.MelodyModel,
Expand Down

0 comments on commit 1c19b83

Please sign in to comment.