Skip to content

Commit

Permalink
fixed naming convention with Schema__*_Config
Browse files Browse the repository at this point in the history
added tests for Mermaid Schema files
  • Loading branch information
DinisCruz committed Jan 9, 2025
1 parent f3965d3 commit f51a2d7
Show file tree
Hide file tree
Showing 32 changed files with 458 additions and 264 deletions.
16 changes: 8 additions & 8 deletions docs/formatting-spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
Imports should be aligned with the longest import path, using spaces between major groups:

```python
from unittest import TestCase
from mgraph_ai.schemas.Schema__MGraph__Node import Schema__MGraph__Node
from mgraph_ai.schemas.Schema__MGraph__Node_Config import Schema__MGraph__Node_Config
from mgraph_ai.schemas.Schema__MGraph__Attribute import Schema__MGraph__Attribute
from osbot_utils.helpers.Random_Guid import Random_Guid
from osbot_utils.helpers.Safe_Id import Safe_Id
from unittest import TestCase
from mgraph_ai.schemas.Schema__MGraph__Node import Schema__MGraph__Node
from mgraph_ai.schemas.Schema__MGraph__Node__Config import Schema__MGraph__Node__Config
from mgraph_ai.schemas.Schema__MGraph__Attribute import Schema__MGraph__Attribute
from osbot_utils.helpers.Random_Guid import Random_Guid
from osbot_utils.helpers.Safe_Id import Safe_Id
```

## Method Documentation
Expand All @@ -33,8 +33,8 @@ self.attribute = Schema__MGraph__Attribute(...)
Constructor calls should be formatted with aligned parameters, aligned equals signs, and aligned commas:

