From 987164b834f2533c0b91b5c184387d870c444b89 Mon Sep 17 00:00:00 2001 From: George O'Neill Date: Thu, 14 Sep 2023 17:55:19 +0200 Subject: [PATCH] test verification and fix --- nexus_constructor/json/load_from_json.py | 2 +- tests/json/test_load_from_json.py | 38 ++---------------------- 2 files changed, 3 insertions(+), 37 deletions(-) diff --git a/nexus_constructor/json/load_from_json.py b/nexus_constructor/json/load_from_json.py index 76363d9ad..6d0ca27c6 100644 --- a/nexus_constructor/json/load_from_json.py +++ b/nexus_constructor/json/load_from_json.py @@ -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) diff --git a/tests/json/test_load_from_json.py b/tests/json/test_load_from_json.py index e69ac344f..128458924 100644 --- a/tests/json/test_load_from_json.py +++ b/tests/json/test_load_from_json.py @@ -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):