diff --git a/mgraph_ai/mgraph/domain/MGraph__Graph.py b/mgraph_ai/mgraph/domain/MGraph__Graph.py index 336fe7f..c101816 100644 --- a/mgraph_ai/mgraph/domain/MGraph__Graph.py +++ b/mgraph_ai/mgraph/domain/MGraph__Graph.py @@ -27,6 +27,9 @@ def edge(self, edge_id: Random_Guid) -> MGraph__Edge: def edges(self) -> List[MGraph__Edge]: return [self.mgraph_edge(edge=edge) for edge in self.model.edges()] + def graph_id(self): + return self.model.data.graph_config.graph_id + def mgraph_edge(self, edge: Model__MGraph__Edge) -> MGraph__Edge: #edge_domain_type = self.model.default_types.node_domain_type # todo: find way to do this edge_domain_type = MGraph__Edge diff --git a/mgraph_ai/providers/mermaid/models/Model__Mermaid__Graph.py b/mgraph_ai/providers/mermaid/models/Model__Mermaid__Graph.py index 5506771..2e32bd3 100644 --- a/mgraph_ai/providers/mermaid/models/Model__Mermaid__Graph.py +++ b/mgraph_ai/providers/mermaid/models/Model__Mermaid__Graph.py @@ -1,4 +1,5 @@ from typing import Type +from mgraph_ai.providers.mermaid.models.Model__Mermaid__Edge import Model__Mermaid__Edge from mgraph_ai.providers.mermaid.models.Model__Mermaid__Node import Model__Mermaid__Node from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Graph import Schema__Mermaid__Graph from mgraph_ai.mgraph.models.Model__MGraph__Graph import Model__MGraph__Graph @@ -6,6 +7,7 @@ class Model__Mermaid__Graph(Model__MGraph__Graph): data : Schema__Mermaid__Graph node_model_type: Type[Model__Mermaid__Node] + edge_model_type: Type[Model__Mermaid__Edge] diff --git a/mgraph_ai/providers/mermaid/utils/Mermaid__Random_Graph.py b/mgraph_ai/providers/mermaid/utils/Mermaid__Random_Graph.py index 65950d5..75c0f41 100644 --- a/mgraph_ai/providers/mermaid/utils/Mermaid__Random_Graph.py +++ b/mgraph_ai/providers/mermaid/utils/Mermaid__Random_Graph.py @@ -1,7 +1,6 @@ from typing import Dict, Any, List - -from mgraph_ai.providers.mermaid.domain.Mermaid import Mermaid -from mgraph_ai.providers.mermaid.domain.Mermaid__Graph import Mermaid__Graph +from mgraph_ai.providers.mermaid.domain.Mermaid import Mermaid +from mgraph_ai.providers.mermaid.domain.Mermaid__Graph import Mermaid__Graph from osbot_utils.helpers.Safe_Id import Safe_Id from osbot_utils.helpers.Random_Guid import Random_Guid from mgraph_ai.mgraph.utils.MGraph__Random_Graph import MGraph__Random_Graph diff --git a/tests/unit/providers/mermaid/utils/test_MGraph__Random_Graph.py b/tests/unit/mgraph/utils/test_MGraph__Random_Graph.py similarity index 100% rename from tests/unit/providers/mermaid/utils/test_MGraph__Random_Graph.py rename to tests/unit/mgraph/utils/test_MGraph__Random_Graph.py diff --git a/tests/unit/providers/mermaid/domain/test_Mermaid__Graph.py b/tests/unit/providers/mermaid/domain/test_Mermaid__Graph.py new file mode 100644 index 0000000..198fcca --- /dev/null +++ b/tests/unit/providers/mermaid/domain/test_Mermaid__Graph.py @@ -0,0 +1,31 @@ +import pytest +from unittest import TestCase +from osbot_utils.utils.Objects import __ +from mgraph_ai.providers.mermaid.domain.Mermaid__Graph import Mermaid__Graph + + +class test_Mermaid__MGraph(TestCase): + + def setUp(self): + self.mermaid_graph = Mermaid__Graph() + + def test__init__(self): + with self.mermaid_graph as _: + graph_id = _.graph_id() + assert type(_) is Mermaid__Graph + assert _.obj() == __(model=__(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=__()), + 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/test_Mermaid_Graph.py b/tests/unit/providers/mermaid/test_Mermaid_Graph.py deleted file mode 100644 index 79515f8..0000000 --- a/tests/unit/providers/mermaid/test_Mermaid_Graph.py +++ /dev/null @@ -1,24 +0,0 @@ -import pytest -from unittest import TestCase -from mgraph_ai.mgraph.domain.MGraph import MGraph -from osbot_utils.type_safe.Type_Safe import Type_Safe -from osbot_utils.utils.Misc import list_set -from osbot_utils.utils.Objects import base_types -from mgraph_ai.core.MGraphs import MGraphs -from mgraph_ai.providers.mermaid.domain.Mermaid__Graph import Mermaid__Graph - - -class test_Mermaid_MGraph(TestCase): - - @classmethod - def setUpClass(cls): - pytest.skip("todo: fix these tests after MGraph refactoring") - - def setUp(self): - self.mgraph = MGraphs().new__random(x_nodes=4,y_edges=4) - self.mermaid_graph = Mermaid__Graph() - - def test__init__(self): - assert type(self.mermaid_graph) is Mermaid__Graph - assert base_types(self.mermaid_graph) == [MGraph, Type_Safe, object] - assert list_set(self.mermaid_graph.__locals__()) == ['config', 'edges', 'key', 'mermaid_code', 'nodes'] \ No newline at end of file diff --git a/tests/unit/providers/mermaid/utils/test_Mermaid__Random_Graph.py b/tests/unit/providers/mermaid/utils/test_Mermaid__Random_Graph.py index 7ec21f7..67aabc4 100644 --- a/tests/unit/providers/mermaid/utils/test_Mermaid__Random_Graph.py +++ b/tests/unit/providers/mermaid/utils/test_Mermaid__Random_Graph.py @@ -1,22 +1,13 @@ from unittest import TestCase - -from mgraph_ai.mgraph.domain.MGraph__Edge import MGraph__Edge -from mgraph_ai.mgraph.domain.MGraph__Node import MGraph__Node -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 mgraph_ai.mgraph.models.Model__MGraph__Node import Model__MGraph__Node -from mgraph_ai.mgraph.schemas.Schema__MGraph__Default__Types import Schema__MGraph__Default__Types -from mgraph_ai.mgraph.schemas.Schema__MGraph__Edge import Schema__MGraph__Edge -from mgraph_ai.mgraph.schemas.Schema__MGraph__Graph import Schema__MGraph__Graph -from mgraph_ai.mgraph.schemas.Schema__MGraph__Node import Schema__MGraph__Node -from mgraph_ai.mgraph.schemas.Schema__MGraph__Node__Config import Schema__MGraph__Node__Config +from mgraph_ai.mgraph.domain.MGraph__Edge import MGraph__Edge +from mgraph_ai.mgraph.domain.MGraph__Node import MGraph__Node +from mgraph_ai.mgraph.models.Model__MGraph__Edge import Model__MGraph__Edge +from mgraph_ai.mgraph.models.Model__MGraph__Node import Model__MGraph__Node 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__Graph import Mermaid__Graph -from mgraph_ai.providers.mermaid.domain.Mermaid__Node import Mermaid__Node -from mgraph_ai.providers.mermaid.models.Model__Mermaid__Edge import Model__Mermaid__Edge +from mgraph_ai.providers.mermaid.domain.Mermaid__Graph import Mermaid__Graph +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.models.Model__Mermaid__Node import Model__Mermaid__Node +from mgraph_ai.providers.mermaid.models.Model__Mermaid__Node import Model__Mermaid__Node from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Default__Types import Schema__Mermaid__Default__Types from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Graph import Schema__Mermaid__Graph from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Graph__Config import Schema__Mermaid__Graph__Config @@ -237,8 +228,7 @@ def test_create_random_mgraph(self): assert type(domain_edge.graph ) == Model__Mermaid__Graph assert type(domain_edge.graph.data ) == Schema__Mermaid__Graph assert type(domain_edge.graph.data.default_types) == Schema__Mermaid__Default__Types - assert domain_edge.graph.edge_model_type == Model__MGraph__Edge # BUG - #assert domain_edge.graph.edge_model_type == Model__Mermaid__Edge # BUG + assert domain_edge.graph.edge_model_type == Model__Mermaid__Edge assert type(model_edge ) == Model__MGraph__Edge # BUG #assert type(model_edge ) == Model__Mermaid__Edge # BUG diff --git a/tests/unit/providers/mermaid/utils/test__bugs__Mermaid.py b/tests/unit/providers/mermaid/utils/test__bugs__Mermaid.py new file mode 100644 index 0000000..e8f96fc --- /dev/null +++ b/tests/unit/providers/mermaid/utils/test__bugs__Mermaid.py @@ -0,0 +1,74 @@ +from unittest import TestCase +from mgraph_ai.providers.mermaid.domain.Mermaid__Graph import Mermaid__Graph +from mgraph_ai.mgraph.domain.MGraph__Edge import MGraph__Edge +from mgraph_ai.mgraph.domain.MGraph__Node import MGraph__Node +from mgraph_ai.mgraph.models.Model__MGraph__Edge import Model__MGraph__Edge +from mgraph_ai.mgraph.models.Model__MGraph__Node import Model__MGraph__Node +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 +from mgraph_ai.providers.mermaid.utils.Mermaid__Random_Graph import create_test_mermaid_graph + + +class test__bugs__Mermaid(TestCase): + + def test_bug_domain_node_type_mismatch(self): # Bug: Domain node type should be Mermaid__Node but is MGraph__Node + with create_test_mermaid_graph() as graph: + domain_node = graph.graph.nodes()[0] + + # Current incorrect behavior + assert type(domain_node) is MGraph__Node # ✗ Wrong + assert type(domain_node.node) is Model__MGraph__Node # ✗ Wrong + + # Expected behavior (currently fails) + # assert type(domain_node) is Mermaid__Node # ✓ Should be this + # assert type(domain_node.node) is Model__Mermaid__Node # ✓ Should be this + + def test_bug_model_node_type_mismatch(self): # Bug: Model node type should be Model__Mermaid__Node but is Model__MGraph__Node + with create_test_mermaid_graph() as graph: + model_node = graph.graph.model.nodes()[0] + + # Current incorrect behavior + assert type(model_node) is Model__MGraph__Node # ✗ Wrong + assert type(model_node.data) is Schema__Mermaid__Node + + # Expected behavior (currently fails) + # assert type(model_node) is Model__Mermaid__Node # ✓ Should be this + + def test_bug_domain_edge_type_mismatch(self): # Bug: Domain edge type should be Mermaid__Edge but is MGraph__Edge + with create_test_mermaid_graph() as graph: + domain_edge = graph.graph.edges()[0] + + # Current incorrect behavior + assert type(domain_edge) is MGraph__Edge # ✗ Wrong + assert type(domain_edge.edge) is Model__MGraph__Edge # ✗ Wrong + + # Expected behavior (currently fails) + # assert type(domain_edge) is Mermaid__Edge # ✓ Should be this + # assert type(domain_edge.edge) is Model__Mermaid__Edge # ✓ Should be this + # assert domain_edge.graph.edge_model_type == Model__Mermaid__Edge # ✓ Should be this + + def test_bug_model_edge_type_mismatch( + self): # Bug: Model edge type should be Model__Mermaid__Edge but is Model__MGraph__Edge + with create_test_mermaid_graph() as graph: + model_edge = graph.graph.model.edges()[0] + + # Current incorrect behavior + assert type(model_edge) is Model__MGraph__Edge # ✗ Wrong + assert type(model_edge.data) is Schema__Mermaid__Edge + + # Expected behavior (currently fails) + # assert type(model_edge) is Model__Mermaid__Edge # ✓ Should be this + + def test_direct_node_type_mismatch(self): + graph = Mermaid__Graph() + graph_model = graph.model + mermaid_node = Schema__Mermaid__Node() + model_node = graph_model.add_node(mermaid_node) + + # Current behavior (showing type mismatch) + assert isinstance(model_node , Model__MGraph__Node ) # ✗ Wrong: Should be Model__Mermaid__Node + assert isinstance(model_node.data, Schema__Mermaid__Node) # ✓ Correct + + + domain_node = graph.node(mermaid_node.node_config.node_id) # Get node through domain layer + assert isinstance(domain_node, MGraph__Node) # ✗ Wrong: Should be Mermaid__Node \ No newline at end of file