```python
node_config = Schema__MGraph__Node_Config(node_id = Random_Guid(),
value_type = str )
node_config = Schema__MGraph__Node__Config(node_id = Random_Guid(),
value_type = str )

attribute = Schema__MGraph__Attribute(attribute_id = Random_Guid() ,
attribute_name = Safe_Id('attr_1'),
Expand Down
16 changes: 8 additions & 8 deletions mgraph_ai/mgraph/models/Model__MGraph__Edge.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from typing import Type
from osbot_utils.helpers.Random_Guid import Random_Guid
from mgraph_ai.mgraph.schemas.Schema__MGraph__Edge_Config import Schema__MGraph__Edge_Config
from mgraph_ai.mgraph.schemas.Schema__MGraph__Node import Schema__MGraph__Node
from mgraph_ai.mgraph.schemas.Schema__MGraph__Edge import Schema__MGraph__Edge
from mgraph_ai.mgraph.schemas.Schema__MGraph__Attribute import Schema__MGraph__Attribute
from osbot_utils.type_safe.Type_Safe import Type_Safe
from typing import Type
from osbot_utils.helpers.Random_Guid import Random_Guid
from mgraph_ai.mgraph.schemas.Schema__MGraph__Edge__Config import Schema__MGraph__Edge__Config
from mgraph_ai.mgraph.schemas.Schema__MGraph__Node import Schema__MGraph__Node
from mgraph_ai.mgraph.schemas.Schema__MGraph__Edge import Schema__MGraph__Edge
from mgraph_ai.mgraph.schemas.Schema__MGraph__Attribute import Schema__MGraph__Attribute
from osbot_utils.type_safe.Type_Safe import Type_Safe


class Model__MGraph__Edge(Type_Safe):
Expand All @@ -23,7 +23,7 @@ def from_node_type(self) -> Type[Schema__MGraph__Node]:
def get_attribute(self, attribute_id: Random_Guid) -> Schema__MGraph__Attribute:
return self.data.attributes.get(attribute_id)

def edge_config(self) -> Schema__MGraph__Edge_Config:
def edge_config(self) -> Schema__MGraph__Edge__Config:
return self.data.edge_config

def edge_id(self) -> Random_Guid:
Expand Down
34 changes: 16 additions & 18 deletions mgraph_ai/mgraph/models/Model__MGraph__Graph.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
from typing import Any, Type, Dict, List

from osbot_utils.helpers.Random_Guid import Random_Guid

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.mgraph.schemas.Schema__MGraph__Attribute import Schema__MGraph__Attribute
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__Edge import Schema__MGraph__Edge
from mgraph_ai.mgraph.schemas.Schema__MGraph__Node_Config import Schema__MGraph__Node_Config
from mgraph_ai.mgraph.schemas.Schema__MGraph__Edge_Config import Schema__MGraph__Edge_Config
from osbot_utils.type_safe.Type_Safe import Type_Safe
from osbot_utils.type_safe.decorators.type_safe import type_safe
from typing import Any, Type, Dict, List
from osbot_utils.helpers.Random_Guid import Random_Guid
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.mgraph.schemas.Schema__MGraph__Attribute import Schema__MGraph__Attribute
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__Edge import Schema__MGraph__Edge
from mgraph_ai.mgraph.schemas.Schema__MGraph__Node__Config import Schema__MGraph__Node__Config
from mgraph_ai.mgraph.schemas.Schema__MGraph__Edge__Config import Schema__MGraph__Edge__Config
from osbot_utils.type_safe.Type_Safe import Type_Safe
from osbot_utils.type_safe.decorators.type_safe import type_safe


class Model__MGraph__Graph(Type_Safe):
Expand Down Expand Up @@ -40,7 +38,7 @@ def new_node(self, value : Any
if node_type is None:
node_type = self.data.graph_config.default_node_type

node_config = Schema__MGraph__Node_Config(value_type = type(value) )
node_config = Schema__MGraph__Node__Config(value_type = type(value))
node = Schema__MGraph__Node (attributes = attributes ,
node_config = node_config ,
node_type = node_type ,
Expand All @@ -59,9 +57,9 @@ def new_edge(self, from_node_id: Random_Guid,
if to_node is None:
raise ValueError(f"To node {to_node_id} not found")

edge_config = Schema__MGraph__Edge_Config(edge_id = Random_Guid() ,
from_node_type = self.data.nodes[from_node_id].node_type ,
to_node_type = self.data.nodes[to_node_id ].node_type )
edge_config = Schema__MGraph__Edge__Config(edge_id = Random_Guid(),
from_node_type = self.data.nodes[from_node_id].node_type,
to_node_type = self.data.nodes[to_node_id ].node_type)
edge = Schema__MGraph__Edge (attributes = {} ,
edge_config = edge_config ,
from_node_id = from_node_id ,
Expand Down
4 changes: 2 additions & 2 deletions mgraph_ai/mgraph/schemas/Schema__MGraph__Edge.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from typing import Dict, Type
from mgraph_ai.mgraph.schemas.Schema__MGraph__Attribute import Schema__MGraph__Attribute
from mgraph_ai.mgraph.schemas.Schema__MGraph__Edge_Config import Schema__MGraph__Edge_Config
from mgraph_ai.mgraph.schemas.Schema__MGraph__Edge__Config import Schema__MGraph__Edge__Config
from osbot_utils.type_safe.Type_Safe import Type_Safe
from osbot_utils.helpers.Random_Guid import Random_Guid

class Schema__MGraph__Edge(Type_Safe):
attributes : Dict[Random_Guid, Schema__MGraph__Attribute]
edge_config : Schema__MGraph__Edge_Config
edge_config : Schema__MGraph__Edge__Config
edge_type : Type['Schema__MGraph__Edge']
from_node_id : Random_Guid
to_node_id : Random_Guid
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from osbot_utils.helpers.Random_Guid import Random_Guid
from osbot_utils.type_safe.Type_Safe import Type_Safe

class Schema__MGraph__Edge_Config(Type_Safe):
class Schema__MGraph__Edge__Config(Type_Safe):
edge_id : Random_Guid
from_node_type: Type[Schema__MGraph__Node]
to_node_type : Type[Schema__MGraph__Node]
4 changes: 2 additions & 2 deletions mgraph_ai/mgraph/schemas/Schema__MGraph__Graph.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from typing import Dict, Type
from mgraph_ai.mgraph.schemas.Schema__MGraph__Edge import Schema__MGraph__Edge
from mgraph_ai.mgraph.schemas.Schema__MGraph__Graph_Config import Schema__MGraph__Graph_Config
from mgraph_ai.mgraph.schemas.Schema__MGraph__Graph__Config import Schema__MGraph__Graph__Config
from mgraph_ai.mgraph.schemas.Schema__MGraph__Node import Schema__MGraph__Node
from osbot_utils.type_safe.Type_Safe import Type_Safe
from osbot_utils.helpers.Random_Guid import Random_Guid

class Schema__MGraph__Graph(Type_Safe):
edges : Dict[Random_Guid, Schema__MGraph__Edge]
graph_config: Schema__MGraph__Graph_Config
graph_config: Schema__MGraph__Graph__Config
graph_type : Type['Schema__MGraph__Graph']
nodes : Dict[Random_Guid, Schema__MGraph__Node]
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from osbot_utils.helpers.Random_Guid import Random_Guid
from osbot_utils.type_safe.Type_Safe import Type_Safe

class Schema__MGraph__Graph_Config(Type_Safe):
class Schema__MGraph__Graph__Config(Type_Safe):
default_edge_type: Type[Schema__MGraph__Edge]
default_node_type: Type[Schema__MGraph__Node]
graph_id : Random_Guid
12 changes: 6 additions & 6 deletions mgraph_ai/mgraph/schemas/Schema__MGraph__Node.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from typing import Dict, Any, Type
from mgraph_ai.mgraph.schemas.Schema__MGraph__Attribute import Schema__MGraph__Attribute
from mgraph_ai.mgraph.schemas.Schema__MGraph__Node_Config import Schema__MGraph__Node_Config
from osbot_utils.helpers.Random_Guid import Random_Guid
from osbot_utils.type_safe.Type_Safe import Type_Safe
from typing import Dict, Any, Type
from mgraph_ai.mgraph.schemas.Schema__MGraph__Attribute import Schema__MGraph__Attribute
from mgraph_ai.mgraph.schemas.Schema__MGraph__Node__Config import Schema__MGraph__Node__Config
from osbot_utils.helpers.Random_Guid import Random_Guid
from osbot_utils.type_safe.Type_Safe import Type_Safe

class Schema__MGraph__Node(Type_Safe):
attributes : Dict[Random_Guid, Schema__MGraph__Attribute]
node_config: Schema__MGraph__Node_Config
node_config: Schema__MGraph__Node__Config
node_type : Type['Schema__MGraph__Node']
value : Any
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from osbot_utils.helpers.Random_Guid import Random_Guid
from osbot_utils.type_safe.Type_Safe import Type_Safe

class Schema__MGraph__Node_Config(Type_Safe):
class Schema__MGraph__Node__Config(Type_Safe):
node_id : Random_Guid
value_type: type
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import Type
from mgraph_ai.mgraph.schemas.Schema__MGraph__Edge_Config import Schema__MGraph__Edge_Config
from mgraph_ai.mgraph.schemas.Schema__MGraph__Edge__Config import Schema__MGraph__Edge__Config
from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Node import Schema__Mermaid__Node


class Schema__Mermaid__Edge__Config(Schema__MGraph__Edge_Config):
class Schema__Mermaid__Edge__Config(Schema__MGraph__Edge__Config):
from_node_type: Type[Schema__Mermaid__Node]
to_node_type : Type[Schema__Mermaid__Node]
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from typing import Type
from mgraph_ai.mgraph.schemas.Schema__MGraph__Graph_Config import Schema__MGraph__Graph_Config
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):
class Schema__Mermaid__Graph__Config(Schema__MGraph__Graph__Config):
default_edge_type : Type[Schema__Mermaid__Edge]
default_node_type : Type[Schema__Mermaid__Node]
allow_circle_edges : bool
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from mgraph_ai.mgraph.schemas.Schema__MGraph__Node__Config import Schema__MGraph__Node__Config
from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Node__Shape import Schema__Mermaid__Node__Shape
from osbot_utils.type_safe.Type_Safe import Type_Safe


class Schema__Mermaid__Node__Config(Type_Safe):
class Schema__Mermaid__Node__Config(Schema__MGraph__Node__Config):
markdown : bool
node_shape : Schema__Mermaid__Node__Shape = Schema__Mermaid__Node__Shape.default
show_label : bool = True
Expand Down
2 changes: 1 addition & 1 deletion modules/OSBot-Utils
32 changes: 0 additions & 32 deletions tests/unit/core/test_MGraphs.py

This file was deleted.

36 changes: 18 additions & 18 deletions tests/unit/mgraph/domain/test_MGraph__Edge.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
from unittest import TestCase
from osbot_utils.helpers.Safe_Id import Safe_Id
from mgraph_ai.mgraph.domain.MGraph__Edge import MGraph__Edge
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.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__Edge_Config import Schema__MGraph__Edge_Config
from mgraph_ai.mgraph.schemas.Schema__MGraph__Node_Config import Schema__MGraph__Node_Config
from osbot_utils.helpers.Random_Guid import Random_Guid
from unittest import TestCase
from osbot_utils.helpers.Safe_Id import Safe_Id
from mgraph_ai.mgraph.domain.MGraph__Edge import MGraph__Edge
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.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__Edge__Config import Schema__MGraph__Edge__Config
from mgraph_ai.mgraph.schemas.Schema__MGraph__Node__Config import Schema__MGraph__Node__Config
from osbot_utils.helpers.Random_Guid import Random_Guid

class test_MGraph__Edge(TestCase):

def setUp(self): # Initialize test data
self.graph = Model__MGraph__Graph(data=None) # Mock graph for testing


self.from_node_config = Schema__MGraph__Node_Config(node_id = Random_Guid(), # Create source and target nodes
value_type = str )
self.from_node_config = Schema__MGraph__Node__Config(node_id = Random_Guid(), # Create source and target nodes
value_type = str)
self.from_schema_node = Schema__MGraph__Node (attributes = {} ,
node_config = self.from_node_config,
node_type = Schema__MGraph__Node ,
value = "from_value" )
self.to_node_config = Schema__MGraph__Node_Config (node_id = Random_Guid(),
value_type = str )
self.to_node_config = Schema__MGraph__Node__Config (node_id = Random_Guid(),
value_type = str)
self.to_schema_node = Schema__MGraph__Node (attributes = {} ,
node_config = self.to_node_config,
node_type = Schema__MGraph__Node,
Expand All @@ -37,9 +37,9 @@ def setUp(self):
graph_type = Schema__MGraph__Graph )

# Create edge configuration and schema
self.edge_config = Schema__MGraph__Edge_Config(edge_id = Random_Guid(),
from_node_type = Schema__MGraph__Node,
to_node_type = Schema__MGraph__Node)
self.edge_config = Schema__MGraph__Edge__Config(edge_id = Random_Guid(),
from_node_type = Schema__MGraph__Node,
to_node_type = Schema__MGraph__Node)
self.schema_edge = Schema__MGraph__Edge (attributes = {} ,
edge_config = self.edge_config ,
edge_type = Schema__MGraph__Edge ,
Expand Down
Loading

0 comments on commit f51a2d7

Please sign in to comment.