Skip to content

Commit

Permalink
Fix tests, if datatype passed without ses names then coerce to proper…
Browse files Browse the repository at this point in the history
… input and display message.
  • Loading branch information
JoeZiminski committed Apr 30, 2024
1 parent e8af435 commit a266c51
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
7 changes: 7 additions & 0 deletions datashuttle/datashuttle.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@ def create_folders(
"""
self._start_log("create-folders", local_vars=locals())

if ses_names is None and datatype != "":
datatype = ""
utils.log_and_message(
"`datatype` passed without `ses_names`, no datatype "
"folders will be created."
)

utils.log("\nFormatting Names...")
ds_logger.log_names(["sub_names", "ses_names"], [sub_names, ses_names])

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 14 additions & 15 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ def check_folder_tree_is_correct(
rely on project settings itself,
as this doesn't explicitly test this.
"""
if created_folder_list is None:
created_folder_list = {}

for sub in subs:
path_to_sub_folder = join(base_folder, sub)
check_and_cd_folder(path_to_sub_folder)
Expand Down Expand Up @@ -265,20 +268,16 @@ def check_folder_tree_is_correct(

# Check the created path is found only in the expected
# dict entry.
if created_folder_list[key]:
for (
datatype_name,
all_datatype_paths,
) in created_folder_list.items():
if datatype_name == key:
assert (
Path(datatype_path) in all_datatype_paths
)
else:
assert (
Path(datatype_path)
not in all_datatype_paths
)
for (
datatype_name,
all_datatype_paths,
) in created_folder_list.items():
if datatype_name == key:
assert Path(datatype_path) in all_datatype_paths
else:
assert (
Path(datatype_path) not in all_datatype_paths
)
else:
assert not os.path.isdir(datatype_path)
assert key not in created_folder_list
Expand Down Expand Up @@ -358,7 +357,7 @@ def make_and_check_local_project_folders(


def make_local_folders_with_files_in(
project, top_level_folder, subs, sessions=None, datatype="all"
project, top_level_folder, subs, sessions=None, datatype=""
):
project.create_folders(top_level_folder, subs, sessions, datatype)
for root, dirs, _ in os.walk(project.cfg["local_path"]):
Expand Down
3 changes: 3 additions & 0 deletions tests/tests_integration/test_create_folders.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ def test_datetime_flag_in_session(self, project):
assert all([re.search(datetime_regexp, name) for name in ses_names])
assert all([tags("time") not in name for name in ses_names])

def test_error_raised_with_skipped_session_input(self, project):
pass

# ----------------------------------------------------------------------------------------------------------
# Test Make Folders in Different Top Level Folders
# ----------------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit a266c51

Please sign in to comment.