diff --git a/mgraph_ai/mgraph/schemas/Schema__MGraph__Node.py b/mgraph_ai/mgraph/schemas/Schema__MGraph__Node.py index b357818..14fae5f 100644 --- a/mgraph_ai/mgraph/schemas/Schema__MGraph__Node.py +++ b/mgraph_ai/mgraph/schemas/Schema__MGraph__Node.py @@ -7,4 +7,4 @@ class Schema__MGraph__Node(Type_Safe): node_data : Schema__MGraph__Node__Data node_id : Obj_Id node_type : Type['Schema__MGraph__Node'] - + diff --git a/mgraph_ai/providers/json/schemas/Schema__MGraph__Json__Node.py b/mgraph_ai/providers/json/schemas/Schema__MGraph__Json__Node.py index a5a55d5..962a4e5 100644 --- a/mgraph_ai/providers/json/schemas/Schema__MGraph__Json__Node.py +++ b/mgraph_ai/providers/json/schemas/Schema__MGraph__Json__Node.py @@ -1,4 +1,17 @@ +from osbot_utils.helpers.Obj_Id import Obj_Id from mgraph_ai.mgraph.schemas.Schema__MGraph__Node import Schema__MGraph__Node class Schema__MGraph__Json__Node(Schema__MGraph__Node): - pass + + def __init__(self, **kwargs): + #return super().__init__(**kwargs) + node_data = kwargs.get('node_data') or self.__annotations__['node_data']() + node_id = kwargs.get('node_id' ) or Obj_Id() + node_type = kwargs.get('node_type') or self.__class__ + node_dict = dict(node_data = node_data, + node_id = node_id , + node_type = node_type) + object.__setattr__(self, '__dict__', node_dict) + + + diff --git a/mgraph_ai/providers/json/schemas/Schema__MGraph__Json__Node__Value__Data.py b/mgraph_ai/providers/json/schemas/Schema__MGraph__Json__Node__Value__Data.py index f1090bf..51347d3 100644 --- a/mgraph_ai/providers/json/schemas/Schema__MGraph__Json__Node__Value__Data.py +++ b/mgraph_ai/providers/json/schemas/Schema__MGraph__Json__Node__Value__Data.py @@ -3,4 +3,9 @@ class Schema__MGraph__Json__Node__Value__Data(Schema__MGraph__Node__Data): # Base schema for JSON node data value : Any # The actual value - value_type : type # Type of the value \ No newline at end of file + value_type : type # Type of the value + + def __init__(self, **kwargs): + data_dict = dict(value = kwargs.get('value' ), # note: no type checking here + value_type = kwargs.get('value_type')) # note: no type checking here + object.__setattr__(self, '__dict__', data_dict) \ No newline at end of file diff --git a/tests/unit/providers/json/_performance/test_Perf_Test__MGraph_Json.py b/tests/unit/providers/json/_performance/test_Perf_Test__MGraph_Json.py index 4263218..cb24e2e 100644 --- a/tests/unit/providers/json/_performance/test_Perf_Test__MGraph_Json.py +++ b/tests/unit/providers/json/_performance/test_Perf_Test__MGraph_Json.py @@ -1,5 +1,10 @@ import pytest from unittest import TestCase + +from osbot_utils.context_managers.print_duration import print_duration + +from osbot_utils.utils.Dev import pprint + from osbot_utils.utils.Http import current_host_offline from mgraph_ai.providers.json.MGraph__Json import MGraph__Json from osbot_utils.helpers.trace.Trace_Call import trace_calls @@ -32,18 +37,29 @@ def test_run_workflow__on_url(self): _.print() assert _.perf_test_duration.duration__total < 6 # shower in GitHub Actions (locally it's around 1.5) - # contains=['models__from_edges', 'edges', 'add_node', 'new_dict_node', 'add_property'], - @trace_calls(#include = ['*'], - contains=['add_property', 'add_node', 'new_edge'], - show_duration=True, duration_padding=120, - show_class =True, - #duration_bigger_than=0.1 - ) + # @trace_calls(#include = ['*'], + # contains=['add_property', 'add_node', 'new_edge', 'schema'], + # show_duration=True, duration_padding=120, + # show_class =True, + # #duration_bigger_than=0.1 + # ) def test_trace(self): - feed_start = { 'channel': { 'description': 'Latest Technology News'}} + feed_start = { 'channel': { 'description': 'Latest Technology News', + 'abc': 'xyz'}, + 'answer': 42, + 'an_list': [1,2,3]} target_json = TEST_DATA__TECH_NEWS__FEED_XML_JSON target_json = feed_start - MGraph__Json().load().from_json(target_json) + mgraph_json = MGraph__Json() + with print_duration(action_name='from-json'): + mgraph_json.load().from_json(target_json) + with print_duration(action_name='to-json'): + round_trip = mgraph_json.export().to_dict() + with print_duration(action_name='to-dot'): + dot_code = mgraph_json.export().to_dot().to_string() + #pprint(round_trip) + #print(dot_code) + assert target_json == round_trip