Skip to content
This repository has been archived by the owner on Nov 7, 2024. It is now read-only.

Commit

Permalink
added further tests specified in review
Browse files Browse the repository at this point in the history
  • Loading branch information
ggoneiESS committed Sep 18, 2023
1 parent 9a47fb8 commit 8d2e148
Showing 1 changed file with 107 additions and 17 deletions.
124 changes: 107 additions & 17 deletions tests/json/test_load_from_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,18 +316,76 @@ def contains_warning_of_type(
return any(isinstance(json_warning, warning_type) for json_warning in json_warnings)


@pytest.mark.parametrize(
"depends_on_path",
[
"/entry/instrument/test_component/transformations/location",
"transformations/location",
"location"
],
)
def test_GIVEN_json_with_component_depending_on_non_existent_transform_WHEN_loaded_THEN_warning_is_added(
json_dict_with_component, json_reader
json_dict_with_component, json_reader, depends_on_path
):
depends_on_dataset_str = """
{
depends_on_dataset_str = f"""
{{
"module":"dataset",
"attributes":[],
"config":{
"config":{{
"type":"string",
"values": "/entry/instrument/test_component/transformations/location",
"values": "{depends_on_path}",
"name":"depends_on"
}
}}
}}
"""
depends_on_dataset = json.loads(depends_on_dataset_str)

# Add depends_on dataset which points to a transformation which does not exist in the JSON
json_dict_with_component["children"][0]["children"][0]["children"][0][
"children"
].append(depends_on_dataset)
json_reader._load_from_json_dict(json_dict_with_component)

assert contains_warning_of_type(json_reader.warnings, TransformDependencyMissing)


def test_GIVEN_json_with_attribute_depends_on_WHEN_loaded_THEN_warning_is_added(
json_dict_with_component, json_reader
):
depends_on_dataset_str = """
{
"module": "dataset",
"config": {
"name": "translation2",
"type": "double",
"values": -157.405
},
"attributes": [
{
"dtype": "string",
"name": "transformation_type",
"values": "translation"
},
{
"dtype": "string",
"name": "units",
"values": "m"
},
{
"dtype": "string",
"name": "vector",
"values": [
0.0,
0.0,
1.0
]
},
{
"dtype": "string",
"name": "depends_on",
"values": "translation1"
}
]
}
"""
depends_on_dataset = json.loads(depends_on_dataset_str)
Expand All @@ -344,14 +402,47 @@ def test_GIVEN_json_with_component_depending_on_non_existent_transform_WHEN_load
@pytest.mark.parametrize(
"depends_on_path",
[
"/entry/instrument/componentname/transformations/slit0",
"transformations/slit0",
"slit0",
".",
"",
None
],
)
def test_GIVEN_json_with_component_with_null_depends_on_WHEN_loaded_THEN_no_effect(
json_dict_with_component, json_reader, depends_on_path
):
# Add depends_on dataset which points to a transformation in the JSON
depends_on_dataset_str = f"""
{{
"module":"dataset",
"attributes":[],
"config":{{
"type":"string",
"values": "{depends_on_path}",
"name":"depends_on"
}}
}}
"""
depends_on_dataset = json.loads(depends_on_dataset_str)
json_dict_with_component["children"][0]["children"][0]["children"][0][
"children"
].append(depends_on_dataset)
json_reader._load_from_json_dict(json_dict_with_component)
success = False
try:
json_reader._components_depends_on["componentname"][1].component_name
except AttributeError:
success = True
assert success


@pytest.mark.parametrize(
"depends_on_path",
[
"/entry/instrument/componentname/transformations/slit0",
"transformations/slit0",
"slit0",
],
)
def test_GIVEN_json_with_component_depending_on_relative_transform_WHEN_loaded_THEN_model_updated(
json_dict_with_component, json_reader, depends_on_path
):
Expand Down Expand Up @@ -382,14 +473,13 @@ def test_GIVEN_json_with_component_depending_on_relative_transform_WHEN_loaded_T
json_reader._components_depends_on["componentname"][1].component_name
except AttributeError:
assert True
else:
assert (
json_reader._components_depends_on["componentname"][1].component_name
== "componentname"
)
assert (
json_reader._components_depends_on["componentname"][1].transform_name == transform_name
)
assert (
json_reader._components_depends_on["componentname"][1].component_name
== "componentname"
)
assert (
json_reader._components_depends_on["componentname"][1].transform_name == transform_name
)


def test_when_experiment_id_in_json_then_it_is_added_to_entry(json_reader):
Expand Down

0 comments on commit 8d2e148

Please sign in to comment.