From f51a2d7dcc16d3fcf8844495f13146493f1bd328 Mon Sep 17 00:00:00 2001 From: Dinis Cruz Date: Thu, 9 Jan 2025 11:49:27 +0000 Subject: [PATCH] fixed naming convention with Schema__*_Config added tests for Mermaid Schema files --- docs/formatting-spec.md | 16 ++--- .../mgraph/models/Model__MGraph__Edge.py | 16 ++--- .../mgraph/models/Model__MGraph__Graph.py | 34 +++++---- .../mgraph/schemas/Schema__MGraph__Edge.py | 4 +- ...fig.py => Schema__MGraph__Edge__Config.py} | 2 +- .../mgraph/schemas/Schema__MGraph__Graph.py | 4 +- ...ig.py => Schema__MGraph__Graph__Config.py} | 2 +- .../mgraph/schemas/Schema__MGraph__Node.py | 12 ++-- ...fig.py => Schema__MGraph__Node__Config.py} | 2 +- .../schemas/Schema__Mermaid__Edge__Config.py | 4 +- .../schemas/Schema__Mermaid__Graph__Config.py | 4 +- .../schemas/Schema__Mermaid__Node__Config.py | 5 +- modules/OSBot-Utils | 2 +- tests/unit/core/test_MGraphs.py | 32 --------- tests/unit/mgraph/domain/test_MGraph__Edge.py | 36 +++++----- .../unit/mgraph/domain/test_MGraph__Graph.py | 30 ++++---- tests/unit/mgraph/domain/test_MGraph__Node.py | 20 +++--- .../mgraph/models/test_Model__MGraph__Edge.py | 18 ++--- .../models/test_Model__MGraph__Graph.py | 30 ++++---- .../mgraph/models/test_Model__MGraph__Node.py | 20 +++--- .../schemas/test_Schema__MGraph__Edge.py | 20 +++--- .../test_Schema__MGraph__Edge_Config.py | 32 ++++----- .../schemas/test_Schema__MGraph__Graph.py | 26 +++---- .../test_Schema__MGraph__Graph_Config.py | 40 +++++------ .../schemas/test_Schema__MGraph__Node.py | 26 +++---- .../test_Schema__MGraph__Node_Config.py | 36 +++++----- .../test_Schema__Mermaid__Edge__Config.py | 41 +++++++++++ .../schemas/test_Schema__Mermaid__Graph.py | 70 +++++++++++++++++++ .../test_Schema__Mermaid__Graph__Config.py | 47 +++++++++++++ .../schemas/test_Schema__Mermaid__Node.py | 20 +++--- .../test_Schema__Mermaid__Node__Config.py | 43 ++++++++++++ .../test_Schema__Mermaid__Node__Shape.py | 28 ++++++++ 32 files changed, 458 insertions(+), 264 deletions(-) rename mgraph_ai/mgraph/schemas/{Schema__MGraph__Edge_Config.py => Schema__MGraph__Edge__Config.py} (89%) rename mgraph_ai/mgraph/schemas/{Schema__MGraph__Graph_Config.py => Schema__MGraph__Graph__Config.py} (91%) rename mgraph_ai/mgraph/schemas/{Schema__MGraph__Node_Config.py => Schema__MGraph__Node__Config.py} (78%) delete mode 100644 tests/unit/core/test_MGraphs.py create mode 100644 tests/unit/providers/mermaid/schemas/test_Schema__Mermaid__Edge__Config.py create mode 100644 tests/unit/providers/mermaid/schemas/test_Schema__Mermaid__Graph.py create mode 100644 tests/unit/providers/mermaid/schemas/test_Schema__Mermaid__Graph__Config.py create mode 100644 tests/unit/providers/mermaid/schemas/test_Schema__Mermaid__Node__Config.py create mode 100644 tests/unit/providers/mermaid/schemas/test_Schema__Mermaid__Node__Shape.py diff --git a/docs/formatting-spec.md b/docs/formatting-spec.md index bc7d9c0..9081e42 100644 --- a/docs/formatting-spec.md +++ b/docs/formatting-spec.md @@ -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 @@ -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'), diff --git a/mgraph_ai/mgraph/models/Model__MGraph__Edge.py b/mgraph_ai/mgraph/models/Model__MGraph__Edge.py index 318fd36..bb3088b 100644 --- a/mgraph_ai/mgraph/models/Model__MGraph__Edge.py +++ b/mgraph_ai/mgraph/models/Model__MGraph__Edge.py @@ -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): @@ -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: diff --git a/mgraph_ai/mgraph/models/Model__MGraph__Graph.py b/mgraph_ai/mgraph/models/Model__MGraph__Graph.py index a7da9bd..9ae938d 100644 --- a/mgraph_ai/mgraph/models/Model__MGraph__Graph.py +++ b/mgraph_ai/mgraph/models/Model__MGraph__Graph.py @@ -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): @@ -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 , @@ -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 , diff --git a/mgraph_ai/mgraph/schemas/Schema__MGraph__Edge.py b/mgraph_ai/mgraph/schemas/Schema__MGraph__Edge.py index fa42cbf..0b7f834 100644 --- a/mgraph_ai/mgraph/schemas/Schema__MGraph__Edge.py +++ b/mgraph_ai/mgraph/schemas/Schema__MGraph__Edge.py @@ -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 \ No newline at end of file diff --git a/mgraph_ai/mgraph/schemas/Schema__MGraph__Edge_Config.py b/mgraph_ai/mgraph/schemas/Schema__MGraph__Edge__Config.py similarity index 89% rename from mgraph_ai/mgraph/schemas/Schema__MGraph__Edge_Config.py rename to mgraph_ai/mgraph/schemas/Schema__MGraph__Edge__Config.py index ad59287..5aa7118 100644 --- a/mgraph_ai/mgraph/schemas/Schema__MGraph__Edge_Config.py +++ b/mgraph_ai/mgraph/schemas/Schema__MGraph__Edge__Config.py @@ -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] \ No newline at end of file diff --git a/mgraph_ai/mgraph/schemas/Schema__MGraph__Graph.py b/mgraph_ai/mgraph/schemas/Schema__MGraph__Graph.py index be402f6..f949f00 100644 --- a/mgraph_ai/mgraph/schemas/Schema__MGraph__Graph.py +++ b/mgraph_ai/mgraph/schemas/Schema__MGraph__Graph.py @@ -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] diff --git a/mgraph_ai/mgraph/schemas/Schema__MGraph__Graph_Config.py b/mgraph_ai/mgraph/schemas/Schema__MGraph__Graph__Config.py similarity index 91% rename from mgraph_ai/mgraph/schemas/Schema__MGraph__Graph_Config.py rename to mgraph_ai/mgraph/schemas/Schema__MGraph__Graph__Config.py index 9ae4d02..92804bd 100644 --- a/mgraph_ai/mgraph/schemas/Schema__MGraph__Graph_Config.py +++ b/mgraph_ai/mgraph/schemas/Schema__MGraph__Graph__Config.py @@ -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 \ No newline at end of file diff --git a/mgraph_ai/mgraph/schemas/Schema__MGraph__Node.py b/mgraph_ai/mgraph/schemas/Schema__MGraph__Node.py index 017cbed..4d0d25c 100644 --- a/mgraph_ai/mgraph/schemas/Schema__MGraph__Node.py +++ b/mgraph_ai/mgraph/schemas/Schema__MGraph__Node.py @@ -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 \ No newline at end of file diff --git a/mgraph_ai/mgraph/schemas/Schema__MGraph__Node_Config.py b/mgraph_ai/mgraph/schemas/Schema__MGraph__Node__Config.py similarity index 78% rename from mgraph_ai/mgraph/schemas/Schema__MGraph__Node_Config.py rename to mgraph_ai/mgraph/schemas/Schema__MGraph__Node__Config.py index ae1871c..f5e7d89 100644 --- a/mgraph_ai/mgraph/schemas/Schema__MGraph__Node_Config.py +++ b/mgraph_ai/mgraph/schemas/Schema__MGraph__Node__Config.py @@ -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 \ No newline at end of file diff --git a/mgraph_ai/providers/mermaid/schemas/Schema__Mermaid__Edge__Config.py b/mgraph_ai/providers/mermaid/schemas/Schema__Mermaid__Edge__Config.py index fa13053..c34cdb7 100644 --- a/mgraph_ai/providers/mermaid/schemas/Schema__Mermaid__Edge__Config.py +++ b/mgraph_ai/providers/mermaid/schemas/Schema__Mermaid__Edge__Config.py @@ -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] \ No newline at end of file diff --git a/mgraph_ai/providers/mermaid/schemas/Schema__Mermaid__Graph__Config.py b/mgraph_ai/providers/mermaid/schemas/Schema__Mermaid__Graph__Config.py index c898e7a..8b42ce2 100644 --- a/mgraph_ai/providers/mermaid/schemas/Schema__Mermaid__Graph__Config.py +++ b/mgraph_ai/providers/mermaid/schemas/Schema__Mermaid__Graph__Config.py @@ -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 diff --git a/mgraph_ai/providers/mermaid/schemas/Schema__Mermaid__Node__Config.py b/mgraph_ai/providers/mermaid/schemas/Schema__Mermaid__Node__Config.py index 41216e0..7ab927a 100644 --- a/mgraph_ai/providers/mermaid/schemas/Schema__Mermaid__Node__Config.py +++ b/mgraph_ai/providers/mermaid/schemas/Schema__Mermaid__Node__Config.py @@ -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 diff --git a/modules/OSBot-Utils b/modules/OSBot-Utils index a6b0bed..9893ff5 160000 --- a/modules/OSBot-Utils +++ b/modules/OSBot-Utils @@ -1 +1 @@ -Subproject commit a6b0bed7775f8a6fb04c2f65f21993a98f9f9053 +Subproject commit 9893ff5783ddd9cbdcf3510e099f691e831f8c48 diff --git a/tests/unit/core/test_MGraphs.py b/tests/unit/core/test_MGraphs.py deleted file mode 100644 index 3be73fa..0000000 --- a/tests/unit/core/test_MGraphs.py +++ /dev/null @@ -1,32 +0,0 @@ -import pytest -from unittest import TestCase -from mgraph_ai.core.MGraph__Config import MGraph__Config -from mgraph_ai.core.MGraphs import MGraphs - -class test_MGraphs(TestCase): - - def setUp(self): - pytest.skip("todo: fix these tests after MGraph refactoring") - self.MGraphs = MGraphs() - self.config = MGraph__Config() - - - #@pytest.mark.skip("todo: implement pickle save") - def test_new__random(self): - #self.config.graph_title = 'Random Graph - from tests' - mgraph = self.MGraphs.new__random() - assert len(mgraph.nodes()) == 10 - assert len(mgraph.edges()) > 10 - #pprint(MGraph) - #MGraph.data().print() - # saved_graph = MGraph.save() - # pprint(saved_graph) - # MGraph_2 = self.MGraphs.load(saved_graph) - # pprint(MGraph_2) - # #MGraph_2.print() - # - # @pytest.mark.skip("todo: remove hard coded path") - # def test_load(self): - # saved_graph = '/var/folders/sj/ks1b_pjd749gk5ssdd1769kc0000gn/T/tmpo3emajer.pickle' - # MGraph = self.MGraphs.load(saved_graph) - # MGraph.print() \ No newline at end of file diff --git a/tests/unit/mgraph/domain/test_MGraph__Edge.py b/tests/unit/mgraph/domain/test_MGraph__Edge.py index 49d477e..51134a4 100644 --- a/tests/unit/mgraph/domain/test_MGraph__Edge.py +++ b/tests/unit/mgraph/domain/test_MGraph__Edge.py @@ -1,14 +1,14 @@ -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): @@ -16,14 +16,14 @@ def setUp(self): 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, @@ -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 , diff --git a/tests/unit/mgraph/domain/test_MGraph__Graph.py b/tests/unit/mgraph/domain/test_MGraph__Graph.py index f89bb6d..6fe87de 100644 --- a/tests/unit/mgraph/domain/test_MGraph__Graph.py +++ b/tests/unit/mgraph/domain/test_MGraph__Graph.py @@ -1,24 +1,24 @@ -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.domain.MGraph__Node import MGraph__Node -from mgraph_ai.mgraph.models.Model__MGraph__Node import Model__MGraph__Node -from mgraph_ai.mgraph.domain.MGraph__Graph import MGraph__Graph -from mgraph_ai.mgraph.models.Model__MGraph__Graph import Model__MGraph__Graph -from mgraph_ai.mgraph.schemas.Schema__MGraph__Graph import Schema__MGraph__Graph -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 mgraph_ai.mgraph.schemas.Schema__MGraph__Attribute import Schema__MGraph__Attribute -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.domain.MGraph__Node import MGraph__Node +from mgraph_ai.mgraph.models.Model__MGraph__Node import Model__MGraph__Node +from mgraph_ai.mgraph.domain.MGraph__Graph import MGraph__Graph +from mgraph_ai.mgraph.models.Model__MGraph__Graph import Model__MGraph__Graph +from mgraph_ai.mgraph.schemas.Schema__MGraph__Graph import Schema__MGraph__Graph +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 mgraph_ai.mgraph.schemas.Schema__MGraph__Attribute import Schema__MGraph__Attribute +from osbot_utils.helpers.Random_Guid import Random_Guid class Simple_Node(Schema__MGraph__Node): pass # Helper class for testing class test_MGraph__Graph(TestCase): def setUp(self): # Initialize test data - self.graph_config = Schema__MGraph__Graph_Config(graph_id = Random_Guid(), - default_node_type = Simple_Node , - default_edge_type = None ) + self.graph_config = Schema__MGraph__Graph__Config(graph_id = Random_Guid(), + default_node_type = Simple_Node, + default_edge_type = None) self.schema_graph = Schema__MGraph__Graph (nodes = {} , edges = {} , graph_config = self.graph_config , diff --git a/tests/unit/mgraph/domain/test_MGraph__Node.py b/tests/unit/mgraph/domain/test_MGraph__Node.py index 4020e34..4aa02be 100644 --- a/tests/unit/mgraph/domain/test_MGraph__Node.py +++ b/tests/unit/mgraph/domain/test_MGraph__Node.py @@ -1,17 +1,17 @@ -from unittest import TestCase -from osbot_utils.helpers.Safe_Id import Safe_Id -from mgraph_ai.mgraph.domain.MGraph__Node import MGraph__Node -from mgraph_ai.mgraph.models.Model__MGraph__Node import Model__MGraph__Node -from mgraph_ai.mgraph.models.Model__MGraph__Graph import Model__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 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__Node import MGraph__Node +from mgraph_ai.mgraph.models.Model__MGraph__Node import Model__MGraph__Node +from mgraph_ai.mgraph.models.Model__MGraph__Graph import Model__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 osbot_utils.helpers.Random_Guid import Random_Guid class test_MGraph__Node(TestCase): def setUp(self): # Initialize test data - self.node_config = Schema__MGraph__Node_Config(node_id = Random_Guid(), - value_type = str ) + self.node_config = Schema__MGraph__Node__Config(node_id = Random_Guid(), + value_type = str) self.schema_node = Schema__MGraph__Node (attributes = {} , node_config = self.node_config , node_type = Schema__MGraph__Node, diff --git a/tests/unit/mgraph/models/test_Model__MGraph__Edge.py b/tests/unit/mgraph/models/test_Model__MGraph__Edge.py index 8ad9ef3..2c09865 100644 --- a/tests/unit/mgraph/models/test_Model__MGraph__Edge.py +++ b/tests/unit/mgraph/models/test_Model__MGraph__Edge.py @@ -1,18 +1,18 @@ -from unittest import TestCase -from mgraph_ai.mgraph.models.Model__MGraph__Edge import Model__MGraph__Edge -from mgraph_ai.mgraph.schemas.Schema__MGraph__Edge import Schema__MGraph__Edge -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__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.mgraph.models.Model__MGraph__Edge import Model__MGraph__Edge +from mgraph_ai.mgraph.schemas.Schema__MGraph__Edge import Schema__MGraph__Edge +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__Attribute import Schema__MGraph__Attribute +from osbot_utils.helpers.Random_Guid import Random_Guid +from osbot_utils.helpers.Safe_Id import Safe_Id class test_Model__MGraph__Edge(TestCase): def setUp(self): # Initialize test data self.from_node_id = Random_Guid() self.to_node_id = Random_Guid() - self.edge_config = Schema__MGraph__Edge_Config( + self.edge_config = Schema__MGraph__Edge__Config( edge_id = Random_Guid(), from_node_type = Schema__MGraph__Node, to_node_type = Schema__MGraph__Node diff --git a/tests/unit/mgraph/models/test_Model__MGraph__Graph.py b/tests/unit/mgraph/models/test_Model__MGraph__Graph.py index e8bc2ab..f67c454 100644 --- a/tests/unit/mgraph/models/test_Model__MGraph__Graph.py +++ b/tests/unit/mgraph/models/test_Model__MGraph__Graph.py @@ -1,25 +1,25 @@ import pytest -from unittest import TestCase -from osbot_utils.helpers.Safe_Id import Safe_Id -from osbot_utils.utils.Misc import is_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.models.Model__MGraph__Graph import Model__MGraph__Graph -from mgraph_ai.mgraph.schemas.Schema__MGraph__Graph import Schema__MGraph__Graph -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 mgraph_ai.mgraph.schemas.Schema__MGraph__Edge import Schema__MGraph__Edge -from osbot_utils.helpers.Random_Guid import Random_Guid +from unittest import TestCase +from osbot_utils.helpers.Safe_Id import Safe_Id +from osbot_utils.utils.Misc import is_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.models.Model__MGraph__Graph import Model__MGraph__Graph +from mgraph_ai.mgraph.schemas.Schema__MGraph__Graph import Schema__MGraph__Graph +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 mgraph_ai.mgraph.schemas.Schema__MGraph__Edge import Schema__MGraph__Edge +from osbot_utils.helpers.Random_Guid import Random_Guid class Simple_Node(Schema__MGraph__Node): pass # Helper class for testing class test_Model__MGraph__Graph(TestCase): def setUp(self): # Initialize test data - self.graph_config = Schema__MGraph__Graph_Config(graph_id = Random_Guid() , - default_node_type = Simple_Node , - default_edge_type = Schema__MGraph__Edge ) + self.graph_config = Schema__MGraph__Graph__Config(graph_id = Random_Guid(), + default_node_type = Simple_Node, + default_edge_type = Schema__MGraph__Edge) self.graph_data = Schema__MGraph__Graph (edges = {} , nodes = {} , graph_config = self.graph_config , diff --git a/tests/unit/mgraph/models/test_Model__MGraph__Node.py b/tests/unit/mgraph/models/test_Model__MGraph__Node.py index e04a290..6928462 100644 --- a/tests/unit/mgraph/models/test_Model__MGraph__Node.py +++ b/tests/unit/mgraph/models/test_Model__MGraph__Node.py @@ -1,16 +1,16 @@ -from unittest import TestCase -from mgraph_ai.mgraph.models.Model__MGraph__Node import Model__MGraph__Node -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.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.mgraph.models.Model__MGraph__Node import Model__MGraph__Node +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.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 class test_Model__MGraph__Node(TestCase): def setUp(self): # Initialize test data - self.node_config = Schema__MGraph__Node_Config(node_id = Random_Guid(), - value_type = str ) + self.node_config = Schema__MGraph__Node__Config(node_id = Random_Guid(), + value_type = str) self.node = Schema__MGraph__Node (attributes = {} , node_config = self.node_config , node_type = Schema__MGraph__Node, @@ -33,7 +33,7 @@ def test_set_value_with_type_check(self): assert str(context.exception) == "Value must be of type " def test_set_value_without_type_check(self): # Tests value setting without type validation - node_config = Schema__MGraph__Node_Config( + node_config = Schema__MGraph__Node__Config( node_id = Random_Guid(), value_type = None ) diff --git a/tests/unit/mgraph/schemas/test_Schema__MGraph__Edge.py b/tests/unit/mgraph/schemas/test_Schema__MGraph__Edge.py index 55636e1..1542028 100644 --- a/tests/unit/mgraph/schemas/test_Schema__MGraph__Edge.py +++ b/tests/unit/mgraph/schemas/test_Schema__MGraph__Edge.py @@ -1,19 +1,19 @@ -from unittest import TestCase -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__Attribute import Schema__MGraph__Attribute -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__Edge import Schema__MGraph__Edge +from unittest import TestCase +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__Attribute import Schema__MGraph__Attribute +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__Edge import Schema__MGraph__Edge class test_Schema__MGraph__Edge(TestCase): def setUp(self): # Initialize test data self.from_node_id = Random_Guid() self.to_node_id = Random_Guid() - 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.attribute = Schema__MGraph__Attribute (attribute_id = Random_Guid() , attribute_name = Safe_Id('test_attr') , attribute_value = "test_value" , diff --git a/tests/unit/mgraph/schemas/test_Schema__MGraph__Edge_Config.py b/tests/unit/mgraph/schemas/test_Schema__MGraph__Edge_Config.py index 39804b0..37f4037 100644 --- a/tests/unit/mgraph/schemas/test_Schema__MGraph__Edge_Config.py +++ b/tests/unit/mgraph/schemas/test_Schema__MGraph__Edge_Config.py @@ -1,43 +1,43 @@ -from unittest import TestCase -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 osbot_utils.helpers.Random_Guid import Random_Guid +from unittest import TestCase +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 osbot_utils.helpers.Random_Guid import Random_Guid class Simple_Node(Schema__MGraph__Node): pass # Helper class for testing -class test_Schema__MGraph__Edge_Config(TestCase): +class test_Schema__MGraph__Edge__Config(TestCase): def setUp(self): # Initialize test data self.edge_id = Random_Guid() self.from_node_type = Simple_Node self.to_node_type = Simple_Node - self.edge_config = Schema__MGraph__Edge_Config(edge_id = self.edge_id , - from_node_type = self.from_node_type, - to_node_type = self.to_node_type ) + self.edge_config = Schema__MGraph__Edge__Config(edge_id = self.edge_id, + from_node_type = self.from_node_type, + to_node_type = self.to_node_type) def test_init(self): # Tests basic initialization and type checking - assert type(self.edge_config) is Schema__MGraph__Edge_Config + assert type(self.edge_config) is Schema__MGraph__Edge__Config assert self.edge_config.edge_id == self.edge_id assert self.edge_config.from_node_type == self.from_node_type assert self.edge_config.to_node_type == self.to_node_type def test_type_safety_validation(self): # Tests type safety validations with self.assertRaises(ValueError) as context: - Schema__MGraph__Edge_Config(edge_id = "not-a-guid" , - from_node_type = self.from_node_type, - to_node_type = self.to_node_type ) + Schema__MGraph__Edge__Config(edge_id ="not-a-guid", + from_node_type = self.from_node_type, + to_node_type = self.to_node_type) assert str(context.exception) == "in Random_Guid: value provided was not a Guid: not-a-guid" with self.assertRaises(ValueError) as context: - Schema__MGraph__Edge_Config(edge_id = self.edge_id , - from_node_type = "not-a-type" , - to_node_type = self.to_node_type) + Schema__MGraph__Edge__Config(edge_id = self.edge_id, + from_node_type = "not-a-type", + to_node_type = self.to_node_type) assert 'Invalid type for attribute' in str(context.exception) def test_different_node_types(self): # Tests different combinations of node types class Another_Node(Schema__MGraph__Node): pass - edge_config = Schema__MGraph__Edge_Config( + edge_config = Schema__MGraph__Edge__Config( edge_id = Random_Guid(), from_node_type = Simple_Node, to_node_type = Another_Node diff --git a/tests/unit/mgraph/schemas/test_Schema__MGraph__Graph.py b/tests/unit/mgraph/schemas/test_Schema__MGraph__Graph.py index 7c0e37c..78a64e2 100644 --- a/tests/unit/mgraph/schemas/test_Schema__MGraph__Graph.py +++ b/tests/unit/mgraph/schemas/test_Schema__MGraph__Graph.py @@ -1,24 +1,24 @@ -from unittest import TestCase -from mgraph_ai.mgraph.schemas.Schema__MGraph__Graph import Schema__MGraph__Graph -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 mgraph_ai.mgraph.schemas.Schema__MGraph__Node_Config import Schema__MGraph__Node_Config -from mgraph_ai.mgraph.schemas.Schema__MGraph__Edge import Schema__MGraph__Edge -from mgraph_ai.mgraph.schemas.Schema__MGraph__Edge_Config import Schema__MGraph__Edge_Config -from osbot_utils.helpers.Random_Guid import Random_Guid +from unittest import TestCase +from mgraph_ai.mgraph.schemas.Schema__MGraph__Graph import Schema__MGraph__Graph +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 mgraph_ai.mgraph.schemas.Schema__MGraph__Node__Config import Schema__MGraph__Node__Config +from mgraph_ai.mgraph.schemas.Schema__MGraph__Edge import Schema__MGraph__Edge +from mgraph_ai.mgraph.schemas.Schema__MGraph__Edge__Config import Schema__MGraph__Edge__Config +from osbot_utils.helpers.Random_Guid import Random_Guid class Simple_Node(Schema__MGraph__Node): pass # Helper class for testing class test_Schema__MGraph__Graph(TestCase): def setUp(self): # Initialize test data - self.graph_config = Schema__MGraph__Graph_Config( + self.graph_config = Schema__MGraph__Graph__Config( graph_id = Random_Guid(), default_node_type = Simple_Node, default_edge_type = Schema__MGraph__Edge ) - self.node_config = Schema__MGraph__Node_Config( + self.node_config = Schema__MGraph__Node__Config( node_id = Random_Guid(), value_type = str ) @@ -29,7 +29,7 @@ def setUp(self): # Initialize test data value = "test_value" ) - self.edge_config = Schema__MGraph__Edge_Config( + self.edge_config = Schema__MGraph__Edge__Config( edge_id = Random_Guid(), from_node_type = Simple_Node, to_node_type = Simple_Node @@ -77,7 +77,7 @@ def test_type_safety_validation(self): # Tests type safety validations assert "Expected a dictionary, but got ''" == str(context.exception) def test_multiple_nodes_and_edges(self): # Tests graph with multiple nodes and edges - node_config_2 = Schema__MGraph__Node_Config( + node_config_2 = Schema__MGraph__Node__Config( node_id = Random_Guid(), value_type = int ) @@ -88,7 +88,7 @@ def test_multiple_nodes_and_edges(self): # Tests graph with multiple nodes an value = 42 ) - edge_config_2 = Schema__MGraph__Edge_Config( + edge_config_2 = Schema__MGraph__Edge__Config( edge_id = Random_Guid(), from_node_type = Simple_Node, to_node_type = Simple_Node diff --git a/tests/unit/mgraph/schemas/test_Schema__MGraph__Graph_Config.py b/tests/unit/mgraph/schemas/test_Schema__MGraph__Graph_Config.py index 735637d..e9442d5 100644 --- a/tests/unit/mgraph/schemas/test_Schema__MGraph__Graph_Config.py +++ b/tests/unit/mgraph/schemas/test_Schema__MGraph__Graph_Config.py @@ -1,46 +1,46 @@ -from unittest import TestCase -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 mgraph_ai.mgraph.schemas.Schema__MGraph__Edge import Schema__MGraph__Edge -from osbot_utils.helpers.Random_Guid import Random_Guid +from unittest import TestCase +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 mgraph_ai.mgraph.schemas.Schema__MGraph__Edge import Schema__MGraph__Edge +from osbot_utils.helpers.Random_Guid import Random_Guid class Simple_Node(Schema__MGraph__Node): pass # Helper class for testing -class test__int__Schema__MGraph__Graph_Config(TestCase): +class test__int__Schema__MGraph__Graph__Config(TestCase): def setUp(self): # Initialize test data self.graph_id = Random_Guid() - self.graph_type = Schema__MGraph__Graph_Config + self.graph_type = Schema__MGraph__Graph__Config self.default_node_type = Simple_Node self.default_edge_type = Schema__MGraph__Edge - self.graph_config = Schema__MGraph__Graph_Config(graph_id = self.graph_id , - default_node_type = self.default_node_type, - default_edge_type = self.default_edge_type) + self.graph_config = Schema__MGraph__Graph__Config(graph_id = self.graph_id, + default_node_type = self.default_node_type, + default_edge_type = self.default_edge_type) def test_init(self): # Tests basic initialization and type checking - assert type(self.graph_config) is Schema__MGraph__Graph_Config + assert type(self.graph_config) is Schema__MGraph__Graph__Config assert self.graph_config.graph_id == self.graph_id assert self.graph_config.default_node_type == self.default_node_type assert self.graph_config.default_edge_type == self.default_edge_type def test_type_safety_validation(self): # Tests type safety validations with self.assertRaises(ValueError) as context: - Schema__MGraph__Graph_Config(graph_id = "not-a-guid" , # Should be Random_Guid - default_node_type = self.default_node_type, - default_edge_type = self.default_edge_type ) + Schema__MGraph__Graph__Config(graph_id ="not-a-guid", # Should be Random_Guid + default_node_type = self.default_node_type, + default_edge_type = self.default_edge_type) assert str(context.exception) == "in Random_Guid: value provided was not a Guid: not-a-guid" with self.assertRaises(ValueError) as context: - Schema__MGraph__Graph_Config(graph_id = self.graph_id , - default_node_type = "not-a-type" , # Should be type - default_edge_type = self.default_edge_type) + Schema__MGraph__Graph__Config(graph_id = self.graph_id, + default_node_type = "not-a-type", # Should be type + default_edge_type = self.default_edge_type) assert 'Invalid type for attribute' in str(context.exception) def test_different_node_and_edge_types(self): # Tests different combinations of node/edge types class Another_Node(Schema__MGraph__Node): pass - graph_config = Schema__MGraph__Graph_Config(graph_id = Random_Guid() , - default_node_type = Another_Node , - default_edge_type = Schema__MGraph__Edge) + graph_config = Schema__MGraph__Graph__Config(graph_id = Random_Guid(), + default_node_type = Another_Node, + default_edge_type = Schema__MGraph__Edge) assert graph_config.default_node_type == Another_Node assert graph_config.default_edge_type == Schema__MGraph__Edge \ No newline at end of file diff --git a/tests/unit/mgraph/schemas/test_Schema__MGraph__Node.py b/tests/unit/mgraph/schemas/test_Schema__MGraph__Node.py index a04b36e..5d1d875 100644 --- a/tests/unit/mgraph/schemas/test_Schema__MGraph__Node.py +++ b/tests/unit/mgraph/schemas/test_Schema__MGraph__Node.py @@ -1,15 +1,15 @@ -from unittest import TestCase -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.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.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.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 class test_Schema__MGraph__Node(TestCase): def setUp(self): # Initialize test data - self.node_config = Schema__MGraph__Node_Config(node_id = Random_Guid(), - value_type = str ) + 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_attr'), @@ -38,14 +38,14 @@ def test_type_safety_validation(self): with self.assertRaises(ValueError) as context: Schema__MGraph__Node(attributes = {self.attribute.attribute_id: self.attribute}, - node_config = "not-a-node-config" , # Should be Schema__MGraph__Node_Config + node_config = "not-a-node-config" , # Should be Schema__MGraph__Node__Config node_type = Schema__MGraph__Node , value = "test_node_value" ) assert 'Invalid type for attribute' in str(context.exception) def test_different_value_types(self): # Tests nodes with different value types - node_config_int = Schema__MGraph__Node_Config(node_id = Random_Guid(), - value_type = int ) + node_config_int = Schema__MGraph__Node__Config(node_id = Random_Guid(), + value_type = int) node_int = Schema__MGraph__Node(attributes = {} , node_config = node_config_int , @@ -53,8 +53,8 @@ def test_different_value_types(self): # Tests nodes with different value type value = 42 ) assert node_int.value == 42 - node_config_bool = Schema__MGraph__Node_Config(node_id = Random_Guid(), - value_type = bool ) + node_config_bool = Schema__MGraph__Node__Config(node_id = Random_Guid(), + value_type = bool) node_bool = Schema__MGraph__Node(attributes = {} , node_config = node_config_bool , diff --git a/tests/unit/mgraph/schemas/test_Schema__MGraph__Node_Config.py b/tests/unit/mgraph/schemas/test_Schema__MGraph__Node_Config.py index 1a84ce2..626eb44 100644 --- a/tests/unit/mgraph/schemas/test_Schema__MGraph__Node_Config.py +++ b/tests/unit/mgraph/schemas/test_Schema__MGraph__Node_Config.py @@ -1,45 +1,45 @@ -from unittest import TestCase -from mgraph_ai.mgraph.schemas.Schema__MGraph__Node_Config import Schema__MGraph__Node_Config -from mgraph_ai.mgraph.schemas.Schema__MGraph__Node import Schema__MGraph__Node -from osbot_utils.helpers.Random_Guid import Random_Guid +from unittest import TestCase +from mgraph_ai.mgraph.schemas.Schema__MGraph__Node__Config import Schema__MGraph__Node__Config +from mgraph_ai.mgraph.schemas.Schema__MGraph__Node import Schema__MGraph__Node +from osbot_utils.helpers.Random_Guid import Random_Guid class Simple_Node(Schema__MGraph__Node): pass # Helper class for testing -class test_Schema__MGraph__Node_Config(TestCase): +class test_Schema__MGraph__Node__Config(TestCase): def setUp(self): # Initialize test data self.node_id = Random_Guid() self.value_type = str - self.node_config = Schema__MGraph__Node_Config(node_id = self.node_id , - value_type = self.value_type) + self.node_config = Schema__MGraph__Node__Config(node_id = self.node_id, + value_type = self.value_type) def test_init(self): # Tests basic initialization and type checking - assert type(self.node_config) is Schema__MGraph__Node_Config + assert type(self.node_config) is Schema__MGraph__Node__Config assert self.node_config.node_id == self.node_id assert self.node_config.value_type == self.value_type def test_type_safety_validation(self): # Tests type safety validations with self.assertRaises(ValueError) as context: - Schema__MGraph__Node_Config(node_id = "not-a-guid", # Should be Random_Guid - value_type = self.value_type) + Schema__MGraph__Node__Config(node_id ="not-a-guid", # Should be Random_Guid + value_type = self.value_type) assert str(context.exception) == "in Random_Guid: value provided was not a Guid: not-a-guid" with self.assertRaises(ValueError) as context: - Schema__MGraph__Node_Config(node_id = self.node_id, - value_type = "not-a-type") # Should be type + Schema__MGraph__Node__Config(node_id = self.node_id, + value_type = "not-a-type") # Should be type assert 'Invalid type for attribute' in str(context.exception) def test_different_value_types(self): # Tests different value type combinations - node_config_1 = Schema__MGraph__Node_Config(node_id = Random_Guid(), - value_type = dict ) + node_config_1 = Schema__MGraph__Node__Config(node_id = Random_Guid(), + value_type = dict) assert node_config_1.value_type == dict class CustomValueType: pass - node_config_2 = Schema__MGraph__Node_Config(node_id = Random_Guid() , - value_type = CustomValueType) + node_config_2 = Schema__MGraph__Node__Config(node_id = Random_Guid(), + value_type = CustomValueType) assert node_config_2.value_type == CustomValueType - node_config_3 = Schema__MGraph__Node_Config(node_id = Random_Guid(), - value_type = int ) + node_config_3 = Schema__MGraph__Node__Config(node_id = Random_Guid(), + value_type = int) assert node_config_3.value_type == int \ No newline at end of file diff --git a/tests/unit/providers/mermaid/schemas/test_Schema__Mermaid__Edge__Config.py b/tests/unit/providers/mermaid/schemas/test_Schema__Mermaid__Edge__Config.py new file mode 100644 index 0000000..05731cd --- /dev/null +++ b/tests/unit/providers/mermaid/schemas/test_Schema__Mermaid__Edge__Config.py @@ -0,0 +1,41 @@ +from unittest import TestCase +from osbot_utils.helpers.Random_Guid import Random_Guid +from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Edge__Config import Schema__Mermaid__Edge__Config +from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Node import Schema__Mermaid__Node + + +class test_Schema__Mermaid__Edge__Config(TestCase): + + def setUp(self): # Initialize test data + self.edge_id = Random_Guid() + self.from_node_type = Schema__Mermaid__Node + self.to_node_type = Schema__Mermaid__Node + self.edge_config = Schema__Mermaid__Edge__Config( + edge_id = self.edge_id , + from_node_type = self.from_node_type, + to_node_type = self.to_node_type + ) + + def test_init(self): # Tests basic initialization and type checking + assert type(self.edge_config) is Schema__Mermaid__Edge__Config + assert self.edge_config.edge_id == self.edge_id + assert self.edge_config.from_node_type == self.from_node_type + assert self.edge_config.to_node_type == self.to_node_type + + def test_type_safety_validation(self): # Tests type safety validations + with self.assertRaises(ValueError) as context: + Schema__Mermaid__Edge__Config(edge_id = "not-a-guid" , + from_node_type = self.from_node_type, + to_node_type = self.to_node_type ) + assert str(context.exception) == "Invalid type for attribute 'edge_id'. Expected '' but got ''" + + with self.assertRaises(ValueError) as context: + Schema__Mermaid__Edge__Config( + edge_id = self.edge_id, + from_node_type = "not-a-type", + to_node_type = self.to_node_type + ) + assert "Invalid type for attribute" in str(context.exception) + + + diff --git a/tests/unit/providers/mermaid/schemas/test_Schema__Mermaid__Graph.py b/tests/unit/providers/mermaid/schemas/test_Schema__Mermaid__Graph.py new file mode 100644 index 0000000..b1171ae --- /dev/null +++ b/tests/unit/providers/mermaid/schemas/test_Schema__Mermaid__Graph.py @@ -0,0 +1,70 @@ +from unittest import TestCase +from osbot_utils.helpers.Random_Guid import Random_Guid +from osbot_utils.helpers.Safe_Id import Safe_Id +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 +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 +from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Node import Schema__Mermaid__Node +from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Node__Config import Schema__Mermaid__Node__Config + +class test_Schema__Mermaid__Graph(TestCase): + + def setUp(self): # Initialize test data + self.graph_config = Schema__Mermaid__Graph__Config(graph_id = Random_Guid() , + default_node_type = Schema__Mermaid__Node, + default_edge_type = Schema__Mermaid__Edge, + allow_circle_edges = True , + allow_duplicate_edges= False , + graph_title = "Test Graph" ) + self.node = Schema__Mermaid__Node (attributes = {} , + node_config = Schema__Mermaid__Node__Config(node_id = Random_Guid(), + value_type = str ), + node_type = Schema__Mermaid__Node , + value = "test_value" , + key = Safe_Id("node_1") , + label = "Test Node" ) + self.edge = Schema__Mermaid__Edge (attributes = {} , + edge_config = Schema__Mermaid__Edge__Config(edge_id = Random_Guid() , + from_node_type = Schema__Mermaid__Node , + to_node_type = Schema__Mermaid__Node), + edge_type = Schema__Mermaid__Edge , + from_node_id = Random_Guid() , + to_node_id = Random_Guid() , + label = "Test Edge" ) + self.graph = Schema__Mermaid__Graph (edges = {self.edge.edge_config.edge_id: self.edge}, + nodes = {self.node.node_config.node_id: self.node}, + graph_config = self.graph_config , + graph_type = Schema__Mermaid__Graph , + mermaid_code = ["graph TD", "A --> B"] ) + + def test_init(self): # Tests basic initialization and type checking + assert type(self.graph) is Schema__Mermaid__Graph + assert self.graph.graph_config == self.graph_config + assert len(self.graph.nodes) == 1 + assert len(self.graph.edges) == 1 + assert type(self.graph.mermaid_code) is list + assert len(self.graph.mermaid_code) == 2 + + def test_type_safety_validation(self): # Tests type safety validations + with self.assertRaises(ValueError) as context: + Schema__Mermaid__Graph( + edges = "not-a-dict" , + nodes = {} , + graph_config = self.graph_config, + graph_type = Schema__Mermaid__Graph, + mermaid_code = ["graph TD"] + ) + assert "Invalid type for attribute" in str(context.exception) + + with self.assertRaises(ValueError) as context: + Schema__Mermaid__Graph( + edges = {} , + nodes = {} , + graph_config = self.graph_config, + graph_type = Schema__Mermaid__Graph, + mermaid_code = "not-a-list" + ) + assert "Invalid type for attribute" in str(context.exception) + + diff --git a/tests/unit/providers/mermaid/schemas/test_Schema__Mermaid__Graph__Config.py b/tests/unit/providers/mermaid/schemas/test_Schema__Mermaid__Graph__Config.py new file mode 100644 index 0000000..ffe4bfb --- /dev/null +++ b/tests/unit/providers/mermaid/schemas/test_Schema__Mermaid__Graph__Config.py @@ -0,0 +1,47 @@ +from unittest import TestCase +from osbot_utils.helpers.Random_Guid import Random_Guid +from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Edge import Schema__Mermaid__Edge +from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Graph__Config import Schema__Mermaid__Graph__Config +from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Node import Schema__Mermaid__Node + + +class test_Schema__Mermaid__Graph__Config(TestCase): + + def setUp(self): # Initialize test data + self.graph_config = Schema__Mermaid__Graph__Config( + graph_id = Random_Guid() , + default_node_type = Schema__Mermaid__Node, + default_edge_type = Schema__Mermaid__Edge, + allow_circle_edges = True , + allow_duplicate_edges= False , + graph_title = "Test Graph" + ) + + def test_init(self): # Tests basic initialization and type checking + assert type(self.graph_config) is Schema__Mermaid__Graph__Config + assert self.graph_config.default_node_type == Schema__Mermaid__Node + assert self.graph_config.default_edge_type == Schema__Mermaid__Edge + assert self.graph_config.allow_circle_edges is True + assert self.graph_config.allow_duplicate_edges is False + assert self.graph_config.graph_title == "Test Graph" + + def test_type_safety_validation(self): # Tests type safety validations + with self.assertRaises(ValueError) as context: + Schema__Mermaid__Graph__Config(graph_id = "not-a-guid" , # invalid guid + default_node_type = Schema__Mermaid__Node, + default_edge_type = Schema__Mermaid__Edge, + allow_circle_edges = True , + allow_duplicate_edges= False , + graph_title = "Test Graph" ) + assert str(context.exception) == "Invalid type for attribute 'graph_id'. Expected '' but got ''" + + with self.assertRaises(ValueError) as context: + Schema__Mermaid__Graph__Config(graph_id = Random_Guid() , + default_node_type = Schema__Mermaid__Node, + default_edge_type = Schema__Mermaid__Edge, + allow_circle_edges = True , + allow_duplicate_edges= False , + graph_title = 123 ) # Invalid type for title + + assert "Invalid type for attribute" in str(context.exception) + diff --git a/tests/unit/providers/mermaid/schemas/test_Schema__Mermaid__Node.py b/tests/unit/providers/mermaid/schemas/test_Schema__Mermaid__Node.py index 41a14f5..945f964 100644 --- a/tests/unit/providers/mermaid/schemas/test_Schema__Mermaid__Node.py +++ b/tests/unit/providers/mermaid/schemas/test_Schema__Mermaid__Node.py @@ -1,16 +1,15 @@ from unittest import TestCase -from typing import Dict 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__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.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" , @@ -36,21 +35,22 @@ def test_type_safety_validation(self): with self.assertRaises(ValueError) as context: Schema__Mermaid__Node(attributes = self.attributes , node_config = self.node_config , - node_type = Schema__Mermaid__Node , + node_type = 123 , # invalid type for note type value = "test_value" , - key = 123 , # Invalid type for key + key = 'an-key' , label = "Test Node" ) - assert "Invalid type for attribute 'key'" in str(context.exception) + assert "Invalid type for attribute 'node_type'" in str(context.exception) with self.assertRaises(ValueError) as context: 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 = 123 ) # Invalid type for label + value = "test_value" , + key = Safe_Id("node_1") , + label = 123 ) # Invalid type for label assert "Invalid type for attribute 'label'" in str(context.exception) + def test_json_serialization(self): # Tests JSON serialization and deserialization json_data = self.node.json() diff --git a/tests/unit/providers/mermaid/schemas/test_Schema__Mermaid__Node__Config.py b/tests/unit/providers/mermaid/schemas/test_Schema__Mermaid__Node__Config.py new file mode 100644 index 0000000..ae814dd --- /dev/null +++ b/tests/unit/providers/mermaid/schemas/test_Schema__Mermaid__Node__Config.py @@ -0,0 +1,43 @@ +from unittest import TestCase +from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Node__Config import Schema__Mermaid__Node__Config +from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Node__Shape import Schema__Mermaid__Node__Shape + + + +class test_Schema__Mermaid__Node__Config(TestCase): + + def setUp(self): # Initialize test data + self.node_config = Schema__Mermaid__Node__Config( + markdown = True , + node_shape = Schema__Mermaid__Node__Shape.circle, + show_label = True , + wrap_with_quotes= True + ) + + def test_init(self): # Tests basic initialization and type checking + assert type(self.node_config) is Schema__Mermaid__Node__Config + assert self.node_config.markdown is True + assert self.node_config.node_shape == Schema__Mermaid__Node__Shape.circle + assert self.node_config.show_label is True + assert self.node_config.wrap_with_quotes is True + + def test_type_safety_validation(self): # Tests type safety validations + with self.assertRaises(ValueError) as context: + Schema__Mermaid__Node__Config( + markdown = "not-a-bool" , + node_shape = Schema__Mermaid__Node__Shape.circle, + show_label = True , + wrap_with_quotes= True + ) + assert "Invalid type for attribute" in str(context.exception) + + with self.assertRaises(ValueError) as context: + Schema__Mermaid__Node__Config( + markdown = True , + node_shape = "not-a-shape" , + show_label = True , + wrap_with_quotes= True + ) + assert "Invalid type for attribute" in str(context.exception) + + diff --git a/tests/unit/providers/mermaid/schemas/test_Schema__Mermaid__Node__Shape.py b/tests/unit/providers/mermaid/schemas/test_Schema__Mermaid__Node__Shape.py new file mode 100644 index 0000000..68ee0e7 --- /dev/null +++ b/tests/unit/providers/mermaid/schemas/test_Schema__Mermaid__Node__Shape.py @@ -0,0 +1,28 @@ +from unittest import TestCase +from mgraph_ai.providers.mermaid.schemas.Schema__Mermaid__Node__Shape import Schema__Mermaid__Node__Shape + + + +class test_Schema__Mermaid__Node__Shape(TestCase): + + def test_shape_values(self): # Tests shape values and format + assert Schema__Mermaid__Node__Shape.default.value == ('[' , ']' ) + assert Schema__Mermaid__Node__Shape.circle.value == ('((' , '))' ) + assert Schema__Mermaid__Node__Shape.rhombus.value == ('{' , '}' ) + assert Schema__Mermaid__Node__Shape.round_edges.value == ('(' , ')' ) + + def test_get_shape(self): # Tests shape retrieval method + # Test with enum value + shape = Schema__Mermaid__Node__Shape.circle + assert Schema__Mermaid__Node__Shape.get_shape(shape) == shape + + # Test with string value + assert Schema__Mermaid__Node__Shape.get_shape('circle') == Schema__Mermaid__Node__Shape.circle + + # Test with invalid value + assert Schema__Mermaid__Node__Shape.get_shape('invalid') == Schema__Mermaid__Node__Shape.default + assert Schema__Mermaid__Node__Shape.get_shape(None) == Schema__Mermaid__Node__Shape.default + + def test_shape_uniqueness(self): # Tests that all shapes have unique values + shape_values = [shape.value for shape in Schema__Mermaid__Node__Shape] + assert len(shape_values) == len(set(shape_values)) # All values should be unique \ No newline at end of file