Skip to content

Commit

Permalink
refactored to _experiments the previous code that might be useful whe…
Browse files Browse the repository at this point in the history
…n we look at improving the filters

achieved 100% code coverage
  • Loading branch information
DinisCruz committed Jan 11, 2025
1 parent c9c1b04 commit e5a56c2
Show file tree
Hide file tree
Showing 21 changed files with 547 additions and 684 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
File renamed without changes.
8 changes: 1 addition & 7 deletions mgraph_ai/mgraph/models/Model__MGraph__Edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
4 changes: 3 additions & 1 deletion mgraph_ai/providers/mermaid/actions/Mermaid__Edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
32 changes: 16 additions & 16 deletions tests/unit/mgraph/actions/test_MGraph__Data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
assert self.graph_data.node(non_existent_id) is None
assert self.graph_data.edge(non_existent_id) is None
10 changes: 9 additions & 1 deletion tests/unit/providers/mermaid/actions/test_Mermaid__Edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -113,4 +114,11 @@ def test_render_config(self):
diagram_direction ='LR' ,
diagram_type ='graph',
line_before_edges = True ,
directives = [] )
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
Loading

0 comments on commit e5a56c2

Please sign in to comment.