From 7c685ba2a5d8f4a1628c81a2913b3c0f153c59fc Mon Sep 17 00:00:00 2001 From: Laurent LAPORTE Date: Fri, 1 Mar 2024 15:42:51 +0100 Subject: [PATCH] fix(study-filesystem): check that the children exist in `FileStudyTree` --- .../rawstudy/model/filesystem/root/filestudytree.py | 2 ++ tests/storage/repository/filesystem/test_folder_node.py | 7 +++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/antarest/study/storage/rawstudy/model/filesystem/root/filestudytree.py b/antarest/study/storage/rawstudy/model/filesystem/root/filestudytree.py index e6389db280..e1daaf4326 100644 --- a/antarest/study/storage/rawstudy/model/filesystem/root/filestudytree.py +++ b/antarest/study/storage/rawstudy/model/filesystem/root/filestudytree.py @@ -30,6 +30,8 @@ def build(self) -> TREE: "user": User(self.context, self.config.next_file("user")), } + children = {key: node for key, node in children.items() if node.config.path.exists()} + if self.config.outputs: output_config = self.config.next_file("output") output_config.path = self.config.output_path or output_config.path diff --git a/tests/storage/repository/filesystem/test_folder_node.py b/tests/storage/repository/filesystem/test_folder_node.py index d08360e223..e706042db3 100644 --- a/tests/storage/repository/filesystem/test_folder_node.py +++ b/tests/storage/repository/filesystem/test_folder_node.py @@ -55,8 +55,8 @@ def test_get_input_areas_sets(tmp_path: Path) -> None: url = ["input", "areas", "sets"] # sets.ini # Empty study tree structure - actual = file_study.tree.get(url) - assert actual == {} + with pytest.raises(ChildNotFoundError, match=r"'input' not a child of FileStudyTree"): + file_study.tree.get(url) # Add the "settings" directory tmp_path.joinpath("input").mkdir() @@ -105,8 +105,7 @@ def test_get_user_expansion_sensitivity_sensitivity_in(tmp_path: Path) -> None: url = ["user", "expansion", "sensitivity", "sensitivity_in"] # Empty study tree structure - # fixme: bad error message - with pytest.raises(ChildNotFoundError, match=r"'expansion' not a child of User"): + with pytest.raises(ChildNotFoundError, match=r"'user' not a child of FileStudyTree"): file_study.tree.get(url) # Add the "user" directory