From 43229f08530da230ea78c44e91674af4b210f7f2 Mon Sep 17 00:00:00 2001 From: Kevin DeJong Date: Wed, 16 Oct 2024 10:16:01 -0700 Subject: [PATCH] Update graph labels --- src/cfnlint/graph.py | 11 ++++++++--- test/unit/module/template/test_template.py | 8 ++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/cfnlint/graph.py b/src/cfnlint/graph.py index 9fb11e9bc2..877a0c88f4 100644 --- a/src/cfnlint/graph.py +++ b/src/cfnlint/graph.py @@ -7,6 +7,7 @@ from __future__ import annotations +import json import logging import warnings from typing import Any @@ -53,6 +54,9 @@ def _pydot_string_convert(self, value: str | int) -> str | int: return value + def _pydot_list_convert(self, value: list[str | int]) -> str: + return json.dumps(json.dumps(value)) + def subgraph_view(self, graph) -> networkx.MultiDiGraph: view = networkx.MultiDiGraph(name="template") resources: list[str] = [ @@ -69,9 +73,9 @@ def subgraph_view(self, graph) -> networkx.MultiDiGraph: for edge_1, edge_2, edge_data in graph.edges(data=True): if edge_1 in resources and edge_2 in resources: - edge_data["source_paths"] = [ - self._pydot_string_convert(p) for p in edge_data["source_paths"] - ] + edge_data["source_paths"] = self._pydot_list_convert( + edge_data["source_paths"] + ) view.add_edge( edge_1, edge_2, @@ -313,6 +317,7 @@ def to_dot(self, path): warnings.simplefilter("ignore", category=PendingDeprecationWarning) warnings.simplefilter("ignore", category=DeprecationWarning) + print(view) networkx.drawing.nx_pydot.write_dot(view, path) except ImportError as e: raise e diff --git a/test/unit/module/template/test_template.py b/test/unit/module/template/test_template.py index f82ed945e5..f589f9103f 100644 --- a/test/unit/module/template/test_template.py +++ b/test/unit/module/template/test_template.py @@ -54,10 +54,10 @@ def test_build_graph(self): CustomResource [label="CustomResource\\n", color=black, shape=ellipse, type=Resource]; WaitCondition [label="WaitCondition\\n", color=black, shape=ellipse, type=Resource]; LambdaFunction [label="LambdaFunction\\n", color=black, shape=ellipse, type=Resource]; -RolePolicies -> RootRole [key=0, source_paths="['Properties', 'Roles', 0]", label=Ref, color=black]; -RootInstanceProfile -> RootRole [key=0, source_paths="['Properties', 'Roles', 0]", label=Ref, color=black]; -MyEC2Instance -> RootInstanceProfile [key=0, source_paths="['Properties', 'IamInstanceProfile']", label=Ref, color=black]; -ElasticLoadBalancer -> MyEC2Instance [key=0, source_paths="['Properties', 'Instances', 0]", label=Ref, color=black]; +RolePolicies -> RootRole [key=0, source_paths="[\\"Properties\\", \\"Roles\\", 0]", label=Ref, color=black]; +RootInstanceProfile -> RootRole [key=0, source_paths="[\\"Properties\\", \\"Roles\\", 0]", label=Ref, color=black]; +MyEC2Instance -> RootInstanceProfile [key=0, source_paths="[\\"Properties\\", \\"IamInstanceProfile\\"]", label=Ref, color=black]; +ElasticLoadBalancer -> MyEC2Instance [key=0, source_paths="[\\"Properties\\", \\"Instances\\", 0]", label=Ref, color=black]; } """.split( "\n"