From aeb976a1585764d567711d1ad94319064fbf16b4 Mon Sep 17 00:00:00 2001 From: Dinis Cruz Date: Sat, 11 Jan 2025 14:04:55 +0000 Subject: [PATCH] more major refactoring on Mermaids class wired up more ignored tests like test_Mermaid__Render refactored Mermaid__Render__Config into Schema__Mermaid__Render__Config --- mgraph_ai/mgraph/actions/MGraph__Edit.py | 2 +- mgraph_ai/mgraph/domain/MGraph__Edge.py | 24 ++-- .../mermaid/actions/Mermaid__Edit.py | 53 ++++---- .../mermaid/actions/Mermaid__Render.py | 53 ++++---- .../mermaid/configs/Mermaid__Edge__Config.py | 6 - .../configs/Mermaid__Render__Config.py | 7 -- .../providers/mermaid/domain/Mermaid__Edge.py | 28 +++-- .../mermaid/domain/Mermaid__Graph.py | 10 +- .../providers/mermaid/domain/Mermaid__Node.py | 6 + .../mermaid/domain/__to_do__Mermaid.py | 75 ----------- .../schemas/Schema__Mermaid__Edge__Config.py | 6 +- .../mermaid/schemas/Schema__Mermaid__Graph.py | 3 + .../Schema__Mermaid__Render__Config.py | 10 ++ .../mermaid/utils/Mermaid__Random_Graph.py | 4 +- modules/OSBot-Utils | 2 +- poetry.lock | 6 +- .../mermaid/actions/test_Mermaid__Edit.py | 48 ++++--- .../mermaid/actions/test_Mermaid__Render.py | 118 ++++++++++-------- .../providers/mermaid/domain/test_Mermaid.py | 16 +-- .../mermaid/domain/test_Mermaid_Node.py | 9 +- .../mermaid/domain/test_Mermaid__Graph.py | 11 +- .../models/test_Model__Mermaid__Edge.py | 20 +-- .../regression/test__regression_mermaid.py | 4 +- .../schemas/test_Schema__Mermaid__Edge.py | 7 +- .../test_Schema__Mermaid__Edge__Config.py | 20 +-- .../schemas/test_Schema__Mermaid__Graph.py | 12 +- 26 files changed, 258 insertions(+), 302 deletions(-) delete mode 100644 mgraph_ai/providers/mermaid/configs/Mermaid__Edge__Config.py delete mode 100644 mgraph_ai/providers/mermaid/configs/Mermaid__Render__Config.py delete mode 100644 mgraph_ai/providers/mermaid/domain/__to_do__Mermaid.py create mode 100644 mgraph_ai/providers/mermaid/schemas/Schema__Mermaid__Render__Config.py diff --git a/mgraph_ai/mgraph/actions/MGraph__Edit.py b/mgraph_ai/mgraph/actions/MGraph__Edit.py index 528b86a..bbab174 100644 --- a/mgraph_ai/mgraph/actions/MGraph__Edit.py +++ b/mgraph_ai/mgraph/actions/MGraph__Edit.py @@ -5,7 +5,7 @@ class MGraph__Edit(Type_Safe): graph: MGraph__Graph - + def new_node(self, **kwargs): return self.graph.new_node(**kwargs) diff --git a/mgraph_ai/mgraph/domain/MGraph__Edge.py b/mgraph_ai/mgraph/domain/MGraph__Edge.py index 989fa79..52a4b14 100644 --- a/mgraph_ai/mgraph/domain/MGraph__Edge.py +++ b/mgraph_ai/mgraph/domain/MGraph__Edge.py @@ -1,18 +1,22 @@ -from typing import Any, List -from osbot_utils.helpers.Random_Guid import Random_Guid -from osbot_utils.helpers.Safe_Id import Safe_Id -from mgraph_ai.mgraph.domain.MGraph__Node import MGraph__Node -from mgraph_ai.mgraph.models.Model__MGraph__Attribute import Model__MGraph__Attribute -from mgraph_ai.mgraph.schemas.Schema__MGraph__Attribute import Schema__MGraph__Attribute -from mgraph_ai.mgraph.domain.MGraph__Attribute import MGraph__Attribute -from mgraph_ai.mgraph.models.Model__MGraph__Edge import Model__MGraph__Edge -from mgraph_ai.mgraph.models.Model__MGraph__Graph import Model__MGraph__Graph -from osbot_utils.type_safe.Type_Safe import Type_Safe +from typing import Any, List +from mgraph_ai.mgraph.schemas.Schema__MGraph__Edge__Config import Schema__MGraph__Edge__Config +from osbot_utils.helpers.Random_Guid import Random_Guid +from osbot_utils.helpers.Safe_Id import Safe_Id +from mgraph_ai.mgraph.domain.MGraph__Node import MGraph__Node +from mgraph_ai.mgraph.models.Model__MGraph__Attribute import Model__MGraph__Attribute +from mgraph_ai.mgraph.schemas.Schema__MGraph__Attribute import Schema__MGraph__Attribute +from mgraph_ai.mgraph.domain.MGraph__Attribute import MGraph__Attribute +from mgraph_ai.mgraph.models.Model__MGraph__Edge import Model__MGraph__Edge +from mgraph_ai.mgraph.models.Model__MGraph__Graph import Model__MGraph__Graph +from osbot_utils.type_safe.Type_Safe import Type_Safe class MGraph__Edge(Type_Safe): # Domain class for edges edge : Model__MGraph__Edge # Reference to edge model graph: Model__MGraph__Graph # Reference to graph model + def config(self) -> Schema__MGraph__Edge__Config: + return self.edge.data.edge_config + def edge_id(self) -> Random_Guid: # Get edge ID return self.edge.data.edge_config.edge_id diff --git a/mgraph_ai/providers/mermaid/actions/Mermaid__Edit.py b/mgraph_ai/providers/mermaid/actions/Mermaid__Edit.py index 9b0e4cb..7430e26 100644 --- a/mgraph_ai/providers/mermaid/actions/Mermaid__Edit.py +++ b/mgraph_ai/providers/mermaid/actions/Mermaid__Edit.py @@ -1,14 +1,17 @@ -from typing import Dict -from mgraph_ai.mgraph.schemas.Schema__MGraph__Attribute import Schema__MGraph__Attribute -from mgraph_ai.providers.mermaid.domain.Mermaid__Edge import Mermaid__Edge -from osbot_utils.helpers.Safe_Id import Safe_Id -from mgraph_ai.providers.mermaid.actions.Mermaid__Data import Mermaid__Data -from mgraph_ai.providers.mermaid.actions.Mermaid__Render import Mermaid__Render -from mgraph_ai.providers.mermaid.configs.Mermaid__Render__Config import Mermaid__Render__Config -from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Diagram__Type import Schema__Mermaid__Diagram__Type -from osbot_utils.decorators.methods.cache_on_self import cache_on_self -from mgraph_ai.mgraph.actions.MGraph__Edit import MGraph__Edit -from mgraph_ai.providers.mermaid.domain.Mermaid__Graph import Mermaid__Graph +from typing import Dict + +from mgraph_ai.providers.mermaid.domain.Mermaid__Node import Mermaid__Node +from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Render__Config import Schema__Mermaid__Render__Config +from osbot_utils.utils.Misc import random_text +from mgraph_ai.mgraph.schemas.Schema__MGraph__Attribute import Schema__MGraph__Attribute +from mgraph_ai.providers.mermaid.domain.Mermaid__Edge import Mermaid__Edge +from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Diagram_Direction import Schema__Mermaid__Diagram__Direction +from osbot_utils.helpers.Safe_Id import Safe_Id +from mgraph_ai.providers.mermaid.actions.Mermaid__Data import Mermaid__Data +from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Diagram__Type import Schema__Mermaid__Diagram__Type +from osbot_utils.decorators.methods.cache_on_self import cache_on_self +from mgraph_ai.mgraph.actions.MGraph__Edit import MGraph__Edit +from mgraph_ai.providers.mermaid.domain.Mermaid__Graph import Mermaid__Graph class Mermaid__Edit(MGraph__Edit): @@ -41,20 +44,28 @@ def add_edge(self, from_node_key:Safe_Id, to_node_key:Safe_Id, label:str=None, a return edge - def code(self) -> str: - return self.graph_render().code() - @cache_on_self def data(self): return Mermaid__Data(graph=self.graph) # todo: look at the best way to do this (i.e. give access to this class the info inside data) - @cache_on_self - def graph_render(self) -> Mermaid__Render: # todo: review this since we really shouldn't need be able to access the Mermaid__Render here - return Mermaid__Render(graph=self.graph) + def new_edge(self): + from_node_key = random_text('node', lowercase=True) + to_node_key = random_text('node', lowercase=True) + return self.add_edge(from_node_key, to_node_key) - def render_config(self) -> Mermaid__Render__Config: # todo: review this since we really should be able to access the Mermaid__Render__Config outside the Mermaid__Render object - return self.graph_render().config + def render_config(self) -> Schema__Mermaid__Render__Config: # todo: review this since we really should be able to access the Mermaid__Render__Config outside the Mermaid__Render object + return self.graph.model.data.render_config - def set_diagram_type(self, diagram_type): + def set_diagram_type(self, diagram_type): # todo: should this be moved into the render class? if isinstance(diagram_type, Schema__Mermaid__Diagram__Type): - self.graph_render().diagram_type = diagram_type \ No newline at end of file + self.render_config().diagram_type = diagram_type + + def set_direction(self, direction): + if isinstance(direction, Schema__Mermaid__Diagram__Direction): + self.render_config().diagram_direction = direction + elif isinstance(direction, str) and direction in Schema__Mermaid__Diagram__Direction.__members__: + self.render().diagram_direction = Schema__Mermaid__Diagram__Direction[direction] + return self # If the value can't be set (not a valid name), do nothing + + def new_node(self, **kwargs) -> Mermaid__Node: + return super().new_node(**kwargs) \ No newline at end of file diff --git a/mgraph_ai/providers/mermaid/actions/Mermaid__Render.py b/mgraph_ai/providers/mermaid/actions/Mermaid__Render.py index 3efe56b..0a95562 100644 --- a/mgraph_ai/providers/mermaid/actions/Mermaid__Render.py +++ b/mgraph_ai/providers/mermaid/actions/Mermaid__Render.py @@ -2,16 +2,12 @@ from osbot_utils.utils.Str import safe_str from mgraph_ai.providers.mermaid.domain.Mermaid__Node import LINE_PADDING, Mermaid__Node from mgraph_ai.providers.mermaid.domain.Mermaid__Graph import Mermaid__Graph -from mgraph_ai.providers.mermaid.configs.Mermaid__Render__Config import Mermaid__Render__Config from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Diagram_Direction import Schema__Mermaid__Diagram__Direction from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Diagram__Type import Schema__Mermaid__Diagram__Type from osbot_utils.type_safe.Type_Safe import Type_Safe class Mermaid__Render(Type_Safe): - config : Mermaid__Render__Config - diagram_direction : Schema__Mermaid__Diagram__Direction = Schema__Mermaid__Diagram__Direction.LR - diagram_type : Schema__Mermaid__Diagram__Type = Schema__Mermaid__Diagram__Type.graph graph : Mermaid__Graph mermaid_code : List @@ -30,40 +26,48 @@ def code_create(self, recreate=False): _.reset_code() elif self.mermaid_code: # if the code has already been created, don't create it return self # todo: find a better way to do this, namely around the concept of auto detecting (on change) when the recreation needs to be done (vs being able to use the previously calculated data) - for directive in _.config.directives: + for directive in _.config().directives: _.add_line(f'%%{{{directive}}}%%') _.add_line(self.graph_header()) - if self.config.add_nodes: + if self.config().add_nodes: for node in self.graph.nodes(): node_code = self.render_node(node) _.add_line(node_code) - if self.config.line_before_edges: + if self.config().line_before_edges: _.add_line('') for edge in self.graph.edges(): edge_code = self.render_edge(edge) _.add_line(edge_code) return self + def code_markdown(self): + #self.code_create() + self.code() + rendered_lines = self.mermaid_code + markdown = ['#### Mermaid Graph', + "```mermaid" , + *rendered_lines , + "```" ] + return '\n'.join(markdown) + + def config(self): + return self.graph.model.data.render_config def graph_header(self): - # if type(self.diagram_type.value) is str: - # value = self.diagram_type.value - # else: - # value = self.diagram_type.name - value = self.diagram_type.name - return f'{value} {self.diagram_direction.name}' + value = self.config().diagram_type.name + return f'{value} {self.config().diagram_direction.name}' def render_edge(self,edge): - from_node = self.graph.node(edge.from_node_id) - to_node = self.graph.node(edge.to_node_id) - from_node_key = safe_str(from_node.key) - to_node_key = safe_str(to_node .key) - if edge.config.output_node_from: + from_node = self.graph.node(edge.from_node_id()) + to_node = self.graph.node(edge.to_node_id ()) + from_node_key = safe_str(from_node.node_key()) + to_node_key = safe_str(to_node .node_key()) + if edge.config().output_node_from: from_node_key = self.render_node(from_node, include_padding=False) - if edge.config.output_node_to: + if edge.config().output_node_to: to_node_key = self.render_node(to_node, include_padding=False ) - if edge.config.edge_mode == 'lr_using_pipe': + if edge.config().edge_mode == 'lr_using_pipe': link_code = f'-->|{edge.label}|' elif edge.label: link_code = f'--"{edge.label}"-->' @@ -100,4 +104,11 @@ def render_node(self, node: Mermaid__Node, include_padding=True): def reset_code(self): self.mermaid_code = [] - return self \ No newline at end of file + return self + + def save(self, target_file=None): + file_path = target_file or '/tmp/mermaid.md' + + with open(file_path, 'w') as file: + file.write(self.code_markdown()) + return file_path \ No newline at end of file diff --git a/mgraph_ai/providers/mermaid/configs/Mermaid__Edge__Config.py b/mgraph_ai/providers/mermaid/configs/Mermaid__Edge__Config.py deleted file mode 100644 index 2a1a6f6..0000000 --- a/mgraph_ai/providers/mermaid/configs/Mermaid__Edge__Config.py +++ /dev/null @@ -1,6 +0,0 @@ -from osbot_utils.type_safe.Type_Safe import Type_Safe - -class Mermaid__Edge__Config(Type_Safe): - edge_mode : str - output_node_from : bool = False - output_node_to : bool = False \ No newline at end of file diff --git a/mgraph_ai/providers/mermaid/configs/Mermaid__Render__Config.py b/mgraph_ai/providers/mermaid/configs/Mermaid__Render__Config.py deleted file mode 100644 index f5f2983..0000000 --- a/mgraph_ai/providers/mermaid/configs/Mermaid__Render__Config.py +++ /dev/null @@ -1,7 +0,0 @@ -from osbot_utils.type_safe.Type_Safe import Type_Safe - - -class Mermaid__Render__Config(Type_Safe): - add_nodes : bool = True - directives : list - line_before_edges : bool = True \ No newline at end of file diff --git a/mgraph_ai/providers/mermaid/domain/Mermaid__Edge.py b/mgraph_ai/providers/mermaid/domain/Mermaid__Edge.py index 2828d1b..349a1f2 100644 --- a/mgraph_ai/providers/mermaid/domain/Mermaid__Edge.py +++ b/mgraph_ai/providers/mermaid/domain/Mermaid__Edge.py @@ -1,24 +1,36 @@ -from mgraph_ai.mgraph.domain.MGraph__Edge import MGraph__Edge -from mgraph_ai.providers.mermaid.models.Model__Mermaid__Edge import Model__Mermaid__Edge -from mgraph_ai.providers.mermaid.models.Model__Mermaid__Graph import Model__Mermaid__Graph +from mgraph_ai.mgraph.domain.MGraph__Edge import MGraph__Edge +from mgraph_ai.providers.mermaid.models.Model__Mermaid__Edge import Model__Mermaid__Edge +from mgraph_ai.providers.mermaid.models.Model__Mermaid__Graph import Model__Mermaid__Graph +from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Edge__Config import Schema__Mermaid__Edge__Config +from osbot_utils.type_safe.methods.type_safe_property import set_as_property class Mermaid__Edge(MGraph__Edge): edge : Model__Mermaid__Edge graph : Model__Mermaid__Graph - label : str + label = set_as_property('edge.data', 'label') + + + def config(self) -> Schema__Mermaid__Edge__Config: + return super().config() def edge_mode(self, edge_mode): - self.config.edge_mode = edge_mode + self.config().edge_mode = edge_mode return self def edge_mode__lr_using_pipe(self): return self.edge_mode('lr_using_pipe') + def from_node_id(self): + return self.edge.from_node_id() + def output_node_from(self, value=True): - self.config.output_node_from = value + self.config().output_node_from = value return self def output_node_to(self, value=True): - self.config.output_node_to = value - return self \ No newline at end of file + self.config().output_node_to = value + return self + + def to_node_id(self): + return self.edge.to_node_id() \ No newline at end of file diff --git a/mgraph_ai/providers/mermaid/domain/Mermaid__Graph.py b/mgraph_ai/providers/mermaid/domain/Mermaid__Graph.py index 71034ed..2f267c9 100644 --- a/mgraph_ai/providers/mermaid/domain/Mermaid__Graph.py +++ b/mgraph_ai/providers/mermaid/domain/Mermaid__Graph.py @@ -1,8 +1,8 @@ -from typing import Type -from mgraph_ai.mgraph.domain.MGraph__Graph import MGraph__Graph -from mgraph_ai.providers.mermaid.domain.Mermaid__Edge import Mermaid__Edge -from mgraph_ai.providers.mermaid.domain.Mermaid__Node import Mermaid__Node -from mgraph_ai.providers.mermaid.models.Model__Mermaid__Graph import Model__Mermaid__Graph +from typing import Type +from mgraph_ai.mgraph.domain.MGraph__Graph import MGraph__Graph +from mgraph_ai.providers.mermaid.domain.Mermaid__Edge import Mermaid__Edge +from mgraph_ai.providers.mermaid.domain.Mermaid__Node import Mermaid__Node +from mgraph_ai.providers.mermaid.models.Model__Mermaid__Graph import Model__Mermaid__Graph class Mermaid__Graph(MGraph__Graph): model : Model__Mermaid__Graph diff --git a/mgraph_ai/providers/mermaid/domain/Mermaid__Node.py b/mgraph_ai/providers/mermaid/domain/Mermaid__Node.py index ec6ca0d..df646c6 100644 --- a/mgraph_ai/providers/mermaid/domain/Mermaid__Node.py +++ b/mgraph_ai/providers/mermaid/domain/Mermaid__Node.py @@ -1,7 +1,10 @@ +from typing import Any + from mgraph_ai.mgraph.domain.MGraph__Node import MGraph__Node from mgraph_ai.providers.mermaid.models.Model__Mermaid__Graph import Model__Mermaid__Graph from mgraph_ai.providers.mermaid.models.Model__Mermaid__Node import Model__Mermaid__Node from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Node__Shape import Schema__Mermaid__Node__Shape +from osbot_utils.type_safe.methods.type_safe_property import set_as_property LINE_PADDING = ' ' @@ -9,6 +12,9 @@ class Mermaid__Node(MGraph__Node): node : Model__Mermaid__Node graph: Model__Mermaid__Graph + label = set_as_property('node.data', 'label') + key = set_as_property('node.data', 'key') + def config(self): return self.node.data.node_config diff --git a/mgraph_ai/providers/mermaid/domain/__to_do__Mermaid.py b/mgraph_ai/providers/mermaid/domain/__to_do__Mermaid.py deleted file mode 100644 index 952ac5c..0000000 --- a/mgraph_ai/providers/mermaid/domain/__to_do__Mermaid.py +++ /dev/null @@ -1,75 +0,0 @@ -from osbot_utils.decorators.methods.cache_on_self import cache_on_self -from mgraph_ai.providers.mermaid.Mermaid__Render import Mermaid__Render -from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Node import Schema__Mermaid__Node -from mgraph_ai.providers.mermaid.actions.Mermaid__Data import Mermaid__Data -from mgraph_ai.providers.mermaid.Mermaid__Edge import Mermaid__Edge -from mgraph_ai.providers.mermaid.domain.Mermaid__Graph import Mermaid__Graph -from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Diagram_Direction import Schema__Mermaid__Diagram__Direction -from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Diagram__Type import Schema__Mermaid__Diagram__Type -from osbot_utils.type_safe.Type_Safe import Type_Safe - - -class Mermaid(Type_Safe): - graph : Mermaid__Graph - - - - - - - - # def add_node(self, **kwargs): - # return self.graph.add_node(Schema__Mermaid__Node(**kwargs)) - - # def data(self): - # return Mermaid__Data(graph=self.graph) - - # def code(self): - # return self.render().code() - - def code_markdown(self): - #self.code_create() - self.code() - rendered_lines = self.render().mermaid_code - markdown = ['#### Mermaid Graph', - "```mermaid" , - *rendered_lines , - "```" ] - - return '\n'.join(markdown) - - def edges(self): - return self.graph.edges() - - - - def new_edge(self): - from_node = self.new_node() - to_node = self.new_node() - return self.add_edge(from_node.node_id, to_node.node_id) - - def new_node(self): - return self.add_node() - - def nodes(self): - return self.graph.nodes() - - @cache_on_self - def render(self): - return Mermaid__Render(graph=self.graph) - - def set_direction(self, direction): - if isinstance(direction, Schema__Mermaid__Diagram__Direction): - self.render().diagram_direction = direction - elif isinstance(direction, str) and direction in Schema__Mermaid__Diagram__Direction.__members__: - self.render().diagram_direction = Schema__Mermaid__Diagram__Direction[direction] - return self # If the value can't be set (not a valid name), do nothing - - - - def save(self, target_file=None): - file_path = target_file or '/tmp/mermaid.md' - - with open(file_path, 'w') as file: - file.write(self.code_markdown()) - return file_path \ No newline at end of file diff --git a/mgraph_ai/providers/mermaid/schemas/Schema__Mermaid__Edge__Config.py b/mgraph_ai/providers/mermaid/schemas/Schema__Mermaid__Edge__Config.py index c34cdb7..390e86d 100644 --- a/mgraph_ai/providers/mermaid/schemas/Schema__Mermaid__Edge__Config.py +++ b/mgraph_ai/providers/mermaid/schemas/Schema__Mermaid__Edge__Config.py @@ -2,7 +2,7 @@ from mgraph_ai.mgraph.schemas.Schema__MGraph__Edge__Config import Schema__MGraph__Edge__Config from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Node import Schema__Mermaid__Node - class Schema__Mermaid__Edge__Config(Schema__MGraph__Edge__Config): - from_node_type: Type[Schema__Mermaid__Node] - to_node_type : Type[Schema__Mermaid__Node] \ No newline at end of file + edge_mode : str + output_node_from : bool = False + output_node_to : bool = False diff --git a/mgraph_ai/providers/mermaid/schemas/Schema__Mermaid__Graph.py b/mgraph_ai/providers/mermaid/schemas/Schema__Mermaid__Graph.py index b79b7df..903337b 100644 --- a/mgraph_ai/providers/mermaid/schemas/Schema__Mermaid__Graph.py +++ b/mgraph_ai/providers/mermaid/schemas/Schema__Mermaid__Graph.py @@ -1,4 +1,6 @@ from typing import List, Dict, Type + +from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Render__Config import Schema__Mermaid__Render__Config from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Default__Types import Schema__Mermaid__Default__Types from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Edge import Schema__Mermaid__Edge from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Graph__Config import Schema__Mermaid__Graph__Config @@ -14,4 +16,5 @@ class Schema__Mermaid__Graph(Schema__MGraph__Graph): graph_type : Type['Schema__Mermaid__Graph'] mermaid_code : List[str] nodes : Dict[Random_Guid, Schema__Mermaid__Node] + render_config: Schema__Mermaid__Render__Config diff --git a/mgraph_ai/providers/mermaid/schemas/Schema__Mermaid__Render__Config.py b/mgraph_ai/providers/mermaid/schemas/Schema__Mermaid__Render__Config.py new file mode 100644 index 0000000..7a52b63 --- /dev/null +++ b/mgraph_ai/providers/mermaid/schemas/Schema__Mermaid__Render__Config.py @@ -0,0 +1,10 @@ +from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Diagram_Direction import Schema__Mermaid__Diagram__Direction +from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Diagram__Type import Schema__Mermaid__Diagram__Type +from osbot_utils.type_safe.Type_Safe import Type_Safe + +class Schema__Mermaid__Render__Config(Type_Safe): + add_nodes : bool = True + diagram_direction : Schema__Mermaid__Diagram__Direction = Schema__Mermaid__Diagram__Direction.LR + diagram_type : Schema__Mermaid__Diagram__Type = Schema__Mermaid__Diagram__Type.graph + directives : list + line_before_edges : bool = True \ No newline at end of file diff --git a/mgraph_ai/providers/mermaid/utils/Mermaid__Random_Graph.py b/mgraph_ai/providers/mermaid/utils/Mermaid__Random_Graph.py index 75c0f41..ef37af6 100644 --- a/mgraph_ai/providers/mermaid/utils/Mermaid__Random_Graph.py +++ b/mgraph_ai/providers/mermaid/utils/Mermaid__Random_Graph.py @@ -44,9 +44,7 @@ def create_mermaid_edge(self, from_node: Schema__Mermaid__Node, to_node : Schema__Mermaid__Node, label : str = None) -> Schema__Mermaid__Edge: - edge_config = Schema__Mermaid__Edge__Config(edge_id = Random_Guid() , - from_node_type = from_node.node_type , - to_node_type = to_node.node_type ) + edge_config = Schema__Mermaid__Edge__Config(edge_id = Random_Guid() ) return Schema__Mermaid__Edge (attributes = {} , edge_config = edge_config , edge_type = Schema__Mermaid__Edge , diff --git a/modules/OSBot-Utils b/modules/OSBot-Utils index 9bcd4d6..bceb528 160000 --- a/modules/OSBot-Utils +++ b/modules/OSBot-Utils @@ -1 +1 @@ -Subproject commit 9bcd4d69f6e3310b9b4c836fccc6555bd72f86c8 +Subproject commit bceb52846b1ae9750afc9155a288034ecb55f918 diff --git a/poetry.lock b/poetry.lock index a8137d6..bd7c42b 100644 --- a/poetry.lock +++ b/poetry.lock @@ -2,13 +2,13 @@ [[package]] name = "osbot-utils" -version = "2.8.0" +version = "2.9.0" description = "OWASP Security Bot - Utils" optional = false python-versions = "<4.0,>=3.7" files = [ - {file = "osbot_utils-2.8.0-py3-none-any.whl", hash = "sha256:d2f18741d8948ca7c1a23b15464894757a57708186f7e1de5ba491dfc4d3a292"}, - {file = "osbot_utils-2.8.0.tar.gz", hash = "sha256:af17c8cd86ec87ca149daa318c4014c8c7cef58f434d5e0fc1b2d208256f631c"}, + {file = "osbot_utils-2.9.0-py3-none-any.whl", hash = "sha256:251a5775d6b0427f719ffbbee1b2ddee8e95671f22f9f4c87acfde5aa291ec80"}, + {file = "osbot_utils-2.9.0.tar.gz", hash = "sha256:34b3d17938d8a9070b391adc58d0893fffd1e7b260dbb0f4ca03e2f1d409901a"}, ] [metadata] diff --git a/tests/unit/providers/mermaid/actions/test_Mermaid__Edit.py b/tests/unit/providers/mermaid/actions/test_Mermaid__Edit.py index da98067..46f9abc 100644 --- a/tests/unit/providers/mermaid/actions/test_Mermaid__Edit.py +++ b/tests/unit/providers/mermaid/actions/test_Mermaid__Edit.py @@ -1,22 +1,26 @@ -from unittest import TestCase -from mgraph_ai.providers.mermaid.configs.Mermaid__Render__Config import Mermaid__Render__Config -from mgraph_ai.providers.mermaid.domain.Mermaid__Edge import Mermaid__Edge -from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Diagram__Type import Schema__Mermaid__Diagram__Type -from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Node__Config import Schema__Mermaid__Node__Config -from osbot_utils.helpers.Safe_Id import Safe_Id -from osbot_utils.utils.Objects import __, obj -from mgraph_ai.providers.mermaid.domain.Mermaid__Node import Mermaid__Node -from osbot_utils.utils.Misc import is_guid -from mgraph_ai.mgraph.actions.MGraph__Edit import MGraph__Edit -from mgraph_ai.providers.mermaid.actions.Mermaid__Edit import Mermaid__Edit -from mgraph_ai.providers.mermaid.domain.Mermaid__Graph import Mermaid__Graph +from unittest import TestCase + +from mgraph_ai.providers.mermaid.domain.Mermaid import Mermaid +from mgraph_ai.providers.mermaid.domain.Mermaid__Edge import Mermaid__Edge +from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Render__Config import Schema__Mermaid__Render__Config +from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Diagram__Type import Schema__Mermaid__Diagram__Type +from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Node__Config import Schema__Mermaid__Node__Config +from osbot_utils.helpers.Safe_Id import Safe_Id +from osbot_utils.utils.Objects import __, obj +from mgraph_ai.providers.mermaid.domain.Mermaid__Node import Mermaid__Node +from osbot_utils.utils.Misc import is_guid +from mgraph_ai.mgraph.actions.MGraph__Edit import MGraph__Edit +from mgraph_ai.providers.mermaid.actions.Mermaid__Edit import Mermaid__Edit +from mgraph_ai.providers.mermaid.domain.Mermaid__Graph import Mermaid__Graph class test__Mermaid__Edit(TestCase): @classmethod def setUpClass(cls): - cls.mermaid__edit = Mermaid__Edit() + cls.mermaid = Mermaid() + cls.mermaid__edit = cls.mermaid.edit() + cls.mermaid__render = cls.mermaid.render() def test__init__(self): with self.mermaid__edit as _: @@ -30,6 +34,7 @@ def test_add_directive(self): _.add_directive ('init: {"flowchart": {"htmlLabels": false}} ') _.new_node (key='markdown', label='This **is** _Markdown_').markdown() + with self.mermaid__render as _: assert _.code() == ('%%{init: {"flowchart": {"htmlLabels": false}} }%%\n' 'flowchart LR\n' ' markdown["`This **is** _Markdown_`"]\n') @@ -61,9 +66,10 @@ def test_add_edge(self): attribute_type = 'builtins.str')) attributes = obj({attribute_id: edge_attributes[0].attribute.data.json()}) assert edge.edge.obj() == __(data =__(label = label, - edge_config = __(from_node_type = 'mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Node.Schema__Mermaid__Node', - to_node_type = 'mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Node.Schema__Mermaid__Node', - edge_id = edge_id ), + edge_config = __(edge_id = edge_id , + output_node_from = False , + output_node_to = False , + edge_mode = '' ), edge_type = 'mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Edge.Schema__Mermaid__Edge', attributes = attributes , from_node_id = from_node.node_id() , @@ -102,7 +108,9 @@ def test_add_node(self): def test_render_config(self): with Mermaid__Edit().render_config() as _: - assert type(_) is Mermaid__Render__Config - assert _.obj() == __(add_nodes = True, - line_before_edges = True, - directives = [] ) \ No newline at end of file + assert type(_) is Schema__Mermaid__Render__Config + assert _.obj() == __(add_nodes = True , + diagram_direction ='LR' , + diagram_type ='graph', + line_before_edges = True , + directives = [] ) \ No newline at end of file diff --git a/tests/unit/providers/mermaid/actions/test_Mermaid__Render.py b/tests/unit/providers/mermaid/actions/test_Mermaid__Render.py index de30a3a..e09edd7 100644 --- a/tests/unit/providers/mermaid/actions/test_Mermaid__Render.py +++ b/tests/unit/providers/mermaid/actions/test_Mermaid__Render.py @@ -1,9 +1,10 @@ -import pytest from unittest import TestCase +from osbot_utils.utils.Files import file_exists +from mgraph_ai.providers.mermaid.domain.Mermaid__Edge import Mermaid__Edge +from mgraph_ai.providers.mermaid.domain.Mermaid__Node import Mermaid__Node from osbot_utils.utils.Objects import __ from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Diagram_Direction import Schema__Mermaid__Diagram__Direction from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Diagram__Type import Schema__Mermaid__Diagram__Type -from mgraph_ai.providers.mermaid.configs.Mermaid__Render__Config import Mermaid__Render__Config from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Node__Shape import Schema__Mermaid__Node__Shape from mgraph_ai.providers.mermaid.domain.Mermaid import Mermaid from osbot_utils.testing.Stdout import Stdout @@ -11,25 +12,18 @@ class test_Mermaid__Render(TestCase): - @classmethod - def setUpClass(cls): - pytest.skip("todo: fix these tests after MGraph refactoring") - def setUp(self): self.mermaid = Mermaid() self.mermaid_render = self.mermaid.render() self.mermaid_edit = self.mermaid.edit() + self.mermaid_data = self.mermaid.data() def test__init__(self): with self.mermaid_render as _: - expected_data = __(config = _.config.obj(), - diagram_direction = Schema__Mermaid__Diagram__Direction.LR.value, - diagram_type = Schema__Mermaid__Diagram__Type.graph .value, - graph = _.graph.obj(), + expected_data = __(graph = _.graph.obj(), mermaid_code = []) assert _ is not None assert _.obj() == expected_data - assert type(_.config) is Mermaid__Render__Config @@ -43,51 +37,59 @@ def test_code(self): C -->|Three| F[fa:fa-car Car] """) - with self.mermaid as _: - _.render().config.add_nodes = False - _.render().config.line_before_edges = False + + with self.mermaid_edit as _: + _.render_config().add_nodes = False + _.render_config().line_before_edges = False _.set_direction(Schema__Mermaid__Diagram__Direction.TD) _.set_diagram_type(Schema__Mermaid__Diagram__Type.flowchart) - _.add_node(key='A').set_label('Christmas' ).wrap_with_quotes(False).shape_default () - _.add_node(key='B').set_label('Go shopping' ).wrap_with_quotes(False).shape_round_edges() - _.add_node(key='C').set_label('Let me think' ).wrap_with_quotes(False).shape_rhombus () - _.add_node(key='D').set_label('Laptop' ).wrap_with_quotes(False) - _.add_node(key='E').set_label('iPhone' ).wrap_with_quotes(False) - _.add_node(key='F').set_label('fa:fa-car Car').wrap_with_quotes(False) + _.new_node(key='A', label='Christmas' ).wrap_with_quotes(False).shape_default () + _.new_node(key='B').set_label('Go shopping' ).wrap_with_quotes(False).shape_round_edges() + _.new_node(key='C').set_label('Let me think' ).wrap_with_quotes(False).shape_rhombus () + _.new_node(key='D').set_label('Laptop' ).wrap_with_quotes(False) + _.new_node(key='E').set_label('iPhone' ).wrap_with_quotes(False) + _.new_node(key='F').set_label('fa:fa-car Car').wrap_with_quotes(False) _.add_edge('A', 'B', label='Get money').output_node_from().output_node_to().edge_mode__lr_using_pipe() _.add_edge('B', 'C' ).output_node_to() _.add_edge('C', 'D', label='One' ).output_node_to().edge_mode__lr_using_pipe() _.add_edge('C', 'E', label='Two' ).output_node_to().edge_mode__lr_using_pipe() _.add_edge('C', 'F', label='Three' ).output_node_to().edge_mode__lr_using_pipe() - assert expected_code ==_.code() - #file_path = self.mermaid.save() + with self.mermaid_render as _: + file_path = _.save() + + assert file_exists(file_path) is True + assert expected_code == _.code() - assert expected_code == _.code() with Stdout() as stdout: _.print_code() - assert stdout.value() == expected_code + '\n' - assert _.render().mermaid_code == expected_code.splitlines() - _.render().reset_code() - assert _.render().mermaid_code == [] + assert stdout.value() == expected_code + '\n' + assert _.mermaid_code == expected_code.splitlines() - assert expected_code == _.code() + _.reset_code() + assert _.mermaid_code == [] + assert expected_code == _.code() + assert _.mermaid_code != [] def test_code__more_cases(self): - with self.mermaid as _: + with self.mermaid_edit as _: _.add_directive('init: {"flowchart": {"htmlLabels": false}} ') - assert _.code() == ('%%{init: {"flowchart": {"htmlLabels": false}} }%%\n' - 'graph LR\n') + # assert _.code() == ('%%{init: {"flowchart": {"htmlLabels": false}} }%%\n' + # 'graph LR\n') - _.add_node(key='markdown', label='This **is** _Markdown_').markdown() + self.mermaid_render.code() + _.new_node(key='markdown', label='This **is** _Markdown_').markdown() - _.render().code_create(_.nodes(), _.edges(), recreate=True) - assert _.code() == ('%%{init: {"flowchart": {"htmlLabels": false}} }%%\n' - 'graph LR\n' - ' markdown["`This **is** _Markdown_`"]\n') + self.mermaid_render.code_create(recreate=True) - assert self.mermaid_render.diagram_type == Schema__Mermaid__Diagram__Type.graph + #return + + assert self.mermaid_render.code() == ('%%{init: {"flowchart": {"htmlLabels": false}} }%%\n' + 'graph LR\n' + ' markdown["`This **is** _Markdown_`"]\n') + + assert self.mermaid_render.config().diagram_type == Schema__Mermaid__Diagram__Type.graph def test_print_code(self): with self.mermaid_edit as _: @@ -102,28 +104,36 @@ def test_print_code(self): ' from_node --> to_node\n') def test_render_edge(self): + render_edge = self.mermaid_render.render_edge # helper method to make the code more readable with self.mermaid_edit as _: mermaid_edge = _.new_edge() - return - render_edge = self.mermaid_render.render_edge - from_node_id = self.mermaid_edge.from_node_id - to_node_id = self.mermaid_edge.to_node_id - from_node = self.mermaid.graph.node(from_node_id) - to_node = self.mermaid.graph.node(to_node_id ) - assert render_edge(self.mermaid_edge) == f' {from_node.key} --> {to_node.key}' - from_node.label = 'from node' - to_node.label = 'to node' - assert render_edge(self.mermaid_edge) == f' {from_node.key} --> {to_node.key}' - self.mermaid_edge.label = 'link_type' - assert render_edge(self.mermaid_edge) == f' {from_node.key} --"{self.mermaid_edge.label}"--> {to_node.key}' - self.mermaid_edge.edge_mode__lr_using_pipe() - assert render_edge(self.mermaid_edge) == f' {from_node.key} -->|{self.mermaid_edge.label}| {to_node.key}' - self.mermaid_edge.output_node_to() - assert render_edge(self.mermaid_edge) == f' {from_node.key} -->|{self.mermaid_edge.label}| {to_node.key}["to node"]' + from_node_id = mermaid_edge.from_node_id() + to_node_id = mermaid_edge.to_node_id() + from_node = self.mermaid_data.node(from_node_id) + to_node = self.mermaid_data.node(to_node_id ) + + assert type(mermaid_edge) is Mermaid__Edge + assert self.mermaid_render.graph == _.graph # make sure these are the same + assert type(from_node) is Mermaid__Node + assert type(to_node) is Mermaid__Node + assert render_edge(mermaid_edge) == f' {from_node.node_key()} --> {to_node.node_key()}' + + with self.mermaid_edit as _: + + from_node.label = 'from node' + to_node .label = 'to node' + assert render_edge(mermaid_edge) == f' {from_node.key} --> {to_node.key}' + mermaid_edge.label = 'link_type' + + assert render_edge(mermaid_edge) == f' {from_node.key} --"{mermaid_edge.label}"--> {to_node.key}' + mermaid_edge.edge_mode__lr_using_pipe() + assert render_edge(mermaid_edge) == f' {from_node.key} -->|{mermaid_edge.label}| {to_node.key}' + mermaid_edge.output_node_to() + assert render_edge(mermaid_edge) == f' {from_node.key} -->|{mermaid_edge.label}| {to_node.key}["to node"]' def test__render_node__node_shape(self): render_node = self.mermaid_render.render_node - with self.mermaid.add_node(key='id') as _: + with self.mermaid_edit.new_node(key='id') as _: assert render_node(_ ) == ' id["id"]' assert render_node(_.shape('' )) == ' id["id"]' assert render_node(_.shape('aaaaa' )) == ' id["id"]' diff --git a/tests/unit/providers/mermaid/domain/test_Mermaid.py b/tests/unit/providers/mermaid/domain/test_Mermaid.py index 4e24026..22dae91 100644 --- a/tests/unit/providers/mermaid/domain/test_Mermaid.py +++ b/tests/unit/providers/mermaid/domain/test_Mermaid.py @@ -1,9 +1,6 @@ -from unittest import TestCase - -from osbot_utils.utils.Misc import is_guid - -from osbot_utils.utils.Objects import __ - +from unittest import TestCase +from osbot_utils.utils.Misc import is_guid +from osbot_utils.utils.Objects import __ from mgraph_ai.providers.mermaid.domain.Mermaid import Mermaid @@ -31,7 +28,12 @@ def test__init__(self): graph_id=graph_id), graph_type = 'mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Graph.Schema__Mermaid__Graph', mermaid_code = [], - nodes = __()), + nodes = __(), + render_config=__(add_nodes = True , + diagram_direction = 'LR' , + diagram_type = 'graph', + line_before_edges = True , + directives = [] )), node_model_type='mgraph_ai.providers.mermaid.models.Model__Mermaid__Node.Model__Mermaid__Node', edge_model_type='mgraph_ai.providers.mermaid.models.Model__Mermaid__Edge.Model__Mermaid__Edge'), node_domain_type='mgraph_ai.providers.mermaid.domain.Mermaid__Node.Mermaid__Node', diff --git a/tests/unit/providers/mermaid/domain/test_Mermaid_Node.py b/tests/unit/providers/mermaid/domain/test_Mermaid_Node.py index 61c1f70..b026041 100644 --- a/tests/unit/providers/mermaid/domain/test_Mermaid_Node.py +++ b/tests/unit/providers/mermaid/domain/test_Mermaid_Node.py @@ -44,8 +44,13 @@ def test__init__(self): graph_title = '' , graph_id = graph_id ), graph_type = 'mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Graph.Schema__Mermaid__Graph', - mermaid_code = [], - nodes = __()), + mermaid_code = [], + nodes = __(), + render_config = __(add_nodes = True , + diagram_direction = 'LR' , + diagram_type = 'graph', + line_before_edges = True , + directives = [] )), node_model_type = 'mgraph_ai.providers.mermaid.models.Model__Mermaid__Node.Model__Mermaid__Node', edge_model_type = 'mgraph_ai.providers.mermaid.models.Model__Mermaid__Edge.Model__Mermaid__Edge')) diff --git a/tests/unit/providers/mermaid/domain/test_Mermaid__Graph.py b/tests/unit/providers/mermaid/domain/test_Mermaid__Graph.py index 8599aca..d57283e 100644 --- a/tests/unit/providers/mermaid/domain/test_Mermaid__Graph.py +++ b/tests/unit/providers/mermaid/domain/test_Mermaid__Graph.py @@ -23,9 +23,14 @@ def test__init__(self): allow_duplicate_edges = False, graph_title = '', graph_id=graph_id), - graph_type='mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Graph.Schema__Mermaid__Graph', - mermaid_code=[], - nodes=__()), + graph_type = 'mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Graph.Schema__Mermaid__Graph', + mermaid_code = [], + nodes =__(), + render_config = __(add_nodes = True , + diagram_direction = 'LR' , + diagram_type = 'graph', + line_before_edges = True , + directives = [] )), node_model_type='mgraph_ai.providers.mermaid.models.Model__Mermaid__Node.Model__Mermaid__Node', edge_model_type='mgraph_ai.providers.mermaid.models.Model__Mermaid__Edge.Model__Mermaid__Edge'), node_domain_type='mgraph_ai.providers.mermaid.domain.Mermaid__Node.Mermaid__Node', diff --git a/tests/unit/providers/mermaid/models/test_Model__Mermaid__Edge.py b/tests/unit/providers/mermaid/models/test_Model__Mermaid__Edge.py index cf892d6..5db0e4b 100644 --- a/tests/unit/providers/mermaid/models/test_Model__Mermaid__Edge.py +++ b/tests/unit/providers/mermaid/models/test_Model__Mermaid__Edge.py @@ -2,11 +2,9 @@ from mgraph_ai.mgraph.models.Model__MGraph__Edge import Model__MGraph__Edge from mgraph_ai.mgraph.schemas.Schema__MGraph__Edge import Schema__MGraph__Edge from mgraph_ai.mgraph.schemas.Schema__MGraph__Edge__Config import Schema__MGraph__Edge__Config -from mgraph_ai.mgraph.schemas.Schema__MGraph__Node import Schema__MGraph__Node from osbot_utils.helpers.Random_Guid import Random_Guid from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Edge import Schema__Mermaid__Edge from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Edge__Config import Schema__Mermaid__Edge__Config -from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Node import Schema__Mermaid__Node from mgraph_ai.providers.mermaid.models.Model__Mermaid__Edge import Model__Mermaid__Edge class test_Model__Mermaid__Edge(TestCase): @@ -14,9 +12,7 @@ class test_Model__Mermaid__Edge(TestCase): def setUp(self): # Initialize test data self.from_node_id = Random_Guid() self.to_node_id = Random_Guid() - self.edge_config = Schema__Mermaid__Edge__Config(edge_id = Random_Guid() , - from_node_type = Schema__Mermaid__Node , - to_node_type = Schema__Mermaid__Node ) + self.edge_config = Schema__Mermaid__Edge__Config(edge_id = Random_Guid() ) self.edge = Schema__Mermaid__Edge (attributes = {} , edge_config = self.edge_config , edge_type = Schema__Mermaid__Edge , @@ -51,16 +47,4 @@ def test_mermaid_specific_implementations(self): assert issubclass(Model__Mermaid__Edge, Model__MGraph__Edge) is True # Verify model inheritance assert isinstance(self.model.data, Schema__Mermaid__Edge) is True assert type(self.model.data) is Schema__Mermaid__Edge - assert not type(self.model.data) is Schema__MGraph__Edge - - def test_node_type_specifics(self): # Tests node type handling - # Verify node types are correctly set and returned - assert self.model.from_node_type() == Schema__Mermaid__Node - assert self.model.to_node_type() == Schema__Mermaid__Node - - with self.assertRaises(ValueError): # Verify type safety with different node types - Schema__Mermaid__Edge__Config( - edge_id = Random_Guid(), - from_node_type = Schema__MGraph__Node, # Invalid: using base node type - to_node_type = Schema__Mermaid__Node - ) \ No newline at end of file + assert not type(self.model.data) is Schema__MGraph__Edge \ No newline at end of file diff --git a/tests/unit/providers/mermaid/regression/test__regression_mermaid.py b/tests/unit/providers/mermaid/regression/test__regression_mermaid.py index 9198407..7e05f65 100644 --- a/tests/unit/providers/mermaid/regression/test__regression_mermaid.py +++ b/tests/unit/providers/mermaid/regression/test__regression_mermaid.py @@ -4,7 +4,6 @@ from mgraph_ai.providers.mermaid.domain.Mermaid import Mermaid from mgraph_ai.providers.mermaid.domain.Mermaid__Edge import Mermaid__Edge from mgraph_ai.providers.mermaid.domain.Mermaid__Node import Mermaid__Node -from mgraph_ai.providers.mermaid.configs.Mermaid__Edge__Config import Mermaid__Edge__Config from osbot_utils.utils.Misc import list_set from osbot_utils.utils.Objects import obj_data @@ -58,8 +57,7 @@ def test__regression__Mermaid__Edge__init__is_not_enforcing_type_safety(self): from_node = from_node_key to_node = to_node_key - assert Mermaid__Edge.__annotations__ == { 'config' : Mermaid__Edge__Config , - 'label' : str } + assert Mermaid__Edge.__annotations__ == { } assert type(from_node) is str # confirm that both variables are of type str assert type(to_node ) is str diff --git a/tests/unit/providers/mermaid/schemas/test_Schema__Mermaid__Edge.py b/tests/unit/providers/mermaid/schemas/test_Schema__Mermaid__Edge.py index 39df282..605152f 100644 --- a/tests/unit/providers/mermaid/schemas/test_Schema__Mermaid__Edge.py +++ b/tests/unit/providers/mermaid/schemas/test_Schema__Mermaid__Edge.py @@ -2,7 +2,6 @@ from osbot_utils.helpers.Random_Guid import Random_Guid from osbot_utils.helpers.Safe_Id import Safe_Id from mgraph_ai.mgraph.schemas.Schema__MGraph__Attribute import Schema__MGraph__Attribute -from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Node import Schema__Mermaid__Node from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Edge import Schema__Mermaid__Edge from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Edge__Config import Schema__Mermaid__Edge__Config @@ -10,11 +9,7 @@ class test_Schema__Mermaid__Edge(TestCase): def setUp(self): # Initialize test data - self.edge_config = Schema__Mermaid__Edge__Config( - edge_id = Random_Guid() , - from_node_type = Schema__Mermaid__Node , - to_node_type = Schema__Mermaid__Node - ) + self.edge_config = Schema__Mermaid__Edge__Config(edge_id = Random_Guid()) self.attribute = Schema__MGraph__Attribute( attribute_id = Random_Guid() , diff --git a/tests/unit/providers/mermaid/schemas/test_Schema__Mermaid__Edge__Config.py b/tests/unit/providers/mermaid/schemas/test_Schema__Mermaid__Edge__Config.py index 05731cd..fab5204 100644 --- a/tests/unit/providers/mermaid/schemas/test_Schema__Mermaid__Edge__Config.py +++ b/tests/unit/providers/mermaid/schemas/test_Schema__Mermaid__Edge__Config.py @@ -10,32 +10,16 @@ def setUp(self): self.edge_id = Random_Guid() self.from_node_type = Schema__Mermaid__Node self.to_node_type = Schema__Mermaid__Node - self.edge_config = Schema__Mermaid__Edge__Config( - edge_id = self.edge_id , - from_node_type = self.from_node_type, - to_node_type = self.to_node_type - ) + self.edge_config = Schema__Mermaid__Edge__Config(edge_id = self.edge_id) def test_init(self): # Tests basic initialization and type checking assert type(self.edge_config) is Schema__Mermaid__Edge__Config assert self.edge_config.edge_id == self.edge_id - assert self.edge_config.from_node_type == self.from_node_type - assert self.edge_config.to_node_type == self.to_node_type def test_type_safety_validation(self): # Tests type safety validations with self.assertRaises(ValueError) as context: - Schema__Mermaid__Edge__Config(edge_id = "not-a-guid" , - from_node_type = self.from_node_type, - to_node_type = self.to_node_type ) + Schema__Mermaid__Edge__Config(edge_id = "not-a-guid") assert str(context.exception) == "Invalid type for attribute 'edge_id'. Expected '' but got ''" - with self.assertRaises(ValueError) as context: - Schema__Mermaid__Edge__Config( - edge_id = self.edge_id, - from_node_type = "not-a-type", - to_node_type = self.to_node_type - ) - assert "Invalid type for attribute" in str(context.exception) - diff --git a/tests/unit/providers/mermaid/schemas/test_Schema__Mermaid__Graph.py b/tests/unit/providers/mermaid/schemas/test_Schema__Mermaid__Graph.py index f9cd0e4..43d5ad4 100644 --- a/tests/unit/providers/mermaid/schemas/test_Schema__Mermaid__Graph.py +++ b/tests/unit/providers/mermaid/schemas/test_Schema__Mermaid__Graph.py @@ -25,13 +25,11 @@ def setUp(self): key = Safe_Id("node_1") , label = "Test Node" ) self.edge = Schema__Mermaid__Edge (attributes = {} , - edge_config = Schema__Mermaid__Edge__Config(edge_id = Random_Guid() , - from_node_type = Schema__Mermaid__Node , - to_node_type = Schema__Mermaid__Node), - edge_type = Schema__Mermaid__Edge , - from_node_id = Random_Guid() , - to_node_id = Random_Guid() , - label = "Test Edge" ) + edge_config = Schema__Mermaid__Edge__Config(edge_id= Random_Guid() ), + edge_type = Schema__Mermaid__Edge , + from_node_id = Random_Guid() , + to_node_id = Random_Guid() , + label = "Test Edge" ) self.graph = Schema__Mermaid__Graph (default_types = self.default_types , edges = {self.edge.edge_config.edge_id: self.edge}, nodes = {self.node.node_config.node_id: self.node},