Skip to content

Commit

Permalink
Upgrade node unit tests (#363)
Browse files Browse the repository at this point in the history
* added notes to test_collection.py tests

* getter and setter tests
* complex node creation test

* added notes to test_computation.py tests

* added notes to test_computational_process.py tests

* added notes to test_data.py tests

* removed deepcopy for complex_file_node

* added notes to test_inventory.py tests

* added notes to test_process.py tests

* added notes to test_material.py tests

* added notes to test_project.py tests

* added notes to test_file.py tests

* formatted with black

* removed unused import

* fixed test errors
  • Loading branch information
nh916 authored Sep 27, 2023
1 parent 62e440c commit f8e7c53
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 25 deletions.
15 changes: 8 additions & 7 deletions tests/nodes/primary_nodes/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,9 @@ def test_create_complex_collection(simple_experiment_node, simple_inventory_node
"""
my_collection_name = "my complex collection name"
my_cript_doi = "10.1038/1781168a0"
my_collection_notes = "test_create_complex_collection notes"

my_collection = cript.Collection(
name=my_collection_name,
experiment=[simple_experiment_node],
inventory=[simple_inventory_node],
doi=my_cript_doi,
citation=[complex_citation_node],
)
my_collection = cript.Collection(name=my_collection_name, experiment=[simple_experiment_node], inventory=[simple_inventory_node], doi=my_cript_doi, citation=[complex_citation_node], notes=my_collection_notes)

# assertions
assert isinstance(my_collection, cript.Collection)
Expand All @@ -53,6 +48,7 @@ def test_create_complex_collection(simple_experiment_node, simple_inventory_node
assert my_collection.inventory == [simple_inventory_node]
assert my_collection.doi == my_cript_doi
assert my_collection.citation == [complex_citation_node]
assert my_collection.notes == my_collection_notes


def test_collection_getters_and_setters(simple_experiment_node, simple_inventory_node, complex_citation_node) -> None:
Expand All @@ -69,13 +65,15 @@ def test_collection_getters_and_setters(simple_experiment_node, simple_inventory

new_collection_name = "my new collection name"
new_cript_doi = "my new cript doi"
new_collection_notes = "my collection getters and setters notes"

# set Collection attributes
my_collection.name = new_collection_name
my_collection.experiment = [simple_experiment_node]
my_collection.inventory = [simple_inventory_node]
my_collection.doi = new_cript_doi
my_collection.citation = [complex_citation_node]
my_collection.notes = new_collection_notes

# assert getters and setters are the same
assert isinstance(my_collection, cript.Collection)
Expand All @@ -84,19 +82,22 @@ def test_collection_getters_and_setters(simple_experiment_node, simple_inventory
assert my_collection.inventory == [simple_inventory_node]
assert my_collection.doi == new_cript_doi
assert my_collection.citation == [complex_citation_node]
assert my_collection.notes == new_collection_notes

# remove Collection attributes
my_collection.experiment = []
my_collection.inventory = []
my_collection.doi = ""
my_collection.citation = []
my_collection.notes = ""

# assert users can remove optional attributes
assert my_collection.name == new_collection_name
assert my_collection.experiment == []
assert my_collection.inventory == []
assert my_collection.doi == ""
assert my_collection.citation == []
assert my_collection.notes == ""


def test_serialize_collection_to_json(complex_user_node) -> None:
Expand Down
3 changes: 3 additions & 0 deletions tests/nodes/primary_nodes/test_computation.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def test_create_complex_computation_node(simple_data_node, complex_software_conf
test that a complex computation node with all possible arguments can be created
"""
my_computation_type = "analysis"
my_computation_notes = "this is my computation notes"

citation = copy.deepcopy(complex_citation_node)
condition = copy.deepcopy(complex_condition_node)
Expand All @@ -42,6 +43,7 @@ def test_create_complex_computation_node(simple_data_node, complex_software_conf
condition=[condition],
prerequisite_computation=simple_computation_node,
citation=[citation],
notes=my_computation_notes,
)

# assertions
Expand All @@ -53,6 +55,7 @@ def test_create_complex_computation_node(simple_data_node, complex_software_conf
assert my_computation_node.condition == [condition]
assert my_computation_node.prerequisite_computation == simple_computation_node
assert my_computation_node.citation == [citation]
assert my_computation_node.notes == my_computation_notes


def test_computation_type_invalid_vocabulary() -> None:
Expand Down
3 changes: 3 additions & 0 deletions tests/nodes/primary_nodes/test_computational_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def test_create_complex_computational_process(
"""

computational_process_name = "my computational process name"
computational_process_notes = "my computational process notes"
computational_process_type = "cross_linking"

ingredient = complex_ingredient_node
Expand All @@ -55,6 +56,7 @@ def test_create_complex_computational_process(
condition=[complex_condition_node],
property=[simple_property_node],
citation=[complex_citation_node],
notes=computational_process_notes,
)

# assertions
Expand All @@ -68,6 +70,7 @@ def test_create_complex_computational_process(
assert my_computational_process.condition == [complex_condition_node]
assert my_computational_process.property == [simple_property_node]
assert my_computational_process.citation == [complex_citation_node]
assert my_computational_process.notes == computational_process_notes


def test_computational_process_getters_and_setters(simple_computation_process_node, simple_data_node, simple_ingredient_node, simple_software_configuration, simple_condition_node, simple_property_node, complex_citation_node) -> None:
Expand Down
15 changes: 11 additions & 4 deletions tests/nodes/primary_nodes/test_data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import copy
import json
import uuid

Expand Down Expand Up @@ -36,29 +35,32 @@ def test_create_complex_data_node(
create a complex data node with all possible arguments
"""

file_node = copy.deepcopy(complex_file_node)
my_notes = "my complex data node notes"

my_complex_data = cript.Data(
name="my complex data node name",
type="afm_amp",
file=[file_node],
file=[complex_file_node],
sample_preparation=simple_process_node,
computation=[simple_computation_node],
computation_process=[simple_computational_process_node],
material=[simple_material_node],
process=[simple_process_node],
# citation=[complex_citation_node],
notes=my_notes,
)

# assertions
assert isinstance(my_complex_data, cript.Data)
assert my_complex_data.type == "afm_amp"
assert my_complex_data.file == [file_node]
assert my_complex_data.file == [complex_file_node]
assert my_complex_data.sample_preparation == simple_process_node
assert my_complex_data.computation == [simple_computation_node]
assert my_complex_data.computation_process == [simple_computational_process_node]
assert my_complex_data.material == [simple_material_node]
assert my_complex_data.process == [simple_process_node]
# assert my_complex_data.citation == [complex_citation_node]
assert my_complex_data.notes == my_notes


def test_data_getters_and_setters(
Expand All @@ -83,6 +85,7 @@ def test_data_getters_and_setters(
None
"""
my_data_type = "afm_height"
my_data_notes = "my data getter setter notes"

my_new_files = [
complex_file_node,
Expand All @@ -105,6 +108,7 @@ def test_data_getters_and_setters(
simple_data_node.material = [simple_material_node]
simple_data_node.process = [simple_process_node]
simple_data_node.citation = [complex_citation_node]
simple_data_node.notes = my_data_notes

# assertions check getters and setters
assert simple_data_node.type == my_data_type
Expand All @@ -115,6 +119,7 @@ def test_data_getters_and_setters(
assert simple_data_node.material == [simple_material_node]
assert simple_data_node.process == [simple_process_node]
assert simple_data_node.citation == [complex_citation_node]
assert simple_data_node.notes == my_data_notes

# remove optional attributes
simple_data_node.sample_preparation = []
Expand All @@ -123,6 +128,7 @@ def test_data_getters_and_setters(
simple_data_node.material = []
simple_data_node.process = []
simple_data_node.citation = []
simple_data_node.notes = ""

# assert that optional attributes have been removed from data node
assert simple_data_node.sample_preparation == []
Expand All @@ -131,6 +137,7 @@ def test_data_getters_and_setters(
assert simple_data_node.material == []
assert simple_data_node.process == []
assert simple_data_node.citation == []
assert simple_data_node.notes == ""


def test_serialize_data_to_json(simple_data_node) -> None:
Expand Down
7 changes: 6 additions & 1 deletion tests/nodes/primary_nodes/test_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,24 @@ def test_get_and_set_inventory(simple_inventory_node) -> None:
"""
# create new materials
material_1 = cript.Material(name="new material 1", identifier=[{"names": ["new material 1 alternative name"]}])
my_notes = "my inventory notes"

# set inventory materials
# set inventory
simple_inventory_node.material = [material_1]
simple_inventory_node.notes = my_notes

# get and check inventory materials
assert isinstance(simple_inventory_node, cript.Inventory)
assert simple_inventory_node.material[-1] == material_1
assert simple_inventory_node.notes == my_notes

# remove optional attributes
simple_inventory_node.material = []
simple_inventory_node.notes = ""

# assert that optional attributes have been removed
assert simple_inventory_node.material == []
assert simple_inventory_node.notes == ""


def test_inventory_serialization(simple_inventory_node, simple_material_dict) -> None:
Expand Down
9 changes: 8 additions & 1 deletion tests/nodes/primary_nodes/test_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ def test_create_complex_material(simple_material_node, simple_computational_forc
material_name = "my material name"
identifier = [{"bigsmiles": "1234"}, {"bigsmiles": "4567"}]
keyword = ["acetylene"]
material_notes = "my material notes"

component = [simple_material_node]
forcefield = [simple_computational_forcefield_node]

my_property = [cript.Property(key="modulus_shear", type="min", value=1.23, unit="gram")]

my_material = cript.Material(name=material_name, identifier=identifier, keyword=keyword, component=component, process=simple_process_node, property=my_property, computational_forcefield=forcefield)
my_material = cript.Material(name=material_name, identifier=identifier, keyword=keyword, component=component, process=simple_process_node, property=my_property, computational_forcefield=forcefield, notes=material_notes)

assert isinstance(my_material, cript.Material)
assert my_material.name == material_name
Expand All @@ -33,6 +34,7 @@ def test_create_complex_material(simple_material_node, simple_computational_forc
assert my_material.process == simple_process_node
assert my_material.property == my_property
assert my_material.computational_forcefield == forcefield
assert my_material.notes == material_notes


def test_invalid_material_keywords() -> None:
Expand All @@ -53,6 +55,7 @@ def test_all_getters_and_setters(simple_material_node, simple_property_node, sim
"""
# new attributes
new_name = "new material name"
new_notes = "new material notes"

new_identifier = [{"bigsmiles": "6789"}]

Expand Down Expand Up @@ -82,6 +85,7 @@ def test_all_getters_and_setters(simple_material_node, simple_property_node, sim
simple_material_node.computational_forcefield = simple_computational_forcefield_node
simple_material_node.keyword = new_material_keywords
simple_material_node.component = new_components
simple_material_node.notes = new_notes

# get all attributes and assert that they are equal to the setter
assert simple_material_node.name == new_name
Expand All @@ -91,18 +95,21 @@ def test_all_getters_and_setters(simple_material_node, simple_property_node, sim
assert simple_material_node.computational_forcefield == simple_computational_forcefield_node
assert simple_material_node.keyword == new_material_keywords
assert simple_material_node.component == new_components
assert simple_material_node.notes == new_notes

# remove optional attributes
simple_material_node.property = []
simple_material_node.parent_material = None
simple_material_node.computational_forcefield = None
simple_material_node.component = []
simple_material_node.notes = ""

# assert optional attributes have been removed
assert simple_material_node.property == []
assert simple_material_node.parent_material is None
assert simple_material_node.computational_forcefield is None
assert simple_material_node.component == []
assert simple_material_node.notes == ""


def test_serialize_material_to_json(complex_material_dict, complex_material_node) -> None:
Expand Down
29 changes: 17 additions & 12 deletions tests/nodes/primary_nodes/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ def test_complex_process_node(complex_ingredient_node, simple_equipment_node, co
"annealing_sol",
]

my_notes = "my complex process notes"

# create complex process
citation = copy.deepcopy(complex_citation_node)
prop = cript.Property("n_neighbor", "value", 2.0, None)
Expand All @@ -70,6 +72,7 @@ def test_complex_process_node(complex_ingredient_node, simple_equipment_node, co
property=[prop],
keyword=my_process_keywords,
citation=[citation],
notes=my_notes,
)
# assertions
assert my_complex_process.type == my_process_type
Expand All @@ -83,6 +86,7 @@ def test_complex_process_node(complex_ingredient_node, simple_equipment_node, co
assert my_complex_process.property[-1] == prop
assert my_complex_process.keyword[-1] == my_process_keywords[-1]
assert my_complex_process.citation[-1] == citation
assert my_complex_process.notes == my_notes


def test_process_getters_and_setters(
Expand All @@ -107,36 +111,35 @@ def test_process_getters_and_setters(
new_process_type = "blow_molding"
new_process_description = "my new process description"
new_process_keywords = "annealing_sol"
new_process_notes = "new process notes"

# test setters
simple_process_node.type = new_process_type
simple_process_node.ingredient = [complex_ingredient_node]
simple_process_node.description = new_process_description
equipment = complex_equipment_node
simple_process_node.equipment = [equipment]
product = simple_material_node
simple_process_node.product = [product]
simple_process_node.equipment = [complex_equipment_node]
simple_process_node.product = [simple_material_node]
simple_process_node.waste = [simple_material_node]
simple_process_node.prerequisite_process = [simple_process_node]
simple_process_node.condition = [complex_condition_node]
prop = cript.Property("n_neighbor", "value", 2.0, None)
simple_process_node.property += [prop]
simple_process_node.property += [simple_property_node]
simple_process_node.keyword = [new_process_keywords]
citation = copy.deepcopy(complex_citation_node)
simple_process_node.citation = [citation]
simple_process_node.citation = [complex_citation_node]
simple_process_node.notes = new_process_notes

# test getters
assert simple_process_node.type == new_process_type
assert simple_process_node.ingredient == [complex_ingredient_node]
assert simple_process_node.description == new_process_description
assert simple_process_node.equipment[-1] == equipment
assert simple_process_node.product[-1] == product
assert simple_process_node.equipment[-1] == complex_equipment_node
assert simple_process_node.product[-1] == simple_material_node
assert simple_process_node.waste == [simple_material_node]
assert simple_process_node.prerequisite_process == [simple_process_node]
assert simple_process_node.condition == [complex_condition_node]
assert simple_process_node.property[-1] == prop
assert simple_process_node.property[-1] == simple_property_node
assert simple_process_node.keyword == [new_process_keywords]
assert simple_process_node.citation[-1] == citation
assert simple_process_node.citation[-1] == complex_citation_node
assert simple_process_node.notes == new_process_notes

# test that optional attributes can be successfully removed
simple_process_node.ingredient = []
Expand All @@ -149,6 +152,7 @@ def test_process_getters_and_setters(
simple_process_node.property = []
simple_process_node.keyword = []
simple_process_node.citation = []
simple_process_node.notes = ""

# assert that optional attributes have been removed
assert simple_process_node.ingredient == []
Expand All @@ -161,6 +165,7 @@ def test_process_getters_and_setters(
assert simple_process_node.property == []
assert simple_process_node.keyword == []
assert simple_process_node.citation == []
assert simple_process_node.notes == ""


def test_serialize_process_to_json(simple_process_node) -> None:
Expand Down
5 changes: 5 additions & 0 deletions tests/nodes/primary_nodes/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,29 @@ def test_project_getters_and_setters(simple_project_node, simple_collection_node
4. what was set and what was gotten should be equivalent
"""
new_project_name = "my new project name"
new_project_notes = "my new project notes"

# set attributes
simple_project_node.name = new_project_name
simple_project_node.collection = [complex_collection_node]
simple_project_node.material = [simple_material_node]
simple_project_node.notes = new_project_notes

# get attributes and assert that they are the same
assert simple_project_node.name == new_project_name
assert simple_project_node.collection == [complex_collection_node]
assert simple_project_node.material == [simple_material_node]
assert simple_project_node.notes == new_project_notes

# remove optional attributes
simple_project_node.collection = []
simple_project_node.material = []
simple_project_node.notes = ""

# assert optional attributes have been removed
assert simple_project_node.collection == []
assert simple_project_node.material == []
assert simple_project_node.notes == ""


def test_serialize_project_to_json(complex_project_node, complex_project_dict) -> None:
Expand Down
Loading

0 comments on commit f8e7c53

Please sign in to comment.