diff --git a/mgraph_ai/core/MGraph__Data.py b/_experiments/core/MGraph__Data.py similarity index 100% rename from mgraph_ai/core/MGraph__Data.py rename to _experiments/core/MGraph__Data.py diff --git a/mgraph_ai/core/MGraph__Serializer.py b/_experiments/core/MGraph__Serializer.py similarity index 100% rename from mgraph_ai/core/MGraph__Serializer.py rename to _experiments/core/MGraph__Serializer.py diff --git a/mgraph_ai/core/MGraphs.py b/_experiments/core/MGraphs.py similarity index 100% rename from mgraph_ai/core/MGraphs.py rename to _experiments/core/MGraphs.py diff --git a/mgraph_ai/core/__init__.py b/_experiments/core/__init__.py similarity index 100% rename from mgraph_ai/core/__init__.py rename to _experiments/core/__init__.py diff --git a/tests/unit/core/test_MGraph__Serializer.py b/_experiments/core/test_MGraph__Serializer.py similarity index 100% rename from tests/unit/core/test_MGraph__Serializer.py rename to _experiments/core/test_MGraph__Serializer.py diff --git a/tests/unit/core/test__todo__MGraph.py b/_experiments/core/test__todo__MGraph.py similarity index 80% rename from tests/unit/core/test__todo__MGraph.py rename to _experiments/core/test__todo__MGraph.py index 07cf5fb..0920f1c 100644 --- a/tests/unit/core/test__todo__MGraph.py +++ b/_experiments/core/test__todo__MGraph.py @@ -18,24 +18,6 @@ def setUpClass(cls): def setUp(self): self.mgraph = MGraph() - def test___init__(self): - expected_args = ['config', 'data'] - with self.mgraph as _: - assert _.__attr_names__() == expected_args - with self.mgraph.data as _: - assert type(_) is Schema__MGraph__Graph - assert _.edges == {} - assert _.nodes == {} - assert is_guid(_.graph_id) is True - - def test_add_node(self): - with self.mgraph as _: - new_node = _.new_node() - assert dict(_.nodes()) == {new_node.node_id : new_node} - assert new_node.obj() == __(attributes = __() , - node_id = new_node.node_id, - node_type = None ) - def test_add_edge(self): with self.mgraph as _: from_node = _.new_node() diff --git a/tests/unit/core/test__todo__MGraph__Data.py b/_experiments/core/test__todo__MGraph__Data.py similarity index 100% rename from tests/unit/core/test__todo__MGraph__Data.py rename to _experiments/core/test__todo__MGraph__Data.py diff --git a/mgraph_ai/mgraph/models/Model__MGraph__Edge.py b/mgraph_ai/mgraph/models/Model__MGraph__Edge.py index bb3088b..7fe489b 100644 --- a/mgraph_ai/mgraph/models/Model__MGraph__Edge.py +++ b/mgraph_ai/mgraph/models/Model__MGraph__Edge.py @@ -17,9 +17,6 @@ def add_attribute(self, attribute: Schema__MGraph__Attribute): def from_node_id(self) -> Random_Guid: return self.data.from_node_id - def from_node_type(self) -> Type[Schema__MGraph__Node]: - return self.edge_config().from_node_type - def get_attribute(self, attribute_id: Random_Guid) -> Schema__MGraph__Attribute: return self.data.attributes.get(attribute_id) @@ -30,7 +27,4 @@ def edge_id(self) -> Random_Guid: return self.edge_config().edge_id def to_node_id(self) -> Random_Guid: - return self.data.to_node_id - - def to_node_type(self) -> Type[Schema__MGraph__Node]: - return self.edge_config().to_node_type + return self.data.to_node_id \ No newline at end of file diff --git a/mgraph_ai/providers/mermaid/actions/Mermaid__Edit.py b/mgraph_ai/providers/mermaid/actions/Mermaid__Edit.py index 7430e26..4f05f25 100644 --- a/mgraph_ai/providers/mermaid/actions/Mermaid__Edit.py +++ b/mgraph_ai/providers/mermaid/actions/Mermaid__Edit.py @@ -43,6 +43,8 @@ def add_edge(self, from_node_key:Safe_Id, to_node_key:Safe_Id, label:str=None, a edge.edge.data.label = label # todo: find a better way to set these properties (this return edge + def add_node(self, **kwargs) -> Mermaid__Node: # todo: see if we need this method + return self.new_node(**kwargs) @cache_on_self def data(self): @@ -64,7 +66,7 @@ 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] + self.render_config().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: diff --git a/mgraph_ai/providers/mermaid/schemas/Schema__Mermaid__Graph__Config.py b/mgraph_ai/providers/mermaid/schemas/Schema__Mermaid__Graph__Config.py index 71f2b56..40f5e6c 100644 --- a/mgraph_ai/providers/mermaid/schemas/Schema__Mermaid__Graph__Config.py +++ b/mgraph_ai/providers/mermaid/schemas/Schema__Mermaid__Graph__Config.py @@ -1,7 +1,4 @@ -from typing import Type from mgraph_ai.mgraph.schemas.Schema__MGraph__Graph__Config import Schema__MGraph__Graph__Config -from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Edge import Schema__Mermaid__Edge -from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Node import Schema__Mermaid__Node class Schema__Mermaid__Graph__Config(Schema__MGraph__Graph__Config): diff --git a/tests/unit/mgraph/actions/test_MGraph__Data.py b/tests/unit/mgraph/actions/test_MGraph__Data.py index 101a3d7..52ca820 100644 --- a/tests/unit/mgraph/actions/test_MGraph__Data.py +++ b/tests/unit/mgraph/actions/test_MGraph__Data.py @@ -15,31 +15,31 @@ def setUp(self): model_graph = Model__MGraph__Graph(data=schema_graph) # Create model and domain graph domain_graph = MGraph__Graph(model=model_graph) - self.data = MGraph__Data(graph=domain_graph) # Create data object + self.graph_data = MGraph__Data(graph=domain_graph) # Create data object def test_node_and_edge_retrieval(self): - node1 = self.data.graph.new_node().set_value('node_1') # Create nodes and edges - node2 = self.data.graph.new_node().set_value('node_2') - edge = self.data.graph.new_edge(from_node_id=node1.node_id(), to_node_id=node2.node_id()) - retrieved_node = self.data.node(node1.node_id()) # Test node retrieval + node1 = self.graph_data.graph.new_node().set_value('node_1') # Create nodes and edges + node2 = self.graph_data.graph.new_node().set_value('node_2') + edge = self.graph_data.graph.new_edge(from_node_id=node1.node_id(), to_node_id=node2.node_id()) + retrieved_node = self.graph_data.node(node1.node_id()) # Test node retrieval assert retrieved_node is not None assert retrieved_node.value() == "node_1" - retrieved_edge = self.data.edge(edge.edge_id()) # Test edge retrieval - assert self.data.edges()[0].json() == edge.json() - assert self.data.nodes()[0].json() == node1.json() - assert self.data.nodes()[1].json() == node2.json() + retrieved_edge = self.graph_data.edge(edge.edge_id()) # Test edge retrieval + assert self.graph_data.edges()[0].json() == edge.json() + assert self.graph_data.nodes()[0].json() == node1.json() + assert self.graph_data.nodes()[1].json() == node2.json() assert retrieved_edge is not None assert retrieved_edge.from_node().value() == "node_1" assert retrieved_edge.to_node ().value() == "node_2" def test_list_nodes_and_edges(self): - node1 = self.data.graph.new_node() # Create multiple nodes and edges - node2 = self.data.graph.new_node() - edge = self.data.graph.new_edge(from_node_id=node1.node_id(), to_node_id=node2.node_id()) - nodes = self.data.graph.nodes() # get nodes list - edges = self.data.graph.edges() # get edges list + node1 = self.graph_data.graph.new_node() # Create multiple nodes and edges + node2 = self.graph_data.graph.new_node() + edge = self.graph_data.graph.new_edge(from_node_id=node1.node_id(), to_node_id=node2.node_id()) + nodes = self.graph_data.graph.nodes() # get nodes list + edges = self.graph_data.graph.edges() # get edges list assert len(nodes) == 2 assert node1.json() == nodes[0].json() @@ -49,5 +49,5 @@ def test_list_nodes_and_edges(self): def test_nonexistent_retrieval(self): non_existent_id = Random_Guid() # Test retrieving non-existent node and edge - assert self.data.node(non_existent_id) is None - assert self.data.edge(non_existent_id) is None \ No newline at end of file + assert self.graph_data.node(non_existent_id) is None + assert self.graph_data.edge(non_existent_id) is None diff --git a/tests/unit/providers/mermaid/actions/test_Mermaid__Edit.py b/tests/unit/providers/mermaid/actions/test_Mermaid__Edit.py index 46f9abc..ce592d9 100644 --- a/tests/unit/providers/mermaid/actions/test_Mermaid__Edit.py +++ b/tests/unit/providers/mermaid/actions/test_Mermaid__Edit.py @@ -2,6 +2,7 @@ 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__Diagram_Direction import Schema__Mermaid__Diagram__Direction 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 @@ -113,4 +114,11 @@ def test_render_config(self): diagram_direction ='LR' , diagram_type ='graph', line_before_edges = True , - directives = [] ) \ No newline at end of file + directives = [] ) + + def test_set_direction(self): + with self.mermaid__edit as _: + assert _.set_direction(Schema__Mermaid__Diagram__Direction.LR) is _ + assert _.graph.model.data.render_config.diagram_direction == Schema__Mermaid__Diagram__Direction.LR + assert _.set_direction('RL') is _ + assert _.graph.model.data.render_config.diagram_direction == Schema__Mermaid__Diagram__Direction.RL \ 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 e09edd7..9d364ca 100644 --- a/tests/unit/providers/mermaid/actions/test_Mermaid__Render.py +++ b/tests/unit/providers/mermaid/actions/test_Mermaid__Render.py @@ -1,4 +1,7 @@ from unittest import TestCase + +from osbot_utils.testing.Temp_File import Temp_File + 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 @@ -144,5 +147,259 @@ def test__render_node__node_shape(self): assert render_node(_.shape(Schema__Mermaid__Node__Shape.round_edges)) == ' id("id")' assert render_node(_.shape(Schema__Mermaid__Node__Shape.rhombus )) == ' id{"id"}' + def test_save(self): + with Temp_File() as temp_file: + assert temp_file.delete() + with self.mermaid_edit as _: + _.add_node(key='abc') + _.add_node(key='xyz') + _.add_edge('abc', 'xyz') + with self.mermaid_render as _: + assert temp_file.exists() is False + _.save(target_file=temp_file.path()) + assert temp_file.exists() is True + assert _.code() in temp_file.contents() + assert _.code_markdown() == temp_file.contents() + + + + def test__config__edge__output_node_from(self): + with self.mermaid_edit as _: + new_edge = _.add_edge('id', 'id2').output_node_from() + + with self.mermaid_render as _: + assert _.code() == 'graph LR\n id["id"]\n id2["id2"]\n\n id["id"] --> id2' + assert new_edge.config().output_node_from is True + assert _.render_edge(new_edge) == ' id["id"] --> id2' + new_edge.output_node_from(False) + assert new_edge.config().output_node_from is False + assert _.render_edge(new_edge) == ' id --> id2' + + + +# example = """ +# flowchart TD +# A[Christmas] -->|Get money| B(Go shopping) +# B --> C{Let me think} +# C -->|One| D[Laptop] +# C -->|Two| E[iPhone] +# C -->|Three| F[fa:fa-car Car] +# +# """ +# other_examples = """ +# xychart-beta +# title "Sales Revenue" +# x-axis [jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec] +# y-axis "Revenue (in $)" 4000 --> 11000 +# bar [1000, 6000, 7500, 8200, 9500, 10500, 11000, 10200, 9200, 8500, 7000, 6000] +# line [5000, 6000, 7500, 8200, 9500, 10500, 11000, 10200, 9200, 8500, 7000, 6000] +# +# mindmap +# root((mindmap)) +# Origins +# +# Long history +# ::icon(fa fa-book) +# Popularisation +# British popular psychology author Tony Buzan +# Research +# On effectivness
and features +# On Automatic creation +# Uses +# Creative techniques +# Strategic planning +# Argument mapping +# Tools +# Pen and paper +# Mermaid +# journey +# title My working day +# section Go to work +# Make tea: 5: Me +# Go upstairs: 3: Me +# Do work: 1: Me, Cat +# section Go home +# Go downstairs: 5: Me +# Sit down: 3: Me +# gantt +# title A Gantt Diagram +# dateFormat YYYY-MM-DD +# section Section +# A task :a1, 2014-01-01, 30d +# Another task :after a1 , 20d +# section Another +# Task in sec :2014-01-12 , 12d +# another task : 24d +# erDiagram +# CUSTOMER }|..|{ DELIVERY-ADDRESS : has +# CUSTOMER ||--o{ ORDER : places +# CUSTOMER ||--o{ INVOICE : "liable for" +# DELIVERY-ADDRESS ||--o{ ORDER : receives +# INVOICE ||--|{ ORDER : covers +# ORDER ||--|{ ORDER-ITEM : includes +# PRODUCT-CATEGORY ||--|{ PRODUCT : contains +# PRODUCT ||--o{ ORDER-ITEM : "ordered in" +# stateDiagram-v2 +# [*] --> Still +# Still --> [*] +# Still --> Moving +# Moving --> Still +# Moving --> Crash +# Crash --> [*] +# classDiagram +# Animal <|-- Duck +# Animal <|-- Fish +# Animal <|-- Zebra +# Animal : +int age +# Animal : +String gender +# Animal: +isMammal() +# Animal: +mate() +# class Duck{ +# +String beakColor +# +swim() +# +quack() +# } +# class Fish{ +# -int sizeInFeet +# -canEat() +# } +# class Zebra{ +# +bool is_wild +# +run() +# } +# flowchart TD +# A[Christmas] -->|Get money| B(Go shopping) +# B --> C{Let me think} +# C -->|One| D[Laptop] +# C -->|Two| E[iPhone] +# C -->|Three| F[fa:fa-car Car] +# +# gitGraph LR: +# commit "Ashish" +# branch newbranch +# checkout newbranch +# commit id:"1111" +# commit tag:"test" +# checkout main +# commit type: HIGHLIGHT +# commit +# merge newbranch +# commit +# branch b2 +# commit tag:"b2 tag" +# sequenceDiagram +# participant web as Web Browser +# participant blog as Blog Service +# participant account as Account Service +# participant mail as Mail Service +# participant db as Storage +# +# Note over web,db: The user must be logged in to submit blog posts +# web->>+account: Logs in using credentials +# account->>db: Query stored accounts +# db->>account: Respond with query result +# +# alt Credentials not found +# account->>web: Invalid credentials +# else Credentials found +# account->>-web: Successfully logged in +# +# Note over web,db: When the user is authenticated, they can now submit new posts +# web->>+blog: Submit new post +# blog->>db: Store post data +# +# par Notifications +# blog--)mail: Send mail to blog subscribers +# blog--)db: Store in-site notifications +# and Response +# blog-->>-web: Successfully posted +# end +# end +# +# sequenceDiagram +# participant Alice +# participant Bob +# Alice->>John: Hello John, how are you? +# loop Healthcheck +# John->>John: Fight against hypochondria +# end +# Note right of John: Rational thoughts
prevail... +# John-->>Alice: Great! +# John->>Bob: How about you? +# Bob-->>John: Jolly good! +# sequenceDiagram +# loop Daily query +# Alice->>Bob: Hello Bob, how are you? +# alt is sick +# Bob->>Alice: Not so good :( +# else is well +# Bob->>Alice: Feeling fresh like a daisy +# end +# +# opt Extra response +# Bob->>Alice: Thanks for asking +# end +# end +# graph TB +# sq[Square shape] --> ci((Circle shape)) +# +# subgraph A +# od>Odd shape]-- Two line
edge comment --> ro +# di{Diamond with
line break} -.-> ro(Rounded
square
shape) +# di==>ro2(Rounded square shape) +# end +# +# %% Notice that no text in shape are added here instead that is appended further down +# e --> od3>Really long text with linebreak
in an Odd shape] +# +# %% Comments after double percent signs +# e((Inner / circle
and some odd
special characters)) --> f(,.?!+-*ز) +# +# cyr[Cyrillic]-->cyr2((Circle shape Начало)); +# +# classDef green fill:#9f6,stroke:#333,stroke-width:2px; +# classDef orange fill:#f96,stroke:#333,stroke-width:4px; +# class sq,e green +# class di orange +# pie title NETFLIX +# "Time spent looking for movie" : 90 +# "Time spent watching it" : 10 +# sequenceDiagram +# +# Alice ->> Bob: Hello Bob, how are you? +# Bob-->>John: How about you John? +# Bob--x Alice: I am good thanks! +# Bob-x John: I am good thanks! +# Note right of John: Bob thinks a long
long time, so long
that the text does
not fit on a row. +# +# Bob-->Alice: Checking with John... +# Alice->John: Yes... John, how are you? +# +# +# """ +# graph TB +# classDef bigText font-size:40px,background-color:blue, color:red,padding:1; +# classDef smallText font-size:5px; +# +# classDef green fill:#9f6,stroke:#333,stroke-width:2px; +# classDef orange fill:#f96,stroke:#333,stroke-width:4px; +# +# +# C["`A formatted text +# =========== +# .Emojis and +# **bold** and +# *italics*`"] +# +# A[Node A] +# B[Node B] +# +# A --> B +# +# class A bigText +# class B smallText +# +# class C orange +# diff --git a/tests/unit/providers/mermaid/domain/test_Mermaid_Edge.py b/tests/unit/providers/mermaid/domain/test_Mermaid_Edge.py deleted file mode 100644 index a139e6e..0000000 --- a/tests/unit/providers/mermaid/domain/test_Mermaid_Edge.py +++ /dev/null @@ -1,47 +0,0 @@ -import pytest -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 -from mgraph_ai.providers.mermaid.domain.Mermaid__Node import Mermaid__Node -from mgraph_ai.providers.mermaid.domain.Mermaid__Edge import Mermaid__Edge - -class test_Mermaid_Edge(TestCase): - - @classmethod - def setUpClass(cls): - pytest.skip("todo: fix these tests after MGraph refactoring") - - def setUp(self): - self.mermaid_edge = Mermaid__Edge() - - def test__init__(self): - - with self.mermaid_edge as _: - assert type(_) is Mermaid__Edge - assert is_guid(_.from_node_id ) is True - assert is_guid(_.to_node_id ) is True - assert type (_.from_node_type) is type - assert type (_.to_node_type ) is type - assert _.from_node_type is Mermaid__Node - assert _.to_node_type is Mermaid__Node - assert _.obj() == __(config = __(output_node_from = False , - output_node_to = False , - edge_mode = '' ), - label = '' , - attributes = __() , - edge_id = _.edge_id , - from_node_id = _.from_node_id , - from_node_type = 'mgraph_ai.mermaid.domain.Mermaid__Node.Mermaid__Node', - to_node_id = _.to_node_id , - to_node_type = 'mgraph_ai.mermaid.domain.Mermaid__Node.Mermaid__Node') - - def test__config__edge__output_node_from(self): - with Mermaid() as _: - new_edge = _.add_edge('id', 'id2').output_node_from() - assert _.code() == 'graph LR\n id["id"]\n id2["id2"]\n\n id["id"] --> id2' - assert new_edge.config.output_node_from is True - assert _.render().render_edge(new_edge) == ' id["id"] --> id2' - new_edge.output_node_from(False) - assert new_edge.config.output_node_from is False - assert _.render().render_edge(new_edge) == ' id --> id2' \ No newline at end of file diff --git a/tests/unit/providers/mermaid/domain/test_Mermaid_Node.py b/tests/unit/providers/mermaid/domain/test_Mermaid_Node.py deleted file mode 100644 index b026041..0000000 --- a/tests/unit/providers/mermaid/domain/test_Mermaid_Node.py +++ /dev/null @@ -1,138 +0,0 @@ -from unittest import TestCase -from osbot_utils.utils.Objects import __ -from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Node import Schema__Mermaid__Node -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 mgraph_ai.providers.mermaid.domain.Mermaid__Node import Mermaid__Node - - -class test_Mermaid_Node(TestCase): - - def setUp(self): - self.mermaid_node = Mermaid__Node() - self.mermaid_node_id = self.mermaid_node.node_id() - self.mermaid_node_data = self.mermaid_node.node.data - self.mermaid_node_config = self.mermaid_node.node.data.node_config - - def test__init__(self): - with self.mermaid_node as _: - node_id = _.node_id() - node_key = _.node_key() - graph_id = _.graph_id() - - assert type(_) is Mermaid__Node - assert _.obj() == __(node=__(data=__(key = node_key , - label = node_key , - node_config =__(node_shape = 'default', - show_label = True , - wrap_with_quotes = True , - markdown = False , - node_id = node_id , - value_type = None ), - node_type = 'mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Node.Schema__Mermaid__Node', - attributes = __(), - value=None)), - graph=__(data=__(default_types = __(edge_type = 'mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Edge.Schema__Mermaid__Edge', - edge_config_type = 'mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Edge__Config.Schema__Mermaid__Edge__Config', - graph_config_type = 'mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Graph__Config.Schema__Mermaid__Graph__Config', - node_type = 'mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Node.Schema__Mermaid__Node', - node_config_type = 'mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Node__Config.Schema__Mermaid__Node__Config', - attribute_type = 'mgraph_ai.mgraph.schemas.Schema__MGraph__Attribute.Schema__MGraph__Attribute'), - edges = __(), - graph_config = __(allow_circle_edges = False , - 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 = __(), - 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')) - - def test_shape(self): - assert self.mermaid_node.shape(Schema__Mermaid__Node__Shape.round_edges).config().node_shape == Schema__Mermaid__Node__Shape.round_edges - assert self.mermaid_node.shape(Schema__Mermaid__Node__Shape.rhombus ).config().node_shape == Schema__Mermaid__Node__Shape.rhombus - assert self.mermaid_node.shape(Schema__Mermaid__Node__Shape.default ).config().node_shape == Schema__Mermaid__Node__Shape.default - assert self.mermaid_node.shape('round_edges' ).config().node_shape == Schema__Mermaid__Node__Shape.round_edges - assert self.mermaid_node.shape('rhombus' ).config().node_shape == Schema__Mermaid__Node__Shape.rhombus - assert self.mermaid_node.shape('default' ).config().node_shape == Schema__Mermaid__Node__Shape.default - assert self.mermaid_node.shape('aaaa' ).config().node_shape == Schema__Mermaid__Node__Shape.default - assert self.mermaid_node.shape(' ' ).config().node_shape == Schema__Mermaid__Node__Shape.default - assert self.mermaid_node.shape('' ).config().node_shape == Schema__Mermaid__Node__Shape.default - assert self.mermaid_node.shape(None ).config().node_shape == Schema__Mermaid__Node__Shape.default - assert self.mermaid_node.shape( ).config().node_shape == Schema__Mermaid__Node__Shape.default - - def test_shape__shape_name(self): - assert self.mermaid_node.shape_hexagon() is self.mermaid_node; assert self.mermaid_node.config().node_shape == Schema__Mermaid__Node__Shape.hexagon - assert self.mermaid_node.shape_parallelogram() is self.mermaid_node; assert self.mermaid_node.config().node_shape == Schema__Mermaid__Node__Shape.parallelogram - assert self.mermaid_node.shape_parallelogram_alt() is self.mermaid_node; assert self.mermaid_node.config().node_shape == Schema__Mermaid__Node__Shape.parallelogram_alt - assert self.mermaid_node.shape_rectangle() is self.mermaid_node; assert self.mermaid_node.config().node_shape == Schema__Mermaid__Node__Shape.rectangle - assert self.mermaid_node.shape_trapezoid() is self.mermaid_node; assert self.mermaid_node.config().node_shape == Schema__Mermaid__Node__Shape.trapezoid - assert self.mermaid_node.shape_trapezoid_alt() is self.mermaid_node; assert self.mermaid_node.config().node_shape == Schema__Mermaid__Node__Shape.trapezoid_alt - assert self.mermaid_node.shape_default() is self.mermaid_node; assert self.mermaid_node.config().node_shape == Schema__Mermaid__Node__Shape.default - assert self.mermaid_node.shape_round_edges() is self.mermaid_node; assert self.mermaid_node.config().node_shape == Schema__Mermaid__Node__Shape.round_edges - assert self.mermaid_node.shape_rhombus() is self.mermaid_node; assert self.mermaid_node.config().node_shape == Schema__Mermaid__Node__Shape.rhombus - assert self.mermaid_node.shape_circle() is self.mermaid_node; assert self.mermaid_node.config().node_shape == Schema__Mermaid__Node__Shape.circle - - - def test_wrap_with_quotes(self): - assert self.mermaid_node_config.wrap_with_quotes == True - assert self.mermaid_node.wrap_with_quotes( ).config().wrap_with_quotes == True - assert self.mermaid_node.wrap_with_quotes(False).config().wrap_with_quotes == False - assert self.mermaid_node.wrap_with_quotes(True ).config().wrap_with_quotes == True - - - def test__config__wrap_with_quotes(self): - data_obj = self.mermaid_node_data.set_key('id').set_label('id') - node_obj = self.mermaid_node.wrap_with_quotes() - assert type(data_obj ) is Schema__Mermaid__Node - assert type(node_obj ) is Mermaid__Node - - assert node_obj.config().wrap_with_quotes == True - assert data_obj.key == 'id' - - assert data_obj.obj() == __(key = 'id', - label = 'id', - node_config = __(node_shape = 'default', - show_label = True, - wrap_with_quotes = True, - markdown = False, - node_id = self.mermaid_node_id, - value_type = None ), - node_type = 'mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Node.Schema__Mermaid__Node', - attributes = __(), - value=None) - assert Schema__Mermaid__Node.from_json(data_obj.json()).json() == data_obj.json() - #pprint(node_obj.json()) - - - with Mermaid() as _: - _.edit().new_node(key='id') - assert _.code() == 'graph LR\n id["id"]\n' - - - - - #return - with Mermaid() as _: - _.edit().new_node(key='id').wrap_with_quotes(False) - assert _.code() == 'graph LR\n id[id]\n' - - mermaid = Mermaid() - new_node = mermaid.edit().new_node(key='id') - new_node.wrap_with_quotes(False) - - assert type(new_node) == Mermaid__Node - assert new_node.attributes() == [] - assert mermaid.code() == 'graph LR\n id[id]\n' - - def test_new_node(self): - key_value = 'this-is-an-key' - with Mermaid() as _: - assert _.edit().new_node(key=key_value).node_key() == key_value - assert _.render().code() == f'graph LR\n {key_value}["{key_value}"]\n' \ No newline at end of file diff --git a/tests/unit/providers/mermaid/domain/test_Mermaid__Edge.py b/tests/unit/providers/mermaid/domain/test_Mermaid__Edge.py new file mode 100644 index 0000000..07fea87 --- /dev/null +++ b/tests/unit/providers/mermaid/domain/test_Mermaid__Edge.py @@ -0,0 +1,29 @@ +from unittest import TestCase +from mgraph_ai.providers.mermaid.models.Model__Mermaid__Graph import Model__Mermaid__Graph +from osbot_utils.utils.Misc import is_guid +from osbot_utils.utils.Objects import __ +from mgraph_ai.providers.mermaid.domain.Mermaid__Edge import Mermaid__Edge + +class test_Mermaid__Edge(TestCase): + + def setUp(self): + self.graph = Model__Mermaid__Graph() + self.mermaid_edge = Mermaid__Edge(graph=self.graph) + + def test__init__(self): + + with self.mermaid_edge as _: + assert type(_) is Mermaid__Edge + assert is_guid(_.from_node_id() ) is True + assert is_guid(_.to_node_id() ) is True + assert _.graph == self.graph + assert _.obj() == __(edge = __(data=__(label='', + edge_config = __(output_node_from = False, + output_node_to = False, + edge_mode = '', + edge_id = _.edge_id()), + edge_type = 'mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Edge.Schema__Mermaid__Edge', + attributes = __(), + from_node_id = _.from_node_id(), + to_node_id = _.to_node_id())), + graph = self.graph.obj()) \ No newline at end of file diff --git a/tests/unit/providers/mermaid/domain/test_Mermaid__Node.py b/tests/unit/providers/mermaid/domain/test_Mermaid__Node.py index 21f61a7..b026041 100644 --- a/tests/unit/providers/mermaid/domain/test_Mermaid__Node.py +++ b/tests/unit/providers/mermaid/domain/test_Mermaid__Node.py @@ -1,78 +1,138 @@ -from unittest import TestCase -from mgraph_ai.providers.mermaid.domain.Mermaid__Node import Mermaid__Node -from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Node__Shape import Schema__Mermaid__Node__Shape -from mgraph_ai.providers.mermaid.test_data.Test_Data__Mermaid import Test_Data_Mermaid +from unittest import TestCase +from osbot_utils.utils.Objects import __ +from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Node import Schema__Mermaid__Node +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 mgraph_ai.providers.mermaid.domain.Mermaid__Node import Mermaid__Node -class test_Mermaid__Node(TestCase): +class test_Mermaid_Node(TestCase): def setUp(self): - test_data = Test_Data_Mermaid.create_test_graph(num_nodes=1) - self.graph_model = test_data['graph_model'] - self.nodes = test_data['nodes'] + self.mermaid_node = Mermaid__Node() + self.mermaid_node_id = self.mermaid_node.node_id() + self.mermaid_node_data = self.mermaid_node.node.data + self.mermaid_node_config = self.mermaid_node.node.data.node_config - self.first_node = Mermaid__Node(node=self.nodes[0], graph=self.graph_model) + def test__init__(self): + with self.mermaid_node as _: + node_id = _.node_id() + node_key = _.node_key() + graph_id = _.graph_id() - def test_init(self): - assert isinstance(self.first_node, Mermaid__Node) - assert self.first_node.value() == "value_key_0" + assert type(_) is Mermaid__Node + assert _.obj() == __(node=__(data=__(key = node_key , + label = node_key , + node_config =__(node_shape = 'default', + show_label = True , + wrap_with_quotes = True , + markdown = False , + node_id = node_id , + value_type = None ), + node_type = 'mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Node.Schema__Mermaid__Node', + attributes = __(), + value=None)), + graph=__(data=__(default_types = __(edge_type = 'mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Edge.Schema__Mermaid__Edge', + edge_config_type = 'mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Edge__Config.Schema__Mermaid__Edge__Config', + graph_config_type = 'mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Graph__Config.Schema__Mermaid__Graph__Config', + node_type = 'mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Node.Schema__Mermaid__Node', + node_config_type = 'mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Node__Config.Schema__Mermaid__Node__Config', + attribute_type = 'mgraph_ai.mgraph.schemas.Schema__MGraph__Attribute.Schema__MGraph__Attribute'), + edges = __(), + graph_config = __(allow_circle_edges = False , + 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 = __(), + 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')) + + def test_shape(self): + assert self.mermaid_node.shape(Schema__Mermaid__Node__Shape.round_edges).config().node_shape == Schema__Mermaid__Node__Shape.round_edges + assert self.mermaid_node.shape(Schema__Mermaid__Node__Shape.rhombus ).config().node_shape == Schema__Mermaid__Node__Shape.rhombus + assert self.mermaid_node.shape(Schema__Mermaid__Node__Shape.default ).config().node_shape == Schema__Mermaid__Node__Shape.default + assert self.mermaid_node.shape('round_edges' ).config().node_shape == Schema__Mermaid__Node__Shape.round_edges + assert self.mermaid_node.shape('rhombus' ).config().node_shape == Schema__Mermaid__Node__Shape.rhombus + assert self.mermaid_node.shape('default' ).config().node_shape == Schema__Mermaid__Node__Shape.default + assert self.mermaid_node.shape('aaaa' ).config().node_shape == Schema__Mermaid__Node__Shape.default + assert self.mermaid_node.shape(' ' ).config().node_shape == Schema__Mermaid__Node__Shape.default + assert self.mermaid_node.shape('' ).config().node_shape == Schema__Mermaid__Node__Shape.default + assert self.mermaid_node.shape(None ).config().node_shape == Schema__Mermaid__Node__Shape.default + assert self.mermaid_node.shape( ).config().node_shape == Schema__Mermaid__Node__Shape.default + + def test_shape__shape_name(self): + assert self.mermaid_node.shape_hexagon() is self.mermaid_node; assert self.mermaid_node.config().node_shape == Schema__Mermaid__Node__Shape.hexagon + assert self.mermaid_node.shape_parallelogram() is self.mermaid_node; assert self.mermaid_node.config().node_shape == Schema__Mermaid__Node__Shape.parallelogram + assert self.mermaid_node.shape_parallelogram_alt() is self.mermaid_node; assert self.mermaid_node.config().node_shape == Schema__Mermaid__Node__Shape.parallelogram_alt + assert self.mermaid_node.shape_rectangle() is self.mermaid_node; assert self.mermaid_node.config().node_shape == Schema__Mermaid__Node__Shape.rectangle + assert self.mermaid_node.shape_trapezoid() is self.mermaid_node; assert self.mermaid_node.config().node_shape == Schema__Mermaid__Node__Shape.trapezoid + assert self.mermaid_node.shape_trapezoid_alt() is self.mermaid_node; assert self.mermaid_node.config().node_shape == Schema__Mermaid__Node__Shape.trapezoid_alt + assert self.mermaid_node.shape_default() is self.mermaid_node; assert self.mermaid_node.config().node_shape == Schema__Mermaid__Node__Shape.default + assert self.mermaid_node.shape_round_edges() is self.mermaid_node; assert self.mermaid_node.config().node_shape == Schema__Mermaid__Node__Shape.round_edges + assert self.mermaid_node.shape_rhombus() is self.mermaid_node; assert self.mermaid_node.config().node_shape == Schema__Mermaid__Node__Shape.rhombus + assert self.mermaid_node.shape_circle() is self.mermaid_node; assert self.mermaid_node.config().node_shape == Schema__Mermaid__Node__Shape.circle - def test_markdown(self): - assert self.first_node.config().markdown is False - self.first_node.markdown(True) - assert self.first_node.config().markdown is True - self.first_node.markdown(False) - assert self.first_node.config().markdown is False def test_wrap_with_quotes(self): - assert self.first_node.config().wrap_with_quotes is True - self.first_node.wrap_with_quotes(False) - assert self.first_node.config().wrap_with_quotes is False - self.first_node.wrap_with_quotes(True) - assert self.first_node.config().wrap_with_quotes is True - - def test_show_label(self): - assert self.first_node.config().show_label is True - self.first_node.show_label(False) - assert self.first_node.config().show_label is False - self.first_node.show_label(True) - assert self.first_node.config().show_label is True - - def test_shape_methods(self): - # Test generic shape setter - self.first_node.shape('circle') - assert self.first_node.config().node_shape == Schema__Mermaid__Node__Shape.circle - - # Test all specific shape methods - shape_methods = [ - ('shape_asymmetric', Schema__Mermaid__Node__Shape.asymmetric), - ('shape_circle', Schema__Mermaid__Node__Shape.circle), - ('shape_cylindrical', Schema__Mermaid__Node__Shape.cylindrical), - ('shape_default', Schema__Mermaid__Node__Shape.default), - ('shape_double_circle', Schema__Mermaid__Node__Shape.double_circle), - ('shape_hexagon', Schema__Mermaid__Node__Shape.hexagon), - ('shape_parallelogram', Schema__Mermaid__Node__Shape.parallelogram), - ('shape_parallelogram_alt', Schema__Mermaid__Node__Shape.parallelogram_alt), - ('shape_stadium', Schema__Mermaid__Node__Shape.stadium), - ('shape_subroutine', Schema__Mermaid__Node__Shape.subroutine), - ('shape_rectangle', Schema__Mermaid__Node__Shape.rectangle), - ('shape_rhombus', Schema__Mermaid__Node__Shape.rhombus), - ('shape_round_edges', Schema__Mermaid__Node__Shape.round_edges), - ('shape_trapezoid', Schema__Mermaid__Node__Shape.trapezoid), - ('shape_trapezoid_alt', Schema__Mermaid__Node__Shape.trapezoid_alt) - ] - - for method_name, expected_shape in shape_methods: - method = getattr(self.first_node, method_name) - result = method() - assert result is self.first_node # Test method chaining - assert self.first_node.config().node_shape == expected_shape - - def test_shape_invalid(self): - # Test with invalid shape name - self.first_node.shape('invalid_shape') - assert self.first_node.config().node_shape == Schema__Mermaid__Node__Shape.default - - # Test with None - self.first_node.shape(None) - assert self.first_node.config().node_shape == Schema__Mermaid__Node__Shape.default \ No newline at end of file + assert self.mermaid_node_config.wrap_with_quotes == True + assert self.mermaid_node.wrap_with_quotes( ).config().wrap_with_quotes == True + assert self.mermaid_node.wrap_with_quotes(False).config().wrap_with_quotes == False + assert self.mermaid_node.wrap_with_quotes(True ).config().wrap_with_quotes == True + + + def test__config__wrap_with_quotes(self): + data_obj = self.mermaid_node_data.set_key('id').set_label('id') + node_obj = self.mermaid_node.wrap_with_quotes() + assert type(data_obj ) is Schema__Mermaid__Node + assert type(node_obj ) is Mermaid__Node + + assert node_obj.config().wrap_with_quotes == True + assert data_obj.key == 'id' + + assert data_obj.obj() == __(key = 'id', + label = 'id', + node_config = __(node_shape = 'default', + show_label = True, + wrap_with_quotes = True, + markdown = False, + node_id = self.mermaid_node_id, + value_type = None ), + node_type = 'mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Node.Schema__Mermaid__Node', + attributes = __(), + value=None) + assert Schema__Mermaid__Node.from_json(data_obj.json()).json() == data_obj.json() + #pprint(node_obj.json()) + + + with Mermaid() as _: + _.edit().new_node(key='id') + assert _.code() == 'graph LR\n id["id"]\n' + + + + + #return + with Mermaid() as _: + _.edit().new_node(key='id').wrap_with_quotes(False) + assert _.code() == 'graph LR\n id[id]\n' + + mermaid = Mermaid() + new_node = mermaid.edit().new_node(key='id') + new_node.wrap_with_quotes(False) + + assert type(new_node) == Mermaid__Node + assert new_node.attributes() == [] + assert mermaid.code() == 'graph LR\n id[id]\n' + + def test_new_node(self): + key_value = 'this-is-an-key' + with Mermaid() as _: + assert _.edit().new_node(key=key_value).node_key() == key_value + assert _.render().code() == f'graph LR\n {key_value}["{key_value}"]\n' \ No newline at end of file diff --git a/tests/unit/providers/mermaid/domain/test_Mermaid__Node__config.py b/tests/unit/providers/mermaid/domain/test_Mermaid__Node__config.py new file mode 100644 index 0000000..f992b6b --- /dev/null +++ b/tests/unit/providers/mermaid/domain/test_Mermaid__Node__config.py @@ -0,0 +1,77 @@ +from unittest import TestCase +from mgraph_ai.providers.mermaid.domain.Mermaid__Node import Mermaid__Node +from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Node__Shape import Schema__Mermaid__Node__Shape +from mgraph_ai.providers.mermaid.test_data.Test_Data__Mermaid import Test_Data_Mermaid + + +class test_Mermaid__Node__config(TestCase): # todo: refactor these tests to the correct location since most are related to the node's .config() + + def setUp(self): + test_data = Test_Data_Mermaid.create_test_graph(num_nodes=1) + self.graph_model = test_data['graph_model'] + self.nodes = test_data['nodes'] + self.first_node = Mermaid__Node(node=self.nodes[0], graph=self.graph_model) + + def test_init(self): + assert isinstance(self.first_node, Mermaid__Node) + assert self.first_node.value() == "value_key_0" + + def test_markdown(self): + assert self.first_node.config().markdown is False + self.first_node.markdown(True) + assert self.first_node.config().markdown is True + self.first_node.markdown(False) + assert self.first_node.config().markdown is False + + def test_wrap_with_quotes(self): + assert self.first_node.config().wrap_with_quotes is True + self.first_node.wrap_with_quotes(False) + assert self.first_node.config().wrap_with_quotes is False + self.first_node.wrap_with_quotes(True) + assert self.first_node.config().wrap_with_quotes is True + + def test_show_label(self): + assert self.first_node.config().show_label is True + self.first_node.show_label(False) + assert self.first_node.config().show_label is False + self.first_node.show_label(True) + assert self.first_node.config().show_label is True + + def test_shape_methods(self): + # Test generic shape setter + self.first_node.shape('circle') + assert self.first_node.config().node_shape == Schema__Mermaid__Node__Shape.circle + + # Test all specific shape methods + shape_methods = [ + ('shape_asymmetric', Schema__Mermaid__Node__Shape.asymmetric), + ('shape_circle', Schema__Mermaid__Node__Shape.circle), + ('shape_cylindrical', Schema__Mermaid__Node__Shape.cylindrical), + ('shape_default', Schema__Mermaid__Node__Shape.default), + ('shape_double_circle', Schema__Mermaid__Node__Shape.double_circle), + ('shape_hexagon', Schema__Mermaid__Node__Shape.hexagon), + ('shape_parallelogram', Schema__Mermaid__Node__Shape.parallelogram), + ('shape_parallelogram_alt', Schema__Mermaid__Node__Shape.parallelogram_alt), + ('shape_stadium', Schema__Mermaid__Node__Shape.stadium), + ('shape_subroutine', Schema__Mermaid__Node__Shape.subroutine), + ('shape_rectangle', Schema__Mermaid__Node__Shape.rectangle), + ('shape_rhombus', Schema__Mermaid__Node__Shape.rhombus), + ('shape_round_edges', Schema__Mermaid__Node__Shape.round_edges), + ('shape_trapezoid', Schema__Mermaid__Node__Shape.trapezoid), + ('shape_trapezoid_alt', Schema__Mermaid__Node__Shape.trapezoid_alt) + ] + + for method_name, expected_shape in shape_methods: + method = getattr(self.first_node, method_name) + result = method() + assert result is self.first_node # Test method chaining + assert self.first_node.config().node_shape == expected_shape + + def test_shape_invalid(self): + # Test with invalid shape name + self.first_node.shape('invalid_shape') + assert self.first_node.config().node_shape == Schema__Mermaid__Node__Shape.default + + # Test with None + self.first_node.shape(None) + assert self.first_node.config().node_shape == Schema__Mermaid__Node__Shape.default \ No newline at end of file diff --git a/tests/unit/providers/mermaid/examples/test_Mermain_Examples__FlowChart.py b/tests/unit/providers/mermaid/examples/test_Mermain_Examples__FlowChart.py index 7470796..9cdef79 100644 --- a/tests/unit/providers/mermaid/examples/test_Mermain_Examples__FlowChart.py +++ b/tests/unit/providers/mermaid/examples/test_Mermain_Examples__FlowChart.py @@ -1,4 +1,3 @@ -import pytest from unittest import TestCase from mgraph_ai.providers.mermaid.domain.Mermaid import Mermaid from mgraph_ai.providers.mermaid.examples.Mermaid_Examples__FlowChart import Mermain_Examples__FlowChart @@ -8,12 +7,11 @@ class test_Mermaid_Examples__FlowChart(TestCase): - @classmethod - def setUpClass(cls): - pytest.skip("todo: fix these tests after MGraph refactoring") def setUp(self): self.mermaid = Mermaid() + self.mermaid_edit = self.mermaid.edit() + self.mermaid_render = self.mermaid.render() self.examples = Mermain_Examples__FlowChart() self.target_example = None self.assert_on_exit = True @@ -33,23 +31,23 @@ def tearDown(self): if self.save_on_exit : self.mermaid.save() def test_example_1__a_node_default(self): - with self.mermaid as _: + with self.mermaid_edit as _: _.set_diagram_type(Schema__Mermaid__Diagram__Type.flowchart) _.add_node(key='id').show_label(False) def test_example_2__a_node_with_text(self): - with self.mermaid as _: + with self.mermaid_edit as _: _.set_diagram_type(Schema__Mermaid__Diagram__Type.flowchart) _.add_node(key='id1', label='This is the text in the box').wrap_with_quotes(False) def test_example_3__a_node_with_unicode_text(self): - with self.mermaid as _: + with self.mermaid_edit as _: _.set_diagram_type(Schema__Mermaid__Diagram__Type.flowchart) _.add_node(key='id', label='This ❤ Unicode') def test_example_4__a_node_with_markdown_formatting(self): - with self.mermaid as _: + with self.mermaid_edit as _: _.set_diagram_type(Schema__Mermaid__Diagram__Type.flowchart) _.add_directive('init: {"flowchart": {"htmlLabels": false}} ') _.add_node(key='markdown', label='This **is** _Markdown_').markdown() @@ -57,28 +55,28 @@ def test_example_4__a_node_with_markdown_formatting(self): Line 2 Line 3""").markdown() _.add_edge('markdown', 'newLines') - _.render().config.line_before_edges = False + _.render_config().line_before_edges = False def test_example_5__direction__from_top_to_bottom(self): - with self.mermaid as _: + with self.mermaid_edit as _: _.set_diagram_type(Schema__Mermaid__Diagram__Type.flowchart) - _.render().config.line_before_edges = False - _.render().config.add_nodes = False + _.render_config().line_before_edges = False + _.render_config().add_nodes = False _.set_direction('TD') _.add_edge('Start', 'Stop') def test_example_6__direction__from_left_to_right(self): - with self.mermaid as _: + with self.mermaid_edit as _: _.set_diagram_type(Schema__Mermaid__Diagram__Type.flowchart) - _.render().config.line_before_edges = False - _.render().config.add_nodes = False + _.render_config().line_before_edges = False + _.render_config().add_nodes = False _.set_direction('LR') _.add_edge('Start', 'Stop') def test_example_7__node_shapes_a_node_with_round_edges(self): - with self.mermaid as _: + with self.mermaid_edit as _: _.set_diagram_type(Schema__Mermaid__Diagram__Type.flowchart) _.add_node(key='id1', label='This is the text in the box').shape_round_edges().wrap_with_quotes(False) @@ -88,68 +86,68 @@ def test_example_8__node_shapes_a_stadium_shaped_node(self): #self.print_on_exit = True #self.print_expected_code = True - with self.mermaid as _: + with self.mermaid_edit as _: _.set_diagram_type(Schema__Mermaid__Diagram__Type.flowchart) _.add_node(key='id1', label='This is the text in the box').shape_stadium().wrap_with_quotes(False) def test_example_9__node_shapes_a_node_in_a_subroutine(self): - with self.mermaid as _: + with self.mermaid_edit as _: _.set_diagram_type(Schema__Mermaid__Diagram__Type.flowchart) _.add_node(key='id1', label='This is the text in the box').shape_subroutine().wrap_with_quotes(False) def test_example_10__node_shapes_a_node_in_a_cylindrical_shape(self): - with self.mermaid as _: + with self.mermaid_edit as _: _.set_diagram_type(Schema__Mermaid__Diagram__Type.flowchart) _.add_node(key='id1', label='Database').shape_cylindrical().wrap_with_quotes(False) def test_example_11__node_shapes_a_node_in_the_form_of_a_circle(self): - with self.mermaid as _: + with self.mermaid_edit as _: _.set_diagram_type(Schema__Mermaid__Diagram__Type.flowchart) _.add_node(key='id1', label='This is the text in the circle').shape_circle().wrap_with_quotes(False) def test_example_12__node_shapes_a_node_in_an_asymmetric_shape(self): - with self.mermaid as _: + with self.mermaid_edit as _: _.set_diagram_type(Schema__Mermaid__Diagram__Type.flowchart) _.add_node(key='id1', label='This is the text in the box').shape_asymmetric().wrap_with_quotes(False) def test_example_13__node_shapes_a_node_rhombus(self): - with self.mermaid as _: + with self.mermaid_edit as _: _.set_diagram_type(Schema__Mermaid__Diagram__Type.flowchart) _.add_node(key='id1', label='This is the text in the box').shape_rhombus().wrap_with_quotes(False) def test_example_14__node_shapes_a_hexagon_node(self): - with self.mermaid as _: + with self.mermaid_edit as _: _.set_diagram_type(Schema__Mermaid__Diagram__Type.flowchart) _.add_node(key='id1', label='This is the text in the box').shape_hexagon().wrap_with_quotes(False) def test_example_15__node_shapes_parallelogram(self): - with self.mermaid as _: + with self.mermaid_edit as _: _.set_diagram_type(Schema__Mermaid__Diagram__Type.flowchart) _.set_direction('TD') _.add_node(key='id1', label='This is the text in the box').shape_parallelogram().wrap_with_quotes(False) def test_example_16__node_shapes_parallelogram_alt(self): - with self.mermaid as _: + with self.mermaid_edit as _: _.set_diagram_type(Schema__Mermaid__Diagram__Type.flowchart) _.set_direction('TD') _.add_node(key='id1', label='This is the text in the box').shape_parallelogram_alt().wrap_with_quotes(False) def test_example_17__node_shapes_trapezoid(self): - with self.mermaid as _: + with self.mermaid_edit as _: _.set_diagram_type(Schema__Mermaid__Diagram__Type.flowchart) _.set_direction('TD') _.add_node(key='A', label='Christmas').shape_trapezoid().wrap_with_quotes(False) def test_example_18__node_shapes_trapezoid_alt(self): - with self.mermaid as _: + with self.mermaid_edit as _: _.set_diagram_type(Schema__Mermaid__Diagram__Type.flowchart) _.set_direction('TD') _.add_node(key='B', label='Go shopping').shape_trapezoid_alt().wrap_with_quotes(False) def test_example_19__node_shapes_double_circle(self): - with self.mermaid as _: + with self.mermaid_edit as _: _.set_diagram_type(Schema__Mermaid__Diagram__Type.flowchart) _.set_direction('TD') _.add_node(key='id1', label='This is the text in the circle').shape_double_circle().wrap_with_quotes(False) diff --git a/tests/unit/providers/mermaid/regression/test__regression_mermaid.py b/tests/unit/providers/mermaid/regression/test__regression_mermaid.py deleted file mode 100644 index 7e05f65..0000000 --- a/tests/unit/providers/mermaid/regression/test__regression_mermaid.py +++ /dev/null @@ -1,80 +0,0 @@ -import sys -import pytest -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.domain.Mermaid__Node import Mermaid__Node -from osbot_utils.utils.Misc import list_set -from osbot_utils.utils.Objects import obj_data - - -class test__regression__mermaid(TestCase): - - @classmethod - def setUpClass(cls): - pytest.skip("todo: fix these tests after MGraph refactoring") - if sys.version_info < (3, 9): - pytest.skip("Skipping tests that doesn't work on 3.8 or lower") - - def test__regression__Mermaid_Node__config_is_not_being_set(self): - new_node_1 = Mermaid__Node() - expected_attrs = ['attributes', 'config', 'key', 'label', 'node_id'] - assert type(new_node_1) is Mermaid__Node - assert list_set(new_node_1.__dict__ ) == expected_attrs - assert list_set(new_node_1.__locals__() ) == expected_attrs - assert list_set(obj_data(new_node_1) ) == expected_attrs - assert list_set(obj_data(new_node_1.config)) == ['markdown', 'node_shape','show_label', 'wrap_with_quotes' ] - - new_node_2 = Mermaid().add_node(key='id') - assert type(new_node_2) is Mermaid__Node - assert list_set(new_node_2.__dict__ ) == expected_attrs # FIXED, BUG: missing config - assert list_set(new_node_2.__locals__() ) == expected_attrs - assert list_set(obj_data(new_node_2) ) == expected_attrs # FIXED, BUG: missing config - assert new_node_2.config # FIXED, BUG: missing config - - # with self.assertRaises(Exception) as context: - # new_node_2.config # BUG: should not raise an exception - # assert str(context.exception) == "'Mermaid__Node' object has no attribute 'config'" - - - def test__regression__Mermaid__Edge__is_failing_on_ctor(self): - mermaid_edge = Mermaid__Edge() # FIXED: MGraph__Edge also now doesn't raise an exception - - assert mermaid_edge.from_node_type is Mermaid__Node # confirm that correct types of - assert mermaid_edge.to_node_type is Mermaid__Node # both from_node and to_node vars - - # with self.assertRaises(Exception) as context: - # Mermaid__Edge() # Mermaid__Edge ctor raises an exception - # assert str(context.exception) == ("Invalid type for attribute 'from_node'. Expected '' but got ''") - - - - def test__regression__Mermaid__Edge__init__is_not_enforcing_type_safety(self): - from_node_key = 'from_node_key' - to_node_key = 'to_node_key' - from_node = from_node_key - to_node = to_node_key - - assert Mermaid__Edge.__annotations__ == { } - assert type(from_node) is str # confirm that both variables are of type str - assert type(to_node ) is str - - with self.assertRaises(Exception) as context: - Mermaid__Edge(to_node_id=to_node) # FIXED: this now raises exception: BUG, this should have not worked (an exception should have been raised) - assert str(context.exception) == ("Invalid type for attribute 'to_node_id'. Expected '' but got ''") - - # assert new_edge.from_node == from_node # confirm that assigment worked - # assert new_edge.to_node == to_node # BUG, to_node should never be anything else than a Mermaid__Node object - # assert type(new_edge.from_node) is str # confirm that the type of the variables is still str - # assert type(new_edge.to_node ) is str # BUG, to_node should never be anything else than a Mermaid__Node object - - # with self.assertRaises(Exception) as context: - # new_edge.to_node = to_node # confirm that this type safety is working (i.e. assigment post ctor) - # assert str(context.exception) == ("Invalid type for attribute 'to_node'." - # " Expected '' " # an object of type Mermaid__Node - # "but got ''") # but we got an object of type str \ No newline at end of file diff --git a/tests/unit/providers/mermaid/test__todo__Mermaid.py b/tests/unit/providers/mermaid/test__todo__Mermaid.py deleted file mode 100644 index 7090902..0000000 --- a/tests/unit/providers/mermaid/test__todo__Mermaid.py +++ /dev/null @@ -1,276 +0,0 @@ -import pytest -from unittest import TestCase - -from osbot_utils.utils.Objects import __ -from mgraph_ai.providers.mermaid.actions.Mermaid__Render import Mermaid__Render -from mgraph_ai.providers.mermaid.domain.Mermaid import Mermaid -from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Diagram_Direction import Schema__Mermaid__Diagram__Direction -from osbot_utils.testing.Stdout import Stdout -from osbot_utils.testing.Temp_File import Temp_File - -class test__todo__Mermaid(TestCase): - - @classmethod - def setUpClass(cls): - pytest.skip("todo: fix these tests after MGraph refactoring") - - def setUp(self): - self.mermaid = Mermaid() - - - def test_set_direction(self): - with self.mermaid as _: - assert type(_.render()) is Mermaid__Render - assert _.set_direction(Schema__Mermaid__Diagram__Direction.LR) is _ - assert _.render().diagram_direction == Schema__Mermaid__Diagram__Direction.LR - assert _.set_direction('RL') is _ - assert _.render().diagram_direction == Schema__Mermaid__Diagram__Direction.RL - - def test_save(self): - with Temp_File() as temp_file: - assert temp_file.delete() - with self.mermaid as _: - _.add_node(key='abc') - _.add_node(key='xyz') - _.add_edge('abc', 'xyz') - assert temp_file.exists() is False - _.save(target_file=temp_file.path()) - assert temp_file.exists() is True - assert _.code() in temp_file.contents() - assert _.code_markdown() == temp_file.contents() - - - - - - - - - - - -# example = """ -# flowchart TD -# A[Christmas] -->|Get money| B(Go shopping) -# B --> C{Let me think} -# C -->|One| D[Laptop] -# C -->|Two| E[iPhone] -# C -->|Three| F[fa:fa-car Car] -# -# """ -# other_examples = """ -# xychart-beta -# title "Sales Revenue" -# x-axis [jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec] -# y-axis "Revenue (in $)" 4000 --> 11000 -# bar [1000, 6000, 7500, 8200, 9500, 10500, 11000, 10200, 9200, 8500, 7000, 6000] -# line [5000, 6000, 7500, 8200, 9500, 10500, 11000, 10200, 9200, 8500, 7000, 6000] -# -# mindmap -# root((mindmap)) -# Origins -# -# Long history -# ::icon(fa fa-book) -# Popularisation -# British popular psychology author Tony Buzan -# Research -# On effectivness
and features -# On Automatic creation -# Uses -# Creative techniques -# Strategic planning -# Argument mapping -# Tools -# Pen and paper -# Mermaid -# journey -# title My working day -# section Go to work -# Make tea: 5: Me -# Go upstairs: 3: Me -# Do work: 1: Me, Cat -# section Go home -# Go downstairs: 5: Me -# Sit down: 3: Me -# gantt -# title A Gantt Diagram -# dateFormat YYYY-MM-DD -# section Section -# A task :a1, 2014-01-01, 30d -# Another task :after a1 , 20d -# section Another -# Task in sec :2014-01-12 , 12d -# another task : 24d -# erDiagram -# CUSTOMER }|..|{ DELIVERY-ADDRESS : has -# CUSTOMER ||--o{ ORDER : places -# CUSTOMER ||--o{ INVOICE : "liable for" -# DELIVERY-ADDRESS ||--o{ ORDER : receives -# INVOICE ||--|{ ORDER : covers -# ORDER ||--|{ ORDER-ITEM : includes -# PRODUCT-CATEGORY ||--|{ PRODUCT : contains -# PRODUCT ||--o{ ORDER-ITEM : "ordered in" -# stateDiagram-v2 -# [*] --> Still -# Still --> [*] -# Still --> Moving -# Moving --> Still -# Moving --> Crash -# Crash --> [*] -# classDiagram -# Animal <|-- Duck -# Animal <|-- Fish -# Animal <|-- Zebra -# Animal : +int age -# Animal : +String gender -# Animal: +isMammal() -# Animal: +mate() -# class Duck{ -# +String beakColor -# +swim() -# +quack() -# } -# class Fish{ -# -int sizeInFeet -# -canEat() -# } -# class Zebra{ -# +bool is_wild -# +run() -# } -# flowchart TD -# A[Christmas] -->|Get money| B(Go shopping) -# B --> C{Let me think} -# C -->|One| D[Laptop] -# C -->|Two| E[iPhone] -# C -->|Three| F[fa:fa-car Car] -# -# gitGraph LR: -# commit "Ashish" -# branch newbranch -# checkout newbranch -# commit id:"1111" -# commit tag:"test" -# checkout main -# commit type: HIGHLIGHT -# commit -# merge newbranch -# commit -# branch b2 -# commit tag:"b2 tag" -# sequenceDiagram -# participant web as Web Browser -# participant blog as Blog Service -# participant account as Account Service -# participant mail as Mail Service -# participant db as Storage -# -# Note over web,db: The user must be logged in to submit blog posts -# web->>+account: Logs in using credentials -# account->>db: Query stored accounts -# db->>account: Respond with query result -# -# alt Credentials not found -# account->>web: Invalid credentials -# else Credentials found -# account->>-web: Successfully logged in -# -# Note over web,db: When the user is authenticated, they can now submit new posts -# web->>+blog: Submit new post -# blog->>db: Store post data -# -# par Notifications -# blog--)mail: Send mail to blog subscribers -# blog--)db: Store in-site notifications -# and Response -# blog-->>-web: Successfully posted -# end -# end -# -# sequenceDiagram -# participant Alice -# participant Bob -# Alice->>John: Hello John, how are you? -# loop Healthcheck -# John->>John: Fight against hypochondria -# end -# Note right of John: Rational thoughts
prevail... -# John-->>Alice: Great! -# John->>Bob: How about you? -# Bob-->>John: Jolly good! -# sequenceDiagram -# loop Daily query -# Alice->>Bob: Hello Bob, how are you? -# alt is sick -# Bob->>Alice: Not so good :( -# else is well -# Bob->>Alice: Feeling fresh like a daisy -# end -# -# opt Extra response -# Bob->>Alice: Thanks for asking -# end -# end -# graph TB -# sq[Square shape] --> ci((Circle shape)) -# -# subgraph A -# od>Odd shape]-- Two line
edge comment --> ro -# di{Diamond with
line break} -.-> ro(Rounded
square
shape) -# di==>ro2(Rounded square shape) -# end -# -# %% Notice that no text in shape are added here instead that is appended further down -# e --> od3>Really long text with linebreak
in an Odd shape] -# -# %% Comments after double percent signs -# e((Inner / circle
and some odd
special characters)) --> f(,.?!+-*ز) -# -# cyr[Cyrillic]-->cyr2((Circle shape Начало)); -# -# classDef green fill:#9f6,stroke:#333,stroke-width:2px; -# classDef orange fill:#f96,stroke:#333,stroke-width:4px; -# class sq,e green -# class di orange -# pie title NETFLIX -# "Time spent looking for movie" : 90 -# "Time spent watching it" : 10 -# sequenceDiagram -# -# Alice ->> Bob: Hello Bob, how are you? -# Bob-->>John: How about you John? -# Bob--x Alice: I am good thanks! -# Bob-x John: I am good thanks! -# Note right of John: Bob thinks a long
long time, so long
that the text does
not fit on a row. -# -# Bob-->Alice: Checking with John... -# Alice->John: Yes... John, how are you? -# -# -# """ - -# graph TB -# classDef bigText font-size:40px,background-color:blue, color:red,padding:1; -# classDef smallText font-size:5px; -# -# classDef green fill:#9f6,stroke:#333,stroke-width:2px; -# classDef orange fill:#f96,stroke:#333,stroke-width:4px; -# -# -# C["`A formatted text -# =========== -# .Emojis and -# **bold** and -# *italics*`"] -# -# A[Node A] -# B[Node B] -# -# A --> B -# -# class A bigText -# class B smallText -# -# class C orange -# \ No newline at end of file