Skip to content

Commit

Permalink
Update tests to include dry run, and do a general related refactor of…
Browse files Browse the repository at this point in the history
… test_filesystem_transfer for clarity.
  • Loading branch information
JoeZiminski committed Apr 10, 2024
1 parent c050d3c commit dce8796
Show file tree
Hide file tree
Showing 2 changed files with 225 additions and 139 deletions.
52 changes: 37 additions & 15 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,42 +428,64 @@ def get_top_level_folder_path(
def handle_upload_or_download(
project,
upload_or_download,
specific_top_level_folder=False,
transfer_entire_project=False,
transfer_method,
top_level_folder=None,
swap_last_folder_only=False,
):
"""
To keep things consistent and avoid the pain of writing
files over SSH, to test download just swap the central
and local server (so things are still transferred from
local machine to central, but using the download function).
Also returns the transfer method, if 'transfer_method="top_level_folder"`
then the `top_level_folder` is used to determine the method,
otherwise it is not used.
"""
if upload_or_download == "download":
central_path = swap_local_and_central_paths(
project, swap_last_folder_only
)
else:
central_path = project.cfg["central_path"]

transfer_function = get_transfer_func(
project, upload_or_download, transfer_method, top_level_folder
)

return transfer_function, central_path


if transfer_entire_project:
def get_transfer_func(
project, upload_or_download, transfer_method, top_level_folder=None
):
""""""
if transfer_method == "top_level_folder":
assert top_level_folder is not None, "must pass top-level-folder"
assert top_level_folder in [None, "rawdata", "derivatives"]

if upload_or_download == "download":
if transfer_method == "entire_project":
transfer_function = project.download_entire_project
elif specific_top_level_folder == "rawdata":
transfer_function = project.download_rawdata
elif specific_top_level_folder == "derivatives":
transfer_function = project.download_derivatives
elif transfer_method == "top_level_folder":
if top_level_folder == "rawdata":
transfer_function = project.download_rawdata
else:
transfer_function = project.download_derivatives
else:
transfer_function = project.download_custom
else:
central_path = project.cfg["central_path"]

if transfer_entire_project:
if transfer_method == "entire_project":
transfer_function = project.upload_entire_project
elif specific_top_level_folder == "rawdata":
transfer_function = project.upload_rawdata
elif specific_top_level_folder == "derivatives":
transfer_function = project.upload_derivatives
elif transfer_method == "top_level_folder":
if top_level_folder == "rawdata":
transfer_function = project.upload_rawdata
else:
transfer_function = project.upload_derivatives
else:
transfer_function = project.upload_custom

return transfer_function, central_path
return transfer_function


def swap_local_and_central_paths(project, swap_last_folder_only=False):
Expand Down
Loading

0 comments on commit dce8796

Please sign in to comment.