Skip to content

Commit

Permalink
two failing tests still trying to debug
Browse files Browse the repository at this point in the history
  • Loading branch information
duboyal committed May 3, 2024
1 parent 817a9a5 commit 606c8c7
Show file tree
Hide file tree
Showing 14 changed files with 328 additions and 257 deletions.
445 changes: 219 additions & 226 deletions src/cript/api/api.py

Large diffs are not rendered by default.

47 changes: 44 additions & 3 deletions src/cript/nodes/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ def shallow_equal(self, other):

self_sorted_json = self.get_json(known_uuid=self_child_map.keys(), sort_keys=True, condense_to_uuid={}).json
other_sorted_json = other.get_json(known_uuid=other_child_map.keys(), sort_keys=True, condense_to_uuid={}).json
# maybe bring back
# self_sorted_json_dict = json.loads(self_sorted_json)
# other_sorted_json_dict = json.loads(other_sorted_json)

# del self_sorted_json_dict["uid"]
# del other_sorted_json_dict["uid"]

# self_sorted_json = json.dumps(self_sorted_json_dict)
# other_sorted_json = json.dumps(other_sorted_json_dict)

return self_sorted_json == other_sorted_json

Expand Down Expand Up @@ -429,6 +438,15 @@ def get_expanded_json(self, **kwargs) -> str:
"""
return self.get_json(handled_ids=None, known_uuid=None, suppress_attributes=None, is_patch=False, condense_to_uuid={}, **kwargs).json

# @staticmethod
# def clean_dict(data):
# if isinstance(data, dict):
# return {key: BaseNode.clean_dict(value) for key, value in data.items() if value != "" and value != [""]}
# elif isinstance(data, list):
# return [BaseNode.clean_dict(item) for item in data if item != "" and item != [""]]
# else:
# return data

def get_json(
self,
handled_ids: Optional[Set[str]] = None,
Expand All @@ -439,7 +457,7 @@ def get_json(
"Material": {"parent_material", "component"},
"Experiment": {"data"},
"Inventory": {"material"},
"Ingredient": {"material"},
# "Ingredient": {"material"},
"Property": {"component"},
"ComputationProcess": {"material"},
"Data": {"material"},
Expand Down Expand Up @@ -493,9 +511,32 @@ class ReturnTuple:
try:
tmp_json = json.dumps(self, cls=NodeEncoder, **kwargs)
tmp_dict = json.loads(tmp_json)
#####

# try:
# print(tmp_dict) # ["inventory"])#[0]["experiment"][0]["data"])
# print(f"is_patch: {is_patch}")
# print(f"_no_condense_uuid: {_no_condense_uuid}")
# print(" 🐨🐱🦊 ")
# except:
# print(" - ")

# if tmp_dict["collection"]["experiment"]["data"]:
# print("-----tmp_dict_is_there_a_full data or not")
# print(tmp_dict["collection"]["experiment"]["data"])

if is_patch:
del tmp_dict["uuid"] # patches do not allow UUID is the parent most node
del tmp_dict["uid"]
# del tmp_dict["uuid"] # patches do not allow UUID is the parent most node

# try: # this should only affect parent
# del tmp_dict["uuid"]
# except KeyError:
# pass

# try:
# del tmp_dict["uid"]
# except KeyError:
# pass

try:
del tmp_dict["created_at"]
Expand Down
4 changes: 2 additions & 2 deletions src/cript/nodes/primary_nodes/computation.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def input_data(self) -> List[Any]:
... source="https://criptapp.org",
... type="calibration",
... extension=".csv",
... data_dictionary="my file's data dictionary"
... data_dictionary="my files data dictionary"
... )
>>> my_input_data = cript.Data(name="my data name", type="afm_amp", file=[my_file])
>>> my_computation.input_data = [my_input_data]
Expand Down Expand Up @@ -257,7 +257,7 @@ def output_data(self) -> List[Any]:
... source="https://criptapp.org",
... type="calibration",
... extension=".csv",
... data_dictionary="my file's data dictionary"
... data_dictionary="my files data dictionary"
... )
>>> my_output_data = cript.Data(name="my data name", type="afm_amp", file=[my_file])
>>> my_computation.output_data = [my_output_data]
Expand Down
8 changes: 4 additions & 4 deletions src/cript/nodes/primary_nodes/computation_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class ComputationProcess(PrimaryBaseNode):
"node":["File"],
"source":"https://criptapp.org",
"type":"calibration",
"data_dictionary":"my file's data dictionary",
"data_dictionary":"my files data dictionary",
"extension":".csv",
"uid":"_:ee8153db-4108-49e4-8c5b-ffc26d4e6f71",
"uuid":"ee8153db-4108-49e4-8c5b-ffc26d4e6f71"
Expand Down Expand Up @@ -150,7 +150,7 @@ def __init__(
... source="https://criptapp.org",
... type="calibration",
... extension=".csv",
... data_dictionary="my file's data dictionary"
... data_dictionary="my files data dictionary"
... )
>>> input_data = cript.Data(name="my data name", type="afm_amp", file=[data_files])
>>> my_material = cript.Material(
Expand Down Expand Up @@ -287,7 +287,7 @@ def input_data(self) -> List[Any]:
... name="my file node name",
... source="https://criptapp.org",
... type="calibration",
... data_dictionary="my file's data dictionary",
... data_dictionary="my files data dictionary",
... extension=".csv",
... )
>>> my_input_data = cript.Data(name="my input data name", type="afm_amp", file=[my_file])
Expand Down Expand Up @@ -331,7 +331,7 @@ def output_data(self) -> List[Any]:
... source="https://criptapp.org",
... type="calibration",
... extension=".csv",
... data_dictionary="my file's data dictionary"
... data_dictionary="my files data dictionary"
... )
>>> my_output_data = cript.Data(name="my output data name", type="afm_amp", file=[my_file])
>>> my_computation_process.output_data = [my_output_data] # doctest: +SKIP
Expand Down
22 changes: 11 additions & 11 deletions src/cript/nodes/primary_nodes/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Data(PrimaryBaseNode):
... source="https://criptapp.org",
... type="calibration",
... extension=".csv",
... data_dictionary="my file's data dictionary"
... data_dictionary="my files data dictionary"
... )
>>> my_data = cript.Data(name="my data name", type="afm_amp", file=[my_file])
Expand All @@ -60,7 +60,7 @@ class Data(PrimaryBaseNode):
"type":"calibration",
"source":"https://criptapp.org",
"extension":".csv",
"data_dictionary":"my file's data dictionary",
"data_dictionary":"my files data dictionary",
}
]
}
Expand Down Expand Up @@ -195,7 +195,7 @@ def type(self) -> str:
... source="https://criptapp.org",
... type="calibration",
... extension=".csv",
... data_dictionary="my file's data dictionary"
... data_dictionary="my files data dictionary"
... )
>>> my_data = cript.Data(name="my data name", type="afm_amp", file=[my_file])
>>> my_data.type = "nmr_h1"
Expand Down Expand Up @@ -240,15 +240,15 @@ def file(self) -> List[Any]:
... source="https://criptapp.org",
... type="calibration",
... extension=".csv",
... data_dictionary="my file's data dictionary"
... data_dictionary="my files data dictionary"
... )
>>> my_data = cript.Data(name="my data name", type="afm_amp", file=[my_file])
>>> my_new_file = cript.File(
... name="my new file node name",
... source="path/to/local/file",
... type="calibration",
... extension=".csv",
... data_dictionary="my file's data dictionary"
... data_dictionary="my files data dictionary"
... )
>>> my_data.file += [my_new_file]
Expand Down Expand Up @@ -336,7 +336,7 @@ def computation(self) -> List[Any]:
... source="https://criptapp.org",
... type="calibration",
... extension=".csv",
... data_dictionary="my file's data dictionary"
... data_dictionary="my files data dictionary"
... )
>>> my_data = cript.Data(name="my data name", type="afm_amp", file=[my_file])
>>> my_computation = cript.Computation(name="my computation name", type="analysis")
Expand Down Expand Up @@ -381,7 +381,7 @@ def computation_process(self) -> Union[Any, None]:
... source="https://criptapp.org",
... type="calibration",
... extension=".csv",
... data_dictionary="my file's data dictionary"
... data_dictionary="my files data dictionary"
... )
>>> my_data = cript.Data(
... name="my data name",
Expand All @@ -393,7 +393,7 @@ def computation_process(self) -> Union[Any, None]:
... source="https://criptapp.org",
... type="calibration",
... extension=".csv",
... data_dictionary="my file's data dictionary"
... data_dictionary="my files data dictionary"
... )
>>> my_second_data_node = cript.Data(
... name="my data name",
Expand Down Expand Up @@ -457,7 +457,7 @@ def material(self) -> List[Any]:
... source="https://criptapp.org",
... type="calibration",
... extension=".csv",
... data_dictionary="my file's data dictionary"
... data_dictionary="my files data dictionary"
... )
>>> my_data = cript.Data(name="my data name", type="afm_amp", file=[my_file])
>>> my_material = cript.Material(name="my material name", bigsmiles = "123456")
Expand Down Expand Up @@ -501,7 +501,7 @@ def process(self) -> List[Any]:
... source="https://criptapp.org",
... type="calibration",
... extension=".csv",
... data_dictionary="my file's data dictionary"
... data_dictionary="my files data dictionary"
... )
>>> my_data = cript.Data(name="my data name", type="afm_amp", file=[my_file])
>>> my_process = cript.Process(name="my process name", type="affinity_pure")
Expand Down Expand Up @@ -553,7 +553,7 @@ def citation(self) -> List[Any]:
... source="https://criptapp.org",
... type="calibration",
... extension=".csv",
... data_dictionary="my file's data dictionary"
... data_dictionary="my files data dictionary"
... )
>>> my_data = cript.Data(name="my data name", type="afm_amp", file=[my_file])
>>> my_reference = cript.Reference(type="journal_article", title="'Living' Polymers")
Expand Down
4 changes: 2 additions & 2 deletions src/cript/nodes/primary_nodes/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def computation_process(self) -> List[Any]:
... source="https://criptapp.org",
... type="calibration",
... extension=".csv",
... data_dictionary="my file's data dictionary",
... data_dictionary="my files data dictionary",
... )
>>> my_data = cript.Data(name="my data name", type="afm_amp", file=[my_file])
>>> my_material = cript.Material(
Expand Down Expand Up @@ -301,7 +301,7 @@ def data(self) -> List[Any]:
... source="https://criptapp.org",
... type="calibration",
... extension=".csv",
... data_dictionary="my file's data dictionary",
... data_dictionary="my files data dictionary",
... )
>>> my_data = cript.Data(name="my data name", type="afm_amp", file=[my_file])
>>> my_experiment.data = [my_data]
Expand Down
11 changes: 11 additions & 0 deletions src/cript/nodes/primary_nodes/primary_base_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ def __str__(self) -> str:
"""
return super().__str__()

@classmethod
def _from_json(cls, json_dict: dict):
# GOOD CHANGE - ALI
# TODO: remove this temporary fix, once back end is working correctly
try:
if json_dict["model_version"] == "1.0.0":
json_dict["model_version"] = "1.0.1"
except KeyError:
pass
return super(PrimaryBaseNode, cls)._from_json(json_dict)

@property
@beartype
def locked(self):
Expand Down
2 changes: 1 addition & 1 deletion src/cript/nodes/subobjects/computational_forcefield.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ComputationalForcefield(UUIDBaseNode):
"type":"calibration",
"source":"https://criptapp.org",
"extension":".csv",
"data_dictionary":"my file's data dictionary"
"data_dictionary":"my files data dictionary"
}
]
},
Expand Down
2 changes: 1 addition & 1 deletion src/cript/nodes/subobjects/condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Condition(UUIDBaseNode):
"type":"calibration",
"source":"https://criptapp.org",
"extension":".csv",
"data_dictionary":"my file's data dictionary"
"data_dictionary":"my files data dictionary"
}
]
}],
Expand Down
2 changes: 1 addition & 1 deletion src/cript/nodes/subobjects/property.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ def data(self) -> List[Union[Data, UIDProxy]]:
... source="https://criptapp.org",
... type="calibration",
... extension=".csv",
... data_dictionary="my file's data dictionary",
... data_dictionary="my files data dictionary",
... )
>>> my_data = cript.Data(name="my data name", type="afm_amp", file=[my_file])
>>> my_property.data = [my_data]
Expand Down
6 changes: 3 additions & 3 deletions src/cript/nodes/supporting_nodes/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class File(PrimaryBaseNode):
"source": "https://criptapp.org",
"type": "calibration",
"extension": ".csv",
"data_dictionary": "my file's data dictionary",
"data_dictionary": "my files data dictionary",
}
```
"""
Expand Down Expand Up @@ -159,7 +159,7 @@ def __init__(self, name: str, source: str, type: str, extension: str, data_dicti
... source="https://pubs.acs.org/doi/suppl/10.1021/acscentsci.3c00011/suppl_file/oc3c00011_si_001.pdf",
... type="calibration",
... extension=".pdf",
... data_dictionary="my file's data dictionary",
... data_dictionary="my files data dictionary",
... notes="my notes for this file",
... )
Expand All @@ -170,7 +170,7 @@ def __init__(self, name: str, source: str, type: str, extension: str, data_dicti
... source="/home/user/MIT/project/my_file.csv",
... type="calibration",
... extension=".csv",
... data_dictionary="my file's data dictionary",
... data_dictionary="my files data dictionary",
... notes="my notes for this file",
... )
"""
Expand Down
11 changes: 11 additions & 0 deletions src/cript/nodes/supporting_nodes/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ def __init__(self, username: str, email: Optional[str] = "", orcid: Optional[str
new_json_attrs = replace(self._json_attrs, username=username, email=email, orcid=orcid)
self._update_json_attrs_if_valid(new_json_attrs)

@classmethod
def _from_json(cls, json_dict: dict):
# GOOD CHANGE - ALI
# TODO: remove this temporary fix, once back end is working correctly
try:
if json_dict["model_version"] == "1.0.0":
json_dict["model_version"] = "1.0.1"
except KeyError:
pass
return super(User, cls)._from_json(json_dict)

@property
@beartype
def created_at(self) -> str:
Expand Down
12 changes: 9 additions & 3 deletions src/cript/nodes/util/json.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
This module contains classes and functions that help with the json serialization and deserialization of nodes.
"""

import dataclasses
import inspect
import json
Expand Down Expand Up @@ -183,10 +184,15 @@ def strip_to_edge_uuid(element):
except AttributeError:
uid = element["uid"]

if self.no_condense_uuid:
element = ""
else:
# old___
# if self.no_condense_uuid:
# element = ""
# else:
# element = {"uuid": str(uuid)}
# GOOD CHANGE - ALI
if self.no_condense_uuid is False:
element = {"uuid": str(uuid)}

return element, uid

# Processes an attribute based on its type (list or single element)
Expand Down
9 changes: 9 additions & 0 deletions tests/nodes/primary_nodes/test_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,12 @@ def test_integration_reference(cript_api, simple_project_node, complex_citation_
simple_project_node.name = f"test_integration_reference_name_{uuid.uuid4().hex}"

simple_project_node.collection[0].citation = [complex_citation_node]
print("PRINTING_citation_INFO 1")
print(simple_project_node.collection[0].citation)

"""
right now this test is failing when you try to add citation
"""
save_integration_node_helper(cript_api=cript_api, project_node=simple_project_node)

# TODO deserialization with citation in collection is wrong
Expand All @@ -222,6 +227,10 @@ def test_integration_reference(cript_api, simple_project_node, complex_citation_
# change simple attribute to trigger update
# TODO can enable this later
# complex_reference_node.type = "book"

print("PRINTING_citation_INFO 2")
print(simple_project_node.collection[0].citation)

simple_project_node.collection[0].citation[0].reference.title = "reference title UPDATED"

save_integration_node_helper(cript_api=cript_api, project_node=simple_project_node)
Expand Down

0 comments on commit 606c8c7

Please sign in to comment.