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

Commit

Permalink
test verification and fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ggoneiESS committed Sep 14, 2023
1 parent 771d188 commit 987164b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 37 deletions.
2 changes: 1 addition & 1 deletion nexus_constructor/json/load_from_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ def _add_transform_and_shape_to_component(self, component, children_dict):
if depends_on[0] != "/":
# we are always in the NXtransformations group but the path could be anything
if len(depends_on.split("/")) <= 2:
depends_on = "transformations/" + depends_on.split("/")[-1]
depends_on = "/transformations/" + depends_on.split("/")[-1]
depends_on = component.absolute_path + depends_on
depends_on_id = TransformId(*get_component_and_transform_name(depends_on))
self._components_depends_on[component.name] = (component, depends_on_id)
Expand Down
38 changes: 2 additions & 36 deletions tests/json/test_load_from_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,42 +361,8 @@ def test_GIVEN_json_with_component_depending_on_relative_transform_WHEN_loaded_T
"children"
].append(depends_on_dataset)
json_reader._load_from_json_dict(json_dict_with_component)
assert (
json_reader.model.entry.children[0]
.children[0]
.stored_items[0]
.children[0]
.attributes[1]
.name
== "depends_on"
)


def test_GIVEN_json_with_no_path_to_depends_on_WHEN_loaded_THEN_skip_addition_in_tree(
json_dict_with_component, json_reader
):
# Add depends_on dataset which points to a transformation in the JSON
depends_on_dataset_str = """
{
"module":"dataset",
"attributes":[],
"config":{
"type":"string",
"values": "some/random/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)
with pytest.raises(AttributeError):
json_reader.model.entry.children[0].children[0].stored_items[0].children[
0
].attributes[1]
assert (json_reader._components_depends_on["componentname"][1].component_name == "componentname")
assert (json_reader._components_depends_on["componentname"][1].transform_name == "slit0")


def test_when_experiment_id_in_json_then_it_is_added_to_entry(json_reader):
Expand Down

0 comments on commit 987164b

Please sign in to comment.