Skip to content

Commit

Permalink
added test_Mermaid__MGraph and couple more misc fixes
Browse files Browse the repository at this point in the history
added test file with bug test__bugs__Mermaid
  • Loading branch information
DinisCruz committed Jan 9, 2025
1 parent f819591 commit 9488beb
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 45 deletions.
3 changes: 3 additions & 0 deletions mgraph_ai/mgraph/domain/MGraph__Graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions mgraph_ai/providers/mermaid/models/Model__Mermaid__Graph.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
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

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]



Expand Down
5 changes: 2 additions & 3 deletions mgraph_ai/providers/mermaid/utils/Mermaid__Random_Graph.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
31 changes: 31 additions & 0 deletions tests/unit/providers/mermaid/domain/test_Mermaid__Graph.py
Original file line number Diff line number Diff line change
@@ -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'))
24 changes: 0 additions & 24 deletions tests/unit/providers/mermaid/test_Mermaid_Graph.py

This file was deleted.

26 changes: 8 additions & 18 deletions tests/unit/providers/mermaid/utils/test_Mermaid__Random_Graph.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
74 changes: 74 additions & 0 deletions tests/unit/providers/mermaid/utils/test__bugs__Mermaid.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9488beb

Please sign in to comment.