From eb73ff62169da4085cfd432d330c989a9ba5cf1d Mon Sep 17 00:00:00 2001 From: Alexander Sutcliffe Date: Mon, 5 Dec 2022 19:32:12 +0100 Subject: [PATCH] feat: basic folder function --- src/tm1filetools/tools/filetool.py | 15 +++++++++++++++ tests/test_tools/test_core.py | 17 +++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/tm1filetools/tools/filetool.py b/src/tm1filetools/tools/filetool.py index 933c7b4..37c500f 100644 --- a/src/tm1filetools/tools/filetool.py +++ b/src/tm1filetools/tools/filetool.py @@ -609,6 +609,21 @@ def _find_files(self, suffix: str, recursive: bool = False, prefix: str = "", pa return self._case_insensitive_glob(self._data_path, f"{prefix}*.{suffix}", recursive=recursive) + def _find_folders(self, recursive: bool = False, path: Path = None): + """ + Return list of all folders in the given path or within the data directory + """ + + # this doesn't really belong here but put here for now + # also need to think about what else needs to be added to this list + static_folders = ["}applications", "}async", "}externals"] # noqa + + if path: + + return [f for f in path.iterdir() if f.is_dir()] + + return [f for f in self._data_path.iterdir() if f.is_dir()] + @staticmethod def _filter_model_and_or_control(objects, model: bool = True, control: bool = False): diff --git a/tests/test_tools/test_core.py b/tests/test_tools/test_core.py index 0055502..906c4f3 100644 --- a/tests/test_tools/test_core.py +++ b/tests/test_tools/test_core.py @@ -1,3 +1,4 @@ +from tm1filetools.files import TM1SubsetFile from tm1filetools.tools import TM1FileTool @@ -41,3 +42,19 @@ def test_find_all(test_folder): ft.find_all() assert all(f.stem != "cat" for f in ft._feeders_files) + + +def test_find_folders(test_folder): + + ft = TM1FileTool(test_folder) + + folders = ft._find_folders() + + # make sure we get something + assert len(folders) > 0 + + # make sure suffix taken into account + assert all(f.name != "cat" for f in folders) + + assert any(f.name == f"cat{TM1SubsetFile.folder_suffix}" for f in folders) + assert all(f.name != f"frog{TM1SubsetFile.folder_suffix}" for f in folders)