Skip to content

Commit

Permalink
first experiments of doing shallow ctors on Schema__MGraph__Json__Nod…
Browse files Browse the repository at this point in the history
…e and Schema__MGraph__Json__Node__Value__Data
  • Loading branch information
DinisCruz committed Jan 21, 2025
1 parent 054e697 commit 89dadff
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 12 deletions.
2 changes: 1 addition & 1 deletion mgraph_ai/mgraph/schemas/Schema__MGraph__Node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']

15 changes: 14 additions & 1 deletion mgraph_ai/providers/json/schemas/Schema__MGraph__Json__Node.py
Original file line number Diff line number Diff line change
@@ -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)



Original file line number Diff line number Diff line change
Expand Up @@ -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
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)
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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



Expand Down

0 comments on commit 89dadff

Please sign in to comment.