Skip to content

Commit

Permalink
added tests for test_Mermaid_Node
Browse files Browse the repository at this point in the history
more misc fixes
  • Loading branch information
DinisCruz committed Jan 10, 2025
1 parent 21eb36d commit fddecc3
Show file tree
Hide file tree
Showing 15 changed files with 193 additions and 124 deletions.
5 changes: 4 additions & 1 deletion mgraph_ai/mgraph/domain/MGraph__Node.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,7 @@ def attribute(self, attribute_id: Random_Guid) -> MGraph__Attribute:
def attributes(self) -> List[MGraph__Attribute]: # Get all node attributes
return [MGraph__Attribute(attribute = Model__MGraph__Attribute(data=attr),
graph = self.graph )
for attr in self.node.data.attributes.values()]
for attr in self.node.data.attributes.values()]

def graph_id(self):
return self.graph.data.graph_config.graph_id
2 changes: 0 additions & 2 deletions mgraph_ai/providers/mermaid/domain/Mermaid__Edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@


class Mermaid__Edge(MGraph__Edge):
# model : Model__Mermaid__Edge
# config : Mermaid__Edge__Config
edge : Model__Mermaid__Edge
graph : Model__Mermaid__Graph
label : str
Expand Down
3 changes: 3 additions & 0 deletions mgraph_ai/providers/mermaid/domain/Mermaid__Node.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ def markdown(self, value=True):
self.config().markdown = value
return self

def node_key(self):
return self.node.data.key

def shape(self, shape=None):
self.config().node_shape = Schema__Mermaid__Node__Shape.get_shape(shape)
return self
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Type
from mgraph_ai.mgraph.schemas.Schema__MGraph__Attribute import Schema__MGraph__Attribute
from mgraph_ai.mgraph.schemas.Schema__MGraph__Default__Types import Schema__MGraph__Default__Types
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
Expand All @@ -7,6 +8,7 @@
from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Node__Config import Schema__Mermaid__Node__Config

class Schema__Mermaid__Default__Types(Schema__MGraph__Default__Types):
attribute_type : Type[Schema__MGraph__Attribute]
edge_type : Type[Schema__Mermaid__Edge ]
edge_config_type : Type[Schema__Mermaid__Edge__Config ]
graph_config_type: Type[Schema__Mermaid__Graph__Config]
Expand Down
14 changes: 8 additions & 6 deletions mgraph_ai/providers/mermaid/schemas/Schema__Mermaid__Node.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from typing import Type
from osbot_utils.helpers.Safe_Id import Safe_Id
from mgraph_ai.mgraph.schemas.Schema__MGraph__Node import Schema__MGraph__Node
from typing import 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 mgraph_ai.mgraph.schemas.Schema__MGraph__Node import Schema__MGraph__Node

class Schema__Mermaid__Node(Schema__MGraph__Node):
key : Safe_Id
label : str
node_type: Type['Schema__Mermaid__Node']
key : Safe_Id
label : str
node_config: Schema__Mermaid__Node__Config
node_type : Type['Schema__Mermaid__Node']
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ class Schema__Mermaid__Node__Config(Schema__MGraph__Node__Config):
node_shape : Schema__Mermaid__Node__Shape = Schema__Mermaid__Node__Shape.default
show_label : bool = True
wrap_with_quotes : bool = True # todo: add support for only using quotes when needed
value_type : type # todo: remove when TypeSafe BUG is fixed
126 changes: 126 additions & 0 deletions tests/unit/providers/mermaid/domain/test_Mermaid_Node.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
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 = __()),
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())

return # todo: wire up the methods below
with Mermaid() as _:
_.add_node(key='id')
assert _.code() == 'graph LR\n id["id"]\n'
pass
#pprint(Mermaid().json())

#return
with Mermaid() as _:
_.add_node(key='id').wrap_with_quotes(False)
assert _.code() == 'graph LR\n id[id]\n'

mermaid = Mermaid()
new_node = mermaid.add_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'

3 changes: 0 additions & 3 deletions tests/unit/providers/mermaid/domain/test_Mermaid__Node.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
from unittest import TestCase

from osbot_utils.utils.Dev import pprint

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
Expand Down
26 changes: 13 additions & 13 deletions tests/unit/providers/mermaid/schemas/test_Schema__Mermaid__Node.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
from unittest import TestCase
from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Node__Config import Schema__Mermaid__Node__Config
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__Node__Config import Schema__MGraph__Node__Config
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

class test_Schema__Mermaid__Node(TestCase):

def setUp(self): # Initialize test data
self.node_config = Schema__MGraph__Node__Config(node_id = Random_Guid(),
value_type = str)
self.attribute = Schema__MGraph__Attribute (attribute_id = Random_Guid() ,
attribute_name = Safe_Id('test') ,
attribute_value = "test_value" ,
attribute_type = str )
self.node_config = Schema__Mermaid__Node__Config(node_id = Random_Guid(),
value_type = str)
self.attribute = Schema__MGraph__Attribute (attribute_id = Random_Guid() ,
attribute_name = Safe_Id('test') ,
attribute_value = "test_value" ,
attribute_type = str )
self.attributes = {self.attribute.attribute_id: self.attribute}
self.node = Schema__Mermaid__Node (attributes = self.attributes ,
node_config = self.node_config ,
node_type = Schema__Mermaid__Node ,
value = "test_value" ,
key = Safe_Id("node_1") ,
label = "Test Node" )
self.node = Schema__Mermaid__Node (attributes = self.attributes ,
node_config = self.node_config ,
node_type = Schema__Mermaid__Node ,
value = "test_value" ,
key = Safe_Id("node_1") ,
label = "Test Node" )

def test_init(self): # Tests basic initialization and type checking
assert type(self.node) is Schema__Mermaid__Node
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/providers/mermaid/test_Mermaid.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from unittest import TestCase

from osbot_utils.utils.Objects import __
from mgraph_ai.providers.mermaid.Mermaid__Render import Mermaid__Render
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.domain.Mermaid__Edge import Mermaid__Edge
from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Diagram__Type import Schema__Mermaid__Diagram__Type
Expand Down
Loading

0 comments on commit fddecc3

Please sign in to comment